BlueGit

timfa bluegit

Files

bluegit / internal / names / names_test.go

names_test.go

feat: vrije tekst wordt een repository- of groepsslug
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Failed f9225546 History
names_test.go 1.5 KiB Download Raw
1package names
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestSlug(t *testing.T) {
9 cases := []struct {
10 kind string
11 in string
12 want string
13 }{
14 {"repo", "test repo", "test-repo"},
15 {"repo", " Test Repo ", "test-repo"},
16 {"repo", "test-repo", "test-repo"},
17 {"repo", "test_repo", "test_repo"},
18 {"repo", "foo---bar", "foo-bar"},
19 {"repo", "foo.bar", "foo.bar"},
20 {"repo", "foo/bar", "foo-bar"},
21 {"repo", "BlueGit", "bluegit"},
22 {"repo", "café repo", "cafe-repo"},
23 {"repo", "123 test", "123-test"},
24 {"repo", " a ", "a"},
25 {"repo", ".git", "git"},
26 {"group", "test repo", "test-repo"},
27 {"group", "Test Groep", "test-groep"},
28 {"group", "foo.bar", "foo-bar"},
29 {"group", "foo.git", "foo-git"},
30 {"group", "Werk", "werk"},
31 }
32 for _, tc := range cases {
33 got, err := Slug(tc.kind, tc.in)
34 if err != nil || got != tc.want {
35 t.Errorf("Slug(%s, %q) = %q, %v; wil %q", tc.kind, tc.in, got, err, tc.want)
36 }
37 }
38
39 bad := []struct{ kind, in string }{
40 {"repo", "!!!"},
41 {"repo", "foo.git"},
42 {"repo", ".."},
43 {"repo", ""},
44 {"repo", " "},
45 {"group", "123 test"},
46 {"group", "new"},
47 {"group", "settings"},
48 {"group", "!!!"},
49 {"other", "test"},
50 }
51 for _, tc := range bad {
52 if _, err := Slug(tc.kind, tc.in); err == nil {
53 t.Errorf("Slug(%s, %q) hoort te falen", tc.kind, tc.in)
54 }
55 }
56
57 got, err := Slug("repo", "test "+strings.Repeat("a", 80))
58 if err != nil || len(got) > 63 || !strings.HasPrefix(got, "test-") {
59 t.Fatalf("lange naam %q %v", got, err)
60 }
61}