-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator_test.go
100 lines (93 loc) · 1.62 KB
/
generator_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
package multiswagger
import (
"reflect"
"sort"
"testing"
)
func TestAppendKeys(t *testing.T) {
cases := map[string]struct {
data string
expected map[string]bool
}{
"not JSON": {
`This is not JSON.`,
map[string]bool{},
},
"pattern 1": {
`{"en":"english","ja":"日本語"}`,
map[string]bool{
"en": true,
"ja": true,
},
},
"pattern 2": {
`{"zh":"汉语"}`,
map[string]bool{
"en": true,
"ja": true,
"zh": true,
},
},
}
var mapKeys []string
for k := range cases {
mapKeys = append(mapKeys, k)
}
sort.Strings(mapKeys)
for _, k := range mapKeys {
tc := cases[k]
appendKeys(&tc.data)
if reflect.DeepEqual(keys, tc.expected) != true {
t.Errorf("%s: appendKeys got %v, want %v", k, keys, tc.expected)
}
}
}
func TestExtract(t *testing.T) {
cases := map[string]struct {
data string
keys map[string]bool
key string
expected string
}{
"not JSON": {
`This is not JSON.`,
map[string]bool{
"en": true,
},
"en",
`This is not JSON.`,
},
"pattern 1": {
`{"en":"english","ja":"日本語"}`,
map[string]bool{
"en": true,
"ja": true,
},
"en",
"english",
},
"pattern 2": {
`{"en":"english","ja":"日本語"}`,
map[string]bool{
"en": true,
"ja": true,
},
"ja",
"日本語",
},
}
var mapKeys []string
for k := range cases {
mapKeys = append(mapKeys, k)
}
sort.Strings(mapKeys)
for _, k := range mapKeys {
tc := cases[k]
keys = tc.keys
key = tc.key
extract(&tc.data)
if tc.data != tc.expected {
t.Errorf("%s: extract got %v, want %v", k, tc.data, tc.expected)
}
}
}