1package spec
2
3import "testing"
4
5func TestPackageName(t *testing.T) {
6 tests := []struct{ in, want string }{
7 {"wlr-layer-shell-unstable-v1.xml", "wlrlayershell"},
8 {"tablet-v2.xml", "tablet"},
9 {"presentation-time.xml", "presentationtime"},
10 {"xdg-shell.xml", "xdgshell"},
11 {"wayland.xml", "wayland"},
12 {"ext-foreign-toplevel-list-v1.xml", "extforeigntoplevellist"},
13 {"xdg-foreign-unstable-v2.xml", "xdgforeign"},
14 {"stable/xdg-shell/xdg-shell.xml", "xdgshell"},
15 {"server-decoration.xml", "serverdecoration"},
16 }
17 for _, tt := range tests {
18 got := PackageName(tt.in)
19 if got != tt.want {
20 t.Errorf("PackageName(%q) = %q, want %q", tt.in, got, tt.want)
21 }
22 if !ValidPackageName(got) {
23 t.Errorf("PackageName(%q) = %q is not a valid Go package name", tt.in, got)
24 }
25 }
26}
27
28func TestValidPackageName(t *testing.T) {
29 for _, name := range []string{"wayland", "xdgshell", "a1"} {
30 if !ValidPackageName(name) {
31 t.Errorf("ValidPackageName(%q) = false, want true", name)
32 }
33 }
34 for _, name := range []string{"", "_", "1a", "a-b", "func", "type", "a.b"} {
35 if ValidPackageName(name) {
36 t.Errorf("ValidPackageName(%q) = true, want false", name)
37 }
38 }
39}