-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fillin_test.go
123 lines (118 loc) · 2.63 KB
/
fillin_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"reflect"
"testing"
)
var collectIdentifiersTests = []struct {
args []string
ids []*Identifier
}{
{
args: []string{"{{foo}}", "{{bar}}", "{{baz}}"},
ids: []*Identifier{
{key: "foo"},
{key: "bar"},
{key: "baz"},
},
},
{
args: []string{"{{foo:bar}}", "{{foo:baz}}", "{{foo}}"},
ids: []*Identifier{
{scope: "foo", key: "bar"},
{scope: "foo", key: "baz"},
{scope: "", key: "foo"},
},
},
{
args: []string{"[[foo]]", "{{bar}}", "[[baz]]"},
ids: []*Identifier{
{key: "foo"},
{key: "bar"},
{key: "baz"},
},
},
{
args: []string{"[[foo:bar]]", "[[foo:baz]]", "{{foo}}"},
ids: []*Identifier{
{scope: "foo", key: "bar"},
{scope: "foo", key: "baz"},
{scope: "", key: "foo"},
},
},
}
func Test_collectIdentifiers(t *testing.T) {
for _, test := range collectIdentifiersTests {
got := collectIdentifiers(test.args)
if !reflect.DeepEqual(got, test.ids) {
t.Errorf("collectIdentifiers failed for %+v", test.args)
}
}
}
var mapCompareTests = []struct {
m1, m2 map[string]string
expected int
}{
{
m1: map[string]string{},
m2: map[string]string{},
expected: mapCompareEqual,
},
{
m1: map[string]string{"x": "1"},
m2: map[string]string{},
expected: mapCompareSuperset,
},
{
m1: map[string]string{"x": "1", "y": "2"},
m2: map[string]string{},
expected: mapCompareSuperset,
},
{
m1: map[string]string{},
m2: map[string]string{"x": "1"},
expected: mapCompareSubset,
},
{
m1: map[string]string{"x": "1"},
m2: map[string]string{"x": "1", "y": "2"},
expected: mapCompareSubset,
},
{
m1: map[string]string{"x": "1", "y": "2"},
m2: map[string]string{"x": "1"},
expected: mapCompareSuperset,
},
{
m1: map[string]string{"x": "1"},
m2: map[string]string{"y": "2"},
expected: mapCompareDiff,
},
{
m1: map[string]string{"x": "1"},
m2: map[string]string{"x": "2"},
expected: mapCompareDiff,
},
{
m1: map[string]string{"x": "1", "y": "2", "z": "3"},
m2: map[string]string{"x": "1", "w": "2", "z": "3"},
expected: mapCompareDiff,
},
{
m1: map[string]string{"x": "1"},
m2: map[string]string{"x": "1", "y": "2", "z": "3"},
expected: mapCompareSubset,
},
{
m1: map[string]string{"x": "1", "y": "2", "z": "3"},
m2: map[string]string{"x": "1", "y": "2", "z": "3"},
expected: mapCompareEqual,
},
}
func Test_mapCompare(t *testing.T) {
for _, test := range mapCompareTests {
got := mapCompare(test.m1, test.m2)
if got != test.expected {
t.Errorf("mapCompare failed for %+v", test)
}
}
}