forked from stathat/jconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
57 lines (53 loc) · 1.33 KB
/
config_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
package jconfig
import (
"testing"
)
func TestConfigFromString(t *testing.T) {
c := LoadConfigString(`{"one":1,"two":"zwei","three":["a","b","c"]}`)
if c == nil {
t.Fatalf("expected a config object")
}
if c.data == nil {
t.Fatalf("expected config object to have data")
}
if c.GetInt("one") != 1 {
t.Errorf("expected 1, got %d:", c.GetInt("one"))
}
if c.GetString("two") != "zwei" {
t.Errorf("expected zwei, got %s:", c.GetString("two"))
}
if len(c.GetArray("three")) != 3 {
t.Errorf("expected 3 elt array")
}
}
func TestConfigBool(t *testing.T) {
c := LoadConfigString(`{"istrue":true,"isfalse":false}`)
if c == nil {
t.Fatalf("expected a config object")
}
if c.GetBool("istrue") == false {
t.Errorf("expected true")
}
if c.GetBool("isfalse") == true {
t.Errorf("expected false")
}
}
func TestConfigMerge(t *testing.T) {
c := LoadConfigString(`{"one":1,"two":"zwei","three":["a","b","c"]}`)
if c == nil {
t.Fatalf("expected a config object")
}
c.StringMerge(`{"two":2,"four":"vier"}`)
if c.GetInt("one") != 1 {
t.Errorf("expected 1, got %d:", c.GetInt("one"))
}
if len(c.GetArray("three")) != 3 {
t.Errorf("expected 3 elt array")
}
if c.GetInt("two") != 2 {
t.Errorf("expected 2, got %d:", c.GetInt("two"))
}
if c.GetString("four") != "vier" {
t.Errorf("expected vier, got %s:", c.GetString("four"))
}
}