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
|
package main
import "testing"
func TestParseType(t *testing.T) {
// blog title:string Author:string PostCategory:string content:string some_thing:int
args := []string{
"blog", "title:string", "Author:string",
"PostCategory:string", "content:string",
"some_thing:int", "Some_otherThing:float64",
}
gt, err := parseType(args)
if err != nil {
t.Errorf("Failed: %s", err.Error())
}
if gt.Name != "Blog" {
t.Errorf("Expected %s, got: %s", "Blog", gt.Name)
}
}
func TestFieldJSONName(t *testing.T) {
cases := map[string]string{
"_T": "t",
"T": "t",
"_tT_": "t_t_",
"TestCapsNoSym": "test_caps_no_sym",
"test_Some_caps_Sym": "test_some_caps_sym",
"testnocaps": "testnocaps",
"_Test_Caps_Sym_odd": "test_caps_sym_odd",
"test-hyphen": "test-hyphen",
"Test-hyphen-Caps": "test-hyphen-caps",
"Test-Hyphen_Sym-Caps": "test-hyphen_sym-caps",
}
for input, expected := range cases {
output := fieldJSONName(input)
if output != expected {
t.Errorf("Expected: %s, got: %s", expected, output)
}
}
}
func TestFieldName(t *testing.T) {
cases := map[string]string{
"_T": "T",
"T": "T",
"_tT_": "TT",
"TestCapsNoSym": "TestCapsNoSym",
"test_Some_caps_Sym": "TestSomeCapsSym",
"testnocaps": "Testnocaps",
"_Test_Caps_Sym_odd": "TestCapsSymOdd",
"test-hyphen": "TestHyphen",
"Test-hyphen-Caps": "TestHyphenCaps",
"Test-Hyphen_Sym-Caps": "TestHyphenSymCaps",
}
for input, expected := range cases {
output := fieldName(input)
if output != expected {
t.Errorf("Expected: %s, got: %s", expected, output)
}
}
}
|