-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathyaml_test.go
183 lines (126 loc) · 3.35 KB
/
yaml_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package yaml
import (
"menteslibres.net/gosexy/to"
"testing"
)
func TestRead(t *testing.T) {
_, err := Open("_examples/input/settings.yaml")
if err != nil {
t.Errorf("Test failed: %v", err.Error())
}
}
func TestGet(t *testing.T) {
settings, err := Open("_examples/input/settings.yaml")
if err != nil {
t.Errorf("Test failed.")
}
test1 := "Hello World!"
val1 := to.String(settings.Get("test_string"))
if val1 != test1 {
t.Errorf("Got %t expecting %t.", val1, test1)
}
val2 := int(to.Int64(settings.Get("non_defined_int")))
if val2 != 0 {
t.Errorf("Test failed.")
}
test3 := "Third"
val3 := settings.Get("test_map", "element_3", "test_sequence").([]interface{})
if val3[2] != test3 {
t.Errorf("Got %t expecting %t.", val3[2], test3)
}
test5 := "Hello World!"
val5 := to.String(settings.Get("test_string"))
if test5 != val5 {
t.Errorf("Got %t expecting %t.", test5, val5)
}
test6 := 1234
val6 := int(to.Int64(settings.Get("test_int")))
if test6 != val6 {
t.Errorf("Got %t expecting %t.", test6, val6)
}
test7 := float64(1.2)
val7 := to.Float64(settings.Get("test_float"))
if test7 != val7 {
t.Errorf("Got %t expecting %t.", test7, val7)
}
test8 := true
val8 := to.Bool(settings.Get("test_bool"))
if test8 != val8 {
t.Errorf("Got %t expecting %t.", test8, val8)
}
}
func TestSet(t *testing.T) {
settings, err := Open("_examples/input/settings.yaml")
if err != nil {
t.Errorf("Test failed.")
}
settings.Set("test_map", "element_3", "test_bool", true)
test1 := true
val1 := to.Bool(settings.Get("test_map", "element_3", "test_bool"))
if val1 != test1 {
t.Errorf("Got %t expecting %t.", val1, test1)
}
}
func TestWrite(t *testing.T) {
settings := New()
settings.Set("test_map", "element_3", "test_bool", true)
err := settings.Write("_examples/input/settings2.yaml")
if err != nil {
t.Errorf("Test failed.")
}
}
// Testing compat with deprecated calls
func TestCompatGet(t *testing.T) {
settings, err := Open("_examples/input/settings.yaml")
if err != nil {
t.Errorf("Test failed.")
}
test1 := "Hello World!"
val1 := to.String(settings.Get("test_string"))
if val1 != test1 {
t.Errorf("Got %t expecting %t.", val1, test1)
}
val2 := int(to.Int64(settings.Get("non_defined_int")))
if val2 != 0 {
t.Errorf("Test failed.")
}
test3 := "Third"
val3 := settings.Get("test_map", "element_3", "test_sequence").([]interface{})
if val3[2] != test3 {
t.Errorf("Got %t expecting %t.", val3[2], test3)
}
test5 := "Hello World!"
val5 := to.String(settings.Get("test_string"))
if test5 != val5 {
t.Errorf("Got %t expecting %t.", test5, val5)
}
test6 := 1234
val6 := int(to.Int64(settings.Get("test_int")))
if test6 != val6 {
t.Errorf("Got %t expecting %t.", test6, val6)
}
test7 := float64(1.2)
val7 := to.Float64(settings.Get("test_float"))
if test7 != val7 {
t.Errorf("Got %t expecting %t.", test7, val7)
}
test8 := true
val8 := to.Bool(settings.Get("test_bool"))
if test8 != val8 {
t.Errorf("Got %t expecting %t.", test8, val8)
}
}
/*
func TestCompatSet(t *testing.T) {
settings, err := Open("_examples/input/settings.yaml")
if err != nil {
t.Errorf("Test failed.")
}
settings.Set("test_map/element_3/test_bool", true)
test1 := true
val1 := to.Bool(settings.Get("test_map/element_3/test_bool"))
if val1 != test1 {
t.Errorf("Got %t expecting %t.", val1, test1)
}
}
*/