-
Notifications
You must be signed in to change notification settings - Fork 23
/
inherited_ini_test.go
109 lines (88 loc) · 2.4 KB
/
inherited_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
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
package goini
import (
"log"
"path/filepath"
"runtime"
"testing"
"github.com/bmizerany/assert"
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
}
func TestInheritedINI(t *testing.T) {
filename := filepath.Join(getTestDataDir(t), "project.ini")
ini, err := LoadInheritedINI(filename)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, ini)
v, ok := ini.Get("product")
assert.Equal(t, v, "test")
assert.Equal(t, ok, true)
v, ok = ini.Get("combo")
assert.Equal(t, v, "test")
assert.Equal(t, ok, true)
//Override the inherited value
v, ok = ini.Get("debug")
assert.Equal(t, v, "1")
assert.Equal(t, ok, true)
//The inherited config
v, ok = ini.Get("version")
assert.Equal(t, v, "0.0.0.0")
assert.Equal(t, ok, true)
v, ok = ini.Get("encoding")
assert.Equal(t, v, "0")
assert.Equal(t, ok, true)
v, ok = ini.SectionGet("sss", "a")
assert.Equal(t, v, "aaval")
assert.Equal(t, ok, true)
v, ok = ini.SectionGet("sss", "b")
assert.Equal(t, v, "bval")
assert.Equal(t, ok, true)
v, ok = ini.SectionGet("sss", "c")
assert.Equal(t, v, "ccval")
assert.Equal(t, ok, true)
ini = New()
err = ini.ParseFile(filename)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, ini)
v, ok = ini.Get("product")
assert.Equal(t, v, "test")
assert.Equal(t, ok, true)
v, ok = ini.Get("combo")
assert.Equal(t, v, "test")
assert.Equal(t, ok, true)
v, ok = ini.Get("version")
assert.Equal(t, v, "")
assert.Equal(t, ok, false)
v, ok = ini.Get("encoding")
assert.Equal(t, v, "")
assert.Equal(t, ok, false)
v, ok = ini.SectionGet("sss", "a")
assert.Equal(t, v, "aaval")
assert.Equal(t, ok, true)
v, ok = ini.SectionGet("sss", "b")
assert.Equal(t, v, "")
assert.Equal(t, ok, false)
v, ok = ini.SectionGet("sss", "c")
assert.Equal(t, v, "ccval")
assert.Equal(t, ok, true)
}
func TestInheritedINI2Error(t *testing.T) {
filename := filepath.Join(getTestDataDir(t), "project2.ini")
ini, err := LoadInheritedINI(filename)
assert.NotEqual(t, nil, err)
assert.Equal(t, ini, (*INI)(nil))
}
func TestInheritedINI3Error(t *testing.T) {
var filename = "project3_linux.ini"
if runtime.GOOS == "windows" {
filename = "project3_windows.ini"
}
filename = filepath.Join(getTestDataDir(t), filename)
ini, err := LoadInheritedINI(filename)
assert.NotEqual(t, nil, err)
assert.Equal(t, ini, (*INI)(nil))
ini = New()
err = ini.ParseFile(filename)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, ini)
}