-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifier_test.go
58 lines (49 loc) · 1.08 KB
/
modifier_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
package gts
import (
"testing"
)
var asModifierTests = []struct {
in string
out Modifier
}{
{"^", Head(0)},
{"^+42", Head(42)},
{"^-42", Head(-42)},
{"$", Tail(0)},
{"$+42", Tail(42)},
{"$-42", Tail(-42)},
{"^..$", HeadTail{0, 0}},
{"^+1..$+1", HeadTail{+1, +1}},
{"^-1..$+1", HeadTail{-1, +1}},
{"^-1..$-1", HeadTail{-1, -1}},
{"^..^", HeadHead{0, 0}},
{"^+1..^+1", HeadHead{+1, +1}},
{"^-1..^+1", HeadHead{-1, +1}},
{"^-1..^-1", HeadHead{-1, -1}},
{"$..$", TailTail{0, 0}},
{"$+1..$+1", TailTail{+1, +1}},
{"$-1..$+1", TailTail{-1, +1}},
{"$-1..$-1", TailTail{-1, -1}},
}
var asModifierFailTests = []string{
"",
"^-2..0",
"$..^",
}
func TestAsModifier(t *testing.T) {
for _, tt := range asModifierTests {
out, err := AsModifier(tt.in)
if err != nil {
t.Errorf("AsModifier(%q): %v", tt.in, err)
continue
}
if out.String() != tt.out.String() {
t.Errorf("AsModifier(%q) = %q, want %q", tt.in, out, tt.out)
}
}
for _, in := range asModifierFailTests {
if _, err := AsModifier(in); err == nil {
t.Errorf("expected error in AsModifier(%q)", in)
}
}
}