github.com/codykaup/genqlient@v0.6.2/generate/imports_test.go (about) 1 package generate 2 3 import ( 4 "go/token" 5 "testing" 6 ) 7 8 func TestMakeIdentifier(t *testing.T) { 9 tests := []struct { 10 testName string 11 input string 12 expected string 13 }{ 14 {"GoodIdentifier", "myIdent", "myIdent"}, 15 {"GoodIdentifierNumbers", "myIdent1234", "myIdent1234"}, 16 {"NumberPrefix", "1234myIdent", "myIdent"}, 17 {"OnlyNumbers", "1234", "alias"}, 18 {"Dashes", "my-ident", "myident"}, 19 // Note: most Go implementations won't actually allow 20 // this package-path, but the spec is pretty vague 21 // so make sure to handle it. 22 {"JunkAnd", "my!!\\\\\nident", "myident"}, 23 {"JunkOnly", "!!\\\\\n", "alias"}, 24 {"Accents", "née", "née"}, 25 {"Kanji", "日本", "日本"}, 26 {"EmojiAnd", "ident👍", "ident"}, 27 {"EmojiOnly", "👍", "alias"}, 28 } 29 30 for _, test := range tests { 31 test := test 32 t.Run(test.testName, func(t *testing.T) { 33 actual := makeIdentifier(test.input) 34 if actual != test.expected { 35 t.Errorf("mismatch:\ngot: %s\nwant: %s", actual, test.expected) 36 } 37 if !token.IsIdentifier(actual) { 38 t.Errorf("not a valid identifier: %s", actual) 39 } 40 }) 41 } 42 }