github.com/mncinnovation/ponzu@v0.11.1-0.20200102001432-9bc41b703131/cmd/ponzu/cli_test.go (about) 1 package main 2 3 import "testing" 4 5 func TestParseType(t *testing.T) { 6 // blog title:string Author:string PostCategory:string content:string some_thing:int 7 args := []string{ 8 "blog", "title:string", "Author:string", 9 "PostCategory:string", "content:string", 10 "some_thing:int", "Some_otherThing:float64", 11 } 12 13 gt, err := parseType(args) 14 if err != nil { 15 t.Errorf("Failed: %s", err.Error()) 16 } 17 18 if gt.Name != "Blog" { 19 t.Errorf("Expected %s, got: %s", "Blog", gt.Name) 20 } 21 } 22 23 func TestFieldJSONName(t *testing.T) { 24 cases := map[string]string{ 25 "_T": "t", 26 "T": "t", 27 "_tT_": "t_t_", 28 "TestCapsNoSym": "test_caps_no_sym", 29 "test_Some_caps_Sym": "test_some_caps_sym", 30 "testnocaps": "testnocaps", 31 "_Test_Caps_Sym_odd": "test_caps_sym_odd", 32 "test-hyphen": "test-hyphen", 33 "Test-hyphen-Caps": "test-hyphen-caps", 34 "Test-Hyphen_Sym-Caps": "test-hyphen_sym-caps", 35 } 36 37 for input, expected := range cases { 38 output := fieldJSONName(input) 39 if output != expected { 40 t.Errorf("Expected: %s, got: %s", expected, output) 41 } 42 } 43 } 44 45 func TestFieldName(t *testing.T) { 46 cases := map[string]string{ 47 "_T": "T", 48 "T": "T", 49 "_tT_": "TT", 50 "TestCapsNoSym": "TestCapsNoSym", 51 "test_Some_caps_Sym": "TestSomeCapsSym", 52 "testnocaps": "Testnocaps", 53 "_Test_Caps_Sym_odd": "TestCapsSymOdd", 54 "test-hyphen": "TestHyphen", 55 "Test-hyphen-Caps": "TestHyphenCaps", 56 "Test-Hyphen_Sym-Caps": "TestHyphenSymCaps", 57 } 58 59 for input, expected := range cases { 60 output := fieldName(input) 61 if output != expected { 62 t.Errorf("Expected: %s, got: %s", expected, output) 63 } 64 } 65 }