Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix edge case in truncate function allowing too long slugs #74

Merged
merged 7 commits into from
Sep 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve TestSlugMakeSmartTruncate cases
matrixik authored Sep 27, 2022
commit 133079cd8453025964740da2e8a71ca316195f3f
24 changes: 21 additions & 3 deletions slug_test.go
Original file line number Diff line number Diff line change
@@ -283,15 +283,33 @@ func TestSlugMakeSmartTruncate(t *testing.T) {
want string
smartTruncate bool
}{
{"DOBROSLAWZYBORT", 100, "dobroslawzybort", true},
{"Dobroslaw Zybort", 100, "dobroslaw-zybort", true},
{"Dobrosław Żybort", 5, "dobro", true},
{"Dobroslaw Zybort", 9, "dobroslaw", true},
{"Dobroslaw Zybort", 12, "dobroslaw", true},
{"Dobroslaw Zybort", 15, "dobroslaw", true},
{"Dobroslaw Zybort", 16, "dobroslaw-zybort", true},
{"Dobroslaw Zybort", 17, "dobroslaw-zybort", true},
{"Dobroslaw Zybort", 100, "dobroslaw-zybort", true},
{"abc", 2, "ab", true},
{"abc-", 2, "ab", true},
{"abc", 4, "abc", true},
{"abc-", 4, "abc", true},
{"abc-de", 4, "abc", true},
{"abc-de", 5, "abc", true},
{"abc-de", 6, "abc-de", true},
{"abc-de", 7, "abc-de", true},
{"abc-de-fg", 6, "abc-de", true},
{"abc-de-fg", 7, "abc-de", true},
{"abc-de-fg", 8, "abc-de", true},
{"abc-de-fg", 9, "abc-de-fg", true},
{"abc-de-fg", 10, "abc-de-fg", true},

{"DOBROSLAWZYBORT", 9, "dobroslaw", true},
{"DOBROSLAWZYBORT", 100, "dobroslawzybort", true},
{" Dobroslaw Zybort ?", 12, "dobroslaw", true},
{"Ala ma 6 kotów.", 10, "ala-ma-6", true},
{"Dobrosław Żybort", 5, "dobro", true},

// No smart truncate
{"Long branch-name", 14, "long-branch-na", false},
{"Long branch-name", 12, "long-branch", false},
}