slug_test.go 649 B

12345678910111213141516171819202122232425
  1. package slug
  2. import (
  3. "testing"
  4. )
  5. func Test_slug(t *testing.T) {
  6. tests := []struct {
  7. name string
  8. arg string
  9. want string
  10. }{
  11. {name: "Replace space with -", arg: "test title slug", want: "test-title-slug"},
  12. {name: "Replace special char with -", arg: "test&title*~slug", want: "test-title-slug"},
  13. {name: "Convert uppercase to lowercase", arg: "TestSlug", want: "testslug"},
  14. {name: "Convert other languages", arg: "测试标题", want: "ce-shi-biao-ti"},
  15. }
  16. for _, tt := range tests {
  17. t.Run(tt.name, func(t *testing.T) {
  18. if got := slug(tt.arg); got != tt.want {
  19. t.Errorf("slug() = %v, want %v", got, tt.want)
  20. }
  21. })
  22. }
  23. }