-
Notifications
You must be signed in to change notification settings - Fork 1
/
ini_test.go
66 lines (61 loc) · 2.38 KB
/
ini_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
package ini_test
import (
. "gopkg.in/check.v1"
"go-ini"
)
func (s *S) TestIni(c *C) {
var (
iniContext = `;comment one
#comment two
[common]
string = testing
string_1 = testing_1
string_1.1 = "testing"
string_2.1 = "testing"
string_3.1.1 = "testing_1"
string_3.1.2 = "testing_2"
iNt = 8080
Float = 3.1415976
BOOLEAN = false
Boolean_1 = true
switcher= on
switcher_1= off
switcher_2 = OFF
switcher_3 = ON
switcher_4 = Y
switcher_5 = N
flag = 1
[Dev:common]
string = "testing_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long"
string_1.1 = "testing_dev"
string_2.2 = "testing_dev"
CaseInsensitive = true
`
)
var iniConf interface{}
err := ini.Unmarshal([]byte(iniContext), &iniConf)
c.Assert(err, IsNil)
value, ok := iniConf.(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", iniConf))
section_value, ok := value["common"].(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", value["common"]))
string_1_value, ok := section_value["string_1"].(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", section_value["string_1"]))
c.Assert(string_1_value[1], DeepEquals, "testing")
string_3_value, ok := section_value["string_3"].(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", section_value["string_3"]))
string_3_1_value, ok := string_3_value[1].(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", string_3_value["1"]))
c.Assert(string_3_1_value[1], DeepEquals, "testing_1")
c.Assert(string_3_1_value[2], DeepEquals, "testing_2")
section_value, ok = value["Dev"].(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", value["Dev"]))
string_value, ok := section_value["string"].(string)
c.Assert(ok, Equals, true, Commentf("value: %#v", section_value["string"]))
c.Assert(string_value, DeepEquals, "testing_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long")
string_1_value, ok = section_value["string_1"].(map[interface{}]interface{})
c.Assert(ok, Equals, true, Commentf("value: %#v", section_value["string_1"]))
c.Assert(string_1_value[1], DeepEquals, "testing_dev")
//buf, err := Marshal(reflect.ValueOf(iniConf))
//fmt.Println(buf)
}