-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield_test.go
63 lines (58 loc) · 1.33 KB
/
field_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
package cronfab
import "testing"
func TestCrontabField_String(t *testing.T) {
cf := CrontabField([][3]int{})
s := cf.String()
if s != "" {
t.Errorf("unexpected value")
}
cf = CrontabField([][3]int{{1, 2, 1}})
s = cf.String()
if s != "1-2/1" {
t.Errorf("unexpected value")
}
cf = CrontabField([][3]int{{1, 2, 1}, {3, 20, 1}})
s = cf.String()
if s != "1-2/1,3-20/1" {
t.Errorf("unexpected value")
}
}
func TestCrontabField_Len(t *testing.T) {
cf := CrontabField([][3]int{})
l := cf.Len()
if l != 0 {
t.Errorf("unexpected value")
}
cf = CrontabField([][3]int{{1, 2, 1}})
l = cf.Len()
if l != 1 {
t.Errorf("unexpected value")
}
cf = CrontabField([][3]int{{1, 2, 1}, {3, 20, 1}})
l = cf.Len()
if l != 2 {
t.Errorf("unexpected value")
}
}
func TestCrontabField_SetConstraint(t *testing.T) {
cf := CrontabField([][3]int{{1, 2, 1}})
if cf.GetConstraint(0) != [3]int{1, 2, 1} {
t.Errorf("unexpected value")
}
cf.SetConstraint(0, [3]int{3, 20, 2})
if cf.GetConstraint(0) != [3]int{3, 20, 2} {
t.Errorf("unexpected value")
}
}
func TestCrontabField_Validate(t *testing.T) {
cf := CrontabField([][3]int{{1, 2, 1}, {3, 4, 1}})
err := cf.Validate()
if err != nil {
t.Errorf("err: %v", err)
}
cf = CrontabField([][3]int{{1, 2, 1}, {2, 4, 1}})
err = cf.Validate()
if err == nil {
t.Errorf("unexpected value")
}
}