-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructpath_test.go
72 lines (58 loc) · 1.44 KB
/
structpath_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
package inj
import "testing"
// smptystructPath should return an empty struct path
func Test_structPathA(t *testing.T) {
if string(emptyStructPath()) != "" {
t.Errorf("smptystructPath() didn't return empty string")
}
}
// Branching should work intuitively
func Test_structPathB(t *testing.T) {
inputs := []struct {
start structPath
add string
end structPath
}{
{"", "Node", ".Node"},
{".Node", "Node", ".Node.Node"},
{".some thing", "else", ".some thing.else"},
}
for i, input := range inputs {
sp := structPath(input.start)
sp = sp.Branch(input.add)
if g, e := sp, input.end; g != e {
t.Errorf("[%d] Got %s, expected %s", i, g, e)
}
}
}
// Shifting should work intuitively
func Test_structPathC(t *testing.T) {
inputs := []struct {
start structPath
str string
sp structPath
}{
{"", "", ""},
{".Node", "Node", ""},
{".Node.NodeTwo", "Node", ".NodeTwo"},
{".Parent.Node.NodeTwo", "Parent", ".Node.NodeTwo"},
}
for i, input := range inputs {
sp := structPath(input.start)
s, sp2 := sp.Shift()
if g, e := s, input.str; g != e {
t.Errorf("[%d] Got string %s, expected %s", i, g, e)
}
if g, e := sp2, input.sp; g != e {
t.Errorf("[%d] Got path %s, expected %s", i, g, e)
}
}
}
// Emptying a structpath should cause the Empty() func to
// return true
func Test_structPathD(t *testing.T) {
sp := structPath("")
if !sp.Empty() {
t.Errorf("structPath wasn't empty when it should be")
}
}