-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_test.go
More file actions
76 lines (71 loc) · 1.2 KB
/
decode_test.go
File metadata and controls
76 lines (71 loc) · 1.2 KB
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
package narg
import (
"reflect"
"strings"
"testing"
"time"
"github.com/kylelemons/godebug/pretty"
)
type testConf struct {
Name string
Port int
Debug bool
Float float32
Hosts []string
Ports []int
PortsU []uint8
Creation time.Time
Admin testUser
Users []testUser
}
type testUser struct {
ID int `narg:"0"`
Name string `narg:"1"`
}
func TestDecode(t *testing.T) {
act := &testConf{}
exp := &testConf{
Name: "foo",
Port: 80,
Debug: true,
Float: 3.14,
Hosts: []string{"a", "bee", "cee e"},
Ports: []int{1024, 1025},
PortsU: []uint8{0xff, 0xff},
Creation: time.Date(1999, time.December, 31, 23, 59, 59, 0, time.UTC),
Admin: testUser{
ID: 1,
Name: `Phil "Tandy" Miller`,
},
Users: []testUser{
{2, "Carol Pilbasian"},
{4, "Todd"},
},
}
in := `
name foo
port 80
debug 1
float 3.14
hosts a bee "cee e"
ports 1024 1025
portsu 0xff 255
creation 1999-12-31T23:59:59Z
admin {
id 1
name "Phil \"Tandy\" Miller"
}
users {
id 2
name "Carol Pilbasian"
}
users 4 Todd
`
err := Decode(strings.NewReader(in), act)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(exp, act) {
t.Fatal(pretty.Compare(act, exp))
}
}