| 1 | package internal |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/go-quicktest/qt" |
| 7 | ) |
| 8 | |
| 9 | func TestIdentifier(t *testing.T) { |
| 10 | testcases := []struct { |
| 11 | in, out string |
| 12 | }{ |
| 13 | {".rodata", "Rodata"}, |
| 14 | {"_foo_bar_", "FooBar"}, |
| 15 | {"ipv6_test", "Ipv6Test"}, |
| 16 | {"FOO_BAR", "FOO_BAR"}, |
| 17 | {"FOO_", "FOO_"}, |
| 18 | {"FOO__BAR", "FOO__BAR"}, |
| 19 | {"FOO___BAR", "FOO___BAR"}, |
| 20 | {"_FOO__BAR", "FOO__BAR"}, |
| 21 | {"__FOO__BAR", "FOO__BAR"}, |
| 22 | } |
| 23 | |
| 24 | for _, tc := range testcases { |
| 25 | have := Identifier(tc.in) |
| 26 | if have != tc.out { |
| 27 | t.Errorf("Expected %q as output of %q, got %q", tc.out, tc.in, have) |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | type foo struct{} |
| 33 | |
| 34 | func TestGoTypeName(t *testing.T) { |
| 35 | type bar[T any] struct{} |
| 36 | qt.Assert(t, qt.Equals(GoTypeName(foo{}), "foo")) |
| 37 | qt.Assert(t, qt.Equals(GoTypeName(new(foo)), "foo")) |
| 38 | qt.Assert(t, qt.Equals(GoTypeName(new(*foo)), "foo")) |
| 39 | qt.Assert(t, qt.Equals(GoTypeName(bar[int]{}), "bar[int]")) |
| 40 | qt.Assert(t, qt.Equals(GoTypeName(bar[foo]{}), "bar[foo]")) |
| 41 | qt.Assert(t, qt.Equals(GoTypeName(bar[testing.T]{}), "bar[testing.T]")) |
| 42 | } |