-
Notifications
You must be signed in to change notification settings - Fork 0
/
ymltree_test.go
80 lines (68 loc) · 1.24 KB
/
ymltree_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
package ymltree
import (
"testing"
)
var cfg1 = `
a: Easy!
b:
c: 2
d: [3, 4]
e:
f: dog
g: cake
`
var cfg2 = `
b:
d: [4, 5, 6]
e:
f: cat
g: [1,2]
`
func TestMapSearch(t *testing.T) {
cfg, _ := Load(cfg1)
srch := cfg.Find("b/e/f")
if srch != "dog" {
t.Error("map search failed found", srch, "dog")
}
}
func TestStringMapMerge(t *testing.T) {
cfg, _ := Load(cfg1)
cfg.Merge(cfg2)
srch := cfg.Find("b/e/f")
if srch != "cat" {
t.Error("merge string override failed", srch, "cat")
}
}
func TestTypeOverride(t *testing.T) {
cfg, _ := Load(cfg1)
cfg.Merge(cfg2)
srch := cfg.Find("b/e/g")
m := make(map[int]bool)
for _, v := range srch.([]interface{}) {
m[v.(int)] = true
}
expected := []int{1, 2}
for _, v := range expected {
if _, ok := m[v]; !ok {
t.Error("missing expected element", v)
}
}
}
func TestIntSliceMapMerge(t *testing.T) {
cfg, _ := Load(cfg1)
cfg.Merge(cfg2)
srch := cfg.Find("b/d")
m := make(map[int]bool)
for _, v := range srch.([]interface{}) {
m[v.(int)] = true
}
if len(m) != 4 {
t.Error("slice merge incorrect size", len(m), 4)
}
expected := []int{3, 4, 5, 6}
for _, v := range expected {
if _, ok := m[v]; !ok {
t.Error("missing expected element", v)
}
}
}