This repository has been archived by the owner on Jun 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_test.go
73 lines (70 loc) · 1.67 KB
/
parse_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
package main
import (
"reflect"
"testing"
)
func TestParseCommand(t *testing.T) {
testcases := []struct {
line string
cmd command
}{
{
"system hostname",
command{
Method: "system.hostname",
},
},
{
"object update subscriber 1234 foo=bar",
command{
Method: "object.update",
Params: []interface{}{"subscriber", "1234", map[string]string{"foo": "bar"}},
},
},
{
"object update subscriber 1234 foo=bar,baz=quux",
command{
Method: "object.update",
Params: []interface{}{"subscriber", "1234", map[string]string{"foo": "bar", "baz": "quux"}},
},
},
{
"object update subscriber 1234 foo=bar baz=quux",
command{
Method: "object.update",
Params: []interface{}{"subscriber", "1234", map[string]string{"foo": "bar"}, map[string]string{"baz": "quux"}},
},
},
{
`object update subscriber 1234 {"foo":"bar","baz":"quux"}`,
command{
Method: "object.update",
Params: []interface{}{"subscriber", "1234", map[string]interface{}{"foo": "bar", "baz": "quux"}},
},
},
{
`object update subscriber 1234 {"foo": "bar 1", "baz 2": "quux 2"}`,
command{
Method: "object.update",
Params: []interface{}{"subscriber", "1234", map[string]interface{}{"foo": "bar 1", "baz 2": "quux 2"}},
},
},
{
`object update subscriber 1234 foo=,bar`,
command{
Method: "object.update",
Params: []interface{}{"subscriber", "1234", map[string]string{"foo": "", "bar": ""}},
},
},
}
for _, tc := range testcases {
cmd, err := parseCommand(tc.line)
if err != nil {
t.Error(err)
continue
}
if !reflect.DeepEqual(cmd, tc.cmd) {
t.Errorf("Parse error;\n\t%#v\n\t%#v", cmd, tc.cmd)
}
}
}