| 1 | package report |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestShortNames(t *testing.T) { |
| 9 | type testCase struct { |
| 10 | name string |
| 11 | in string |
| 12 | out []string |
| 13 | } |
| 14 | test := func(name, in string, out ...string) testCase { |
| 15 | return testCase{name, in, out} |
| 16 | } |
| 17 | |
| 18 | for _, c := range []testCase{ |
| 19 | test("empty", "", ""), |
| 20 | test("simple", "foo", "foo"), |
| 21 | test("trailingsep", "foo.bar.", "foo.bar.", "bar."), |
| 22 | test("cplusplus", "a::b::c", "a::b::c", "b::c", "c"), |
| 23 | test("dotted", "a.b.c", "a.b.c", "b.c", "c"), |
| 24 | test("mixed_separators", "a::b.c::d", "a::b.c::d", "b.c::d", "c::d", "d"), |
| 25 | test("call_operator", "foo::operator()", "foo::operator()", "operator()"), |
| 26 | } { |
| 27 | t.Run(c.name, func(t *testing.T) { |
| 28 | got := shortNameList(c.in) |
| 29 | if !reflect.DeepEqual(c.out, got) { |
| 30 | t.Errorf("shortNameList(%q) = %#v, expecting %#v", c.in, got, c.out) |
| 31 | } |
| 32 | }) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestFileNameSuffixes(t *testing.T) { |
| 37 | type testCase struct { |
| 38 | name string |
| 39 | in string |
| 40 | out []string |
| 41 | } |
| 42 | test := func(name, in string, out ...string) testCase { |
| 43 | return testCase{name, in, out} |
| 44 | } |
| 45 | |
| 46 | for _, c := range []testCase{ |
| 47 | test("empty", "", ""), |
| 48 | test("simple", "foo", "foo"), |
| 49 | test("manypaths", "a/b/c", "a/b/c", "b/c", "c"), |
| 50 | test("leading", "/a/b", "/a/b", "a/b", "b"), |
| 51 | test("trailing", "a/b", "a/b", "b"), |
| 52 | } { |
| 53 | t.Run(c.name, func(t *testing.T) { |
| 54 | got := fileNameSuffixes(c.in) |
| 55 | if !reflect.DeepEqual(c.out, got) { |
| 56 | t.Errorf("fileNameSuffixes(%q) = %#v, expecting %#v", c.in, got, c.out) |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | } |