-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgoconfigobj_test.go
166 lines (150 loc) · 3.53 KB
/
goconfigobj_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
package goconfigobj
import (
"strings"
"testing"
)
func TestNoSection(t *testing.T) {
txt := `
aa =aa
bb =gg
`
co := NewConfigObj(strings.NewReader(txt))
if co.Value("aa") == "aa" && co.Value("bb") == "gg" {
t.Log("NoSection test ok")
} else {
t.Error("NoSection test failed")
}
}
func TestNoSectionSameKeyReplace(t *testing.T) {
txt := `
aa =aa
bb =gg
"aa" = "gggg"
`
co := NewConfigObj(strings.NewReader(txt))
if co.Value("aa") == "gggg" && co.Value("bb") == "gg" {
t.Log("NoSectionSameKeyReplace test ok")
} else {
t.Error("NoSectionSameKeyReplace test failed")
}
}
func TestNoSectionSomeQuot(t *testing.T) {
txt := `
"aa" ="aa"
'bb'= 'gg'
"bb3" ='gg122'
'bbc'= "ggg"
"bbcx"= ggg
`
co := NewConfigObj(strings.NewReader(txt))
if co.Value("bbcx") == "ggg" && co.Value("aa") == "aa" {
t.Log("NoSectionSomeQuot test ok")
} else {
t.Error("NoSectionSomeQuot test failed")
}
}
func TestNoSectionMultiLine(t *testing.T) {
txt := `
"aa" ="""
ffff
ffff
"""
`
c := `
ffff
ffff
`
co := NewConfigObj(strings.NewReader(txt))
if co.Value("aa") == c {
t.Log("NoSectionMultiLine test ok")
} else {
t.Error("NoSectionMultiLine test failed")
}
}
func TestSection(t *testing.T) {
txt := `
[fff]
aa =aa
bb =gg
`
co := NewConfigObj(strings.NewReader(txt))
if co.Section("fff").Value("aa") == "aa" && co.Section("fff").Value("bb") == "gg" {
t.Log("Section test ok")
} else {
t.Error("Section test failed")
}
}
func TestSectionQuot(t *testing.T) {
txt := `
['fff']
aa =aa
["sss"]
bb =gg
`
co := NewConfigObj(strings.NewReader(txt))
if co.Section("fff").Value("aa") == "aa" && co.Section("sss").Value("bb") == "gg" {
t.Log("Section test ok")
} else {
t.Error("Section test failed")
}
}
func TestSectionDepth(t *testing.T) {
txt := `
[fff]
bb =gg
[[zz]]
[[["ggg"]]]
aa =aa
`
co := NewConfigObj(strings.NewReader(txt))
if co.Section("fff").Section("zz").Section("ggg").Value("aa") == "aa" && co.Section("fff").Value("bb") == "gg" {
t.Log("SectionDepth test ok")
} else {
t.Error("SectionDepth test failed")
}
}
func TestChinese(t *testing.T) {
txt := `
[fff]
bb =gg
[[zz]]
[[["ggg"]]]
aa =开心猫
`
co := NewConfigObj(strings.NewReader(txt))
if co.Section("fff").Section("zz").Section("ggg").Value("aa") == "开心猫" && co.Section("fff").Value("bb") == "gg" {
t.Log("Chinese test ok")
} else {
t.Error("Chinese test failed")
}
}
func TestChineseQuot(t *testing.T) {
txt := `
[fff]
bb ="你好"
[[zz]]
[[["ggg"]]]
aa ='开心猫'
`
co := NewConfigObj(strings.NewReader(txt))
if co.Section("fff").Section("zz").Section("ggg").Value("aa") == "开心猫" && co.Section("fff").Value("bb") == "你好" {
t.Log("ChineseQuot test ok")
} else {
t.Error("ChineseQuot test failed")
}
}
func TestHttpUrl(t *testing.T) {
txt := `
[fff]
bb ="你好"
[[zz]]
[[["ggg"]]]
aa =https://www.google.co.jp/search?q=%E5%BC%80%E5%BF%83%E7%8C%AB&oq=%E5%BC%80%E5%BF%83%E7%8C%AB&aqs=chrome..69i57.1391j0j4&sourceid=chrome&ie=UTF-8
`
co := NewConfigObj(strings.NewReader(txt))
if co.Section("fff").Section("zz").Section("ggg").Value("aa") == "https://www.google.co.jp/search?q=%E5%BC%80%E5%BF%83%E7%8C%AB&oq=%E5%BC%80%E5%BF%83%E7%8C%AB&aqs=chrome..69i57.1391j0j4&sourceid=chrome&ie=UTF-8" && co.Section("fff").Value("bb") == "你好" {
t.Log("HttpUrl test ok")
} else {
t.Error("HttpUrl test failed")
}
}