| 25 | } |
| 26 | |
| 27 | func TestSlugifyTruncatesLongNames(t *testing.T) { |
| 28 | cases := []struct { |
| 29 | in, want string |
| 30 | }{ |
| 31 | // Exactly 6 words — no truncation. |
| 32 | {"clarify caas exit plan scope today", "clarify-caas-exit-plan-scope-today"}, |
| 33 | // 7 words — truncated to 6. |
| 34 | {"clarify caas exit plan scope with jayant", "clarify-caas-exit-plan-scope-with"}, |
| 35 | // 10 words. |
| 36 | {"one two three four five six seven eight nine ten", "one-two-three-four-five-six"}, |
| 37 | } |
| 38 | for _, c := range cases { |
| 39 | got, err := Slugify(c.in) |
| 40 | if err != nil { |
| 41 | t.Errorf("Slugify(%q) returned error: %v", c.in, err) |
| 42 | continue |
| 43 | } |
| 44 | if got != c.want { |
| 45 | t.Errorf("Slugify(%q) = %q, want %q", c.in, got, c.want) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestSlugifyEmpty(t *testing.T) { |
| 51 | if _, err := Slugify(""); err == nil { |