| 3 | import "testing" |
| 4 | |
| 5 | func TestSlugify(t *testing.T) { |
| 6 | cases := []struct { |
| 7 | in, want string |
| 8 | }{ |
| 9 | {"hello world", "hello-world"}, |
| 10 | {"Add Auth To Budgeting App", "add-auth-to-budgeting-app"}, |
| 11 | {"Fix bug in login.py!", "fix-bug-in-login-py"}, |
| 12 | {" too many spaces ", "too-many-spaces"}, |
| 13 | {"--leading and trailing--", "leading-and-trailing"}, |
| 14 | } |
| 15 | for _, c := range cases { |
| 16 | got, err := Slugify(c.in) |
| 17 | if err != nil { |
| 18 | t.Errorf("Slugify(%q) returned error: %v", c.in, err) |
| 19 | continue |
| 20 | } |
| 21 | if got != c.want { |
| 22 | t.Errorf("Slugify(%q) = %q, want %q", c.in, got, c.want) |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestSlugifyTruncatesLongNames(t *testing.T) { |
| 28 | cases := []struct { |