MCPcopy
hub / github.com/robfig/cron / TestRange

Function TestRange

parser_test.go:12–58  ·  parser_test.go::TestRange
(t *testing.T)

Source from the content-addressed store, hash-verified

10var secondParser = NewParser(Second | Minute | Hour | Dom | Month | DowOptional | Descriptor)
11
12func TestRange(t *testing.T) {
13 zero := uint64(0)
14 ranges := []struct {
15 expr string
16 min, max uint
17 expected uint64
18 err string
19 }{
20 {"5", 0, 7, 1 << 5, ""},
21 {"0", 0, 7, 1 << 0, ""},
22 {"7", 0, 7, 1 << 7, ""},
23
24 {"5-5", 0, 7, 1 << 5, ""},
25 {"5-6", 0, 7, 1<<5 | 1<<6, ""},
26 {"5-7", 0, 7, 1<<5 | 1<<6 | 1<<7, ""},
27
28 {"5-6/2", 0, 7, 1 << 5, ""},
29 {"5-7/2", 0, 7, 1<<5 | 1<<7, ""},
30 {"5-7/1", 0, 7, 1<<5 | 1<<6 | 1<<7, ""},
31
32 {"*", 1, 3, 1<<1 | 1<<2 | 1<<3 | starBit, ""},
33 {"*/2", 1, 3, 1<<1 | 1<<3, ""},
34
35 {"5--5", 0, 0, zero, "too many hyphens"},
36 {"jan-x", 0, 0, zero, "failed to parse int from"},
37 {"2-x", 1, 5, zero, "failed to parse int from"},
38 {"*/-12", 0, 0, zero, "negative number"},
39 {"*//2", 0, 0, zero, "too many slashes"},
40 {"1", 3, 5, zero, "below minimum"},
41 {"6", 3, 5, zero, "above maximum"},
42 {"5-3", 3, 5, zero, "beyond end of range"},
43 {"*/0", 0, 0, zero, "should be a positive number"},
44 }
45
46 for _, c := range ranges {
47 actual, err := getRange(c.expr, bounds{c.min, c.max, nil})
48 if len(c.err) != 0 && (err == nil || !strings.Contains(err.Error(), c.err)) {
49 t.Errorf("%s => expected %v, got %v", c.expr, c.err, err)
50 }
51 if len(c.err) == 0 && err != nil {
52 t.Errorf("%s => unexpected error %v", c.expr, err)
53 }
54 if actual != c.expected {
55 t.Errorf("%s => expected %d, got %d", c.expr, c.expected, actual)
56 }
57 }
58}
59
60func TestField(t *testing.T) {
61 fields := []struct {

Callers

nothing calls this directly

Calls 2

getRangeFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected