-
Notifications
You must be signed in to change notification settings - Fork 0
/
integral_add_test.go
78 lines (65 loc) · 1.85 KB
/
integral_add_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package gotask
import "testing"
func (c *integralTest) TestAdd(t *testing.T) {
t.Run("ok", c.addOK)
t.Run("afterParse", c.addAfterParse)
t.Run("afterReset", c.addAfterReset)
t.Run("cyclic", c.addCyclic)
t.Run("duplicated", c.addDuplicated)
}
func (c *integralTest) addOK(t *testing.T) {
r := c.New()
if err := r.Add(New("a", nop, []string{})); err != nil {
t.Fatal("unexpected error: ", err)
}
}
func (c *integralTest) addAfterParse(t *testing.T) {
r := c.New()
t.Run("addTaskA", ensureAdd(r, New("a", nop, []string{})))
if err := r.Parse(); err != nil {
t.Fatal("unexpected parse error: ", err)
}
err := r.QuickAdd("b", nop)
if err == nil {
t.Fatal("expected to have ErrParsed, got nothing")
}
if err != ErrParsed {
t.Fatal("expected to have ErrParsed, got ", err)
}
}
func (c *integralTest) addAfterReset(t *testing.T) {
r := c.New()
t.Run("addTaskA", ensureAdd(r, New("a", nop, []string{})))
if err := r.Parse(); err != nil {
t.Fatal("unexpected parse error: ", err)
}
r.Reset()
err := r.QuickAdd("b", nop)
if err != nil {
t.Fatal("unexpected error ", err)
}
}
func (c *integralTest) addCyclic(t *testing.T) {
r := c.New()
err := r.Add(New("a", nop, []string{"a"}))
if err == nil {
t.Fatal("expected ErrCyclic, got nothing")
}
if err != ErrCyclic {
t.Fatalf("expected ErrCyclic, got %s", err)
}
}
func (c *integralTest) addDuplicated(t *testing.T) {
r := c.New()
t.Run("AddTaskA", ensureAdd(r, New("a", nop, []string{})))
err := r.Add(New("a", nop, []string{"b"}))
if err == nil {
t.Fatal("expected ErrDuplicated, got nothing")
}
if err != ErrDuplicated("a") {
t.Fatalf("expected ErrDuplicated(a), got %s", err)
}
}