-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselector_test.go
105 lines (92 loc) · 1.89 KB
/
selector_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package cuckle
import "testing"
func TestSelectorAlias(t *testing.T) {
for _, test := range []struct {
s Selector
i Identifier
e Selector
}{
{`""`, "", `"" as ""`},
{`"a"`, "b", `"a" as "b"`},
} {
t.Log("Test:", test)
if a := SelectorAlias(test.s, test.i); a != test.e {
t.Errorf("Actual %v, expected %v", a, test.e)
}
}
}
func TestSelectorFunc(t *testing.T) {
for _, test := range []struct {
i Identifier
a []Selector
e Selector
}{
{"", nil, `""()`},
{"", []Selector{}, `""()`},
{"a", []Selector{}, `"a"()`},
{"a", []Selector{`"b"`}, `"a"("b")`},
{"a", []Selector{`"b"`, `"c"`}, `"a"("b", "c")`},
} {
t.Log("Test:", test)
if a := SelectorFunc(test.i, test.a...); a != test.e {
t.Errorf("Actual %v, expected %v", a, test.e)
}
}
}
func TestSelectorIdentifier(t *testing.T) {
for _, test := range []struct {
i Identifier
e Selector
}{
{"", `""`},
{"a", `"a"`},
} {
t.Log("Test:", test)
if a := SelectorIdentifier(test.i); a != test.e {
t.Errorf("Actual %v, expected %v", a, test.e)
}
}
}
func TestSelectorIndex(t *testing.T) {
for _, test := range []struct {
i Identifier
t Term
e Selector
}{
{"", "", `""[]`},
{"a", "1", `"a"[1]`},
} {
t.Log("Test:", test)
if a := SelectorIndex(test.i, test.t); a != test.e {
t.Errorf("Actual %v, expected %v", a, test.e)
}
}
}
func TestSelectorTTL(t *testing.T) {
for _, test := range []struct {
i Identifier
e Selector
}{
{"", `ttl("")`},
{"a", `ttl("a")`},
} {
t.Log("Test:", test)
if a := SelectorTTL(test.i); a != test.e {
t.Errorf("Actual %v, expected %v", a, test.e)
}
}
}
func TestSelectorWriteTime(t *testing.T) {
for _, test := range []struct {
i Identifier
e Selector
}{
{"", `writetime("")`},
{"a", `writetime("a")`},
} {
t.Log("Test:", test)
if a := SelectorWriteTime(test.i); a != test.e {
t.Errorf("Actual %v, expected %v", a, test.e)
}
}
}