github.com/nathanstitt/genqlient@v0.3.1-0.20211028004951-a2bda3c41ab8/generate/util_test.go (about) 1 package generate 2 3 import "testing" 4 5 type test struct { 6 name string 7 in string 8 out string 9 } 10 11 func testStringFunc(t *testing.T, f func(string) string, tests []test) { 12 for _, test := range tests { 13 test := test 14 t.Run(test.name, func(t *testing.T) { 15 got := f(test.in) 16 if got != test.out { 17 t.Errorf("got %#v want %#v", got, test.out) 18 } 19 }) 20 } 21 } 22 23 func TestLowerFirst(t *testing.T) { 24 tests := []test{ 25 {"Empty", "", ""}, 26 {"SingleLower", "l", "l"}, 27 {"SingleUpper", "L", "l"}, 28 {"SingleUnicodeLower", "ļ", "ļ"}, 29 {"SingleUnicodeUpper", "Ļ", "ļ"}, 30 {"LongerLower", "lasdf", "lasdf"}, 31 {"LongerUpper", "Lasdf", "lasdf"}, 32 {"LongerUnicodeLower", "ļasdf", "ļasdf"}, 33 {"LongerUnicodeUpper", "Ļasdf", "ļasdf"}, 34 } 35 36 testStringFunc(t, lowerFirst, tests) 37 } 38 39 func TestUpperFirst(t *testing.T) { 40 tests := []test{ 41 {"Empty", "", ""}, 42 {"SingleLower", "l", "L"}, 43 {"SingleUpper", "L", "L"}, 44 {"SingleUnicodeLower", "ļ", "Ļ"}, 45 {"SingleUnicodeUpper", "Ļ", "Ļ"}, 46 {"LongerLower", "lasdf", "Lasdf"}, 47 {"LongerUpper", "Lasdf", "Lasdf"}, 48 {"LongerUnicodeLower", "ļasdf", "Ļasdf"}, 49 {"LongerUnicodeUpper", "Ļasdf", "Ļasdf"}, 50 } 51 52 testStringFunc(t, upperFirst, tests) 53 } 54 55 func TestGoConstName(t *testing.T) { 56 tests := []test{ 57 {"Empty", "", ""}, 58 {"AllCaps", "ASDF", "Asdf"}, 59 {"AllCapsWithUnderscore", "ASDF_GH", "AsdfGh"}, 60 {"JustUnderscore", "_", "_"}, 61 {"LeadingUnderscore", "_ASDF_GH", "AsdfGh"}, 62 } 63 64 testStringFunc(t, goConstName, tests) 65 }