forked from glacjay/goini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathini_test.go
78 lines (70 loc) · 1.86 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
67
68
69
70
71
72
73
74
75
76
77
78
package ini_test
import (
"ini"
"testing"
)
var (
dict ini.Dict
err error
)
func init() {
dict, err = ini.Load("example.ini")
}
func TestLoad(t *testing.T) {
if err != nil {
t.Error("Example: load error:", err)
}
}
func TestGetBool(t *testing.T) {
b, found := dict.GetBool("pizza", "ham")
if !found || !b {
t.Error("Example: parse error for key ham of section pizza.")
}
b, found = dict.GetBool("pizza", "mushrooms")
if !found || !b {
t.Error("Example: parse error for key mushrooms of section pizza.")
}
b, found = dict.GetBool("pizza", "capres")
if !found || b {
t.Error("Example: parse error for key capres of section pizza.")
}
b, found = dict.GetBool("pizza", "cheese")
if !found || b {
t.Error("Example: parse error for key cheese of section pizza.")
}
}
func TestGetStringIntAndDouble(t *testing.T) {
str, found := dict.GetString("wine", "grape")
if !found || str != "Cabernet Sauvignon" {
t.Error("Example: parse error for key grape of section wine.")
}
i, found := dict.GetInt("wine", "year")
if !found || i != 1989 {
t.Error("Example: parse error for key year of section wine.")
}
str, found = dict.GetString("wine", "country")
if !found || str != "Spain" {
t.Error("Example: parse error for key grape of section wine.")
}
d, found := dict.GetDouble("wine", "alcohol")
if !found || d != 12.5 {
t.Error("Example: parse error for key grape of section wine.")
}
}
func TestGetNotExist(t *testing.T) {
_, found := dict.GetString("not", "exist")
if found {
t.Error("There is no key exist of section not.")
}
}
func TestGetSections(t *testing.T) {
sections := dict.GetSections()
if len(sections) != 3 {
t.Error("The number of sections is wrong:", len(sections))
}
for _, section := range sections {
if section != "" && section != "pizza" && section != "wine" {
t.Errorf("Section '%s' should not be exist.", section)
}
}
}