1
0
Fork 0
This repository has been archived on 2025-09-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mareshq-yggdrasil/pkg/slug/slug_test.go
Vojtech Mares 2d32c80182
feat!: add slug to training
BREAKING CHANGE: update init migration
2024-06-26 22:24:36 +02:00

59 lines
1.4 KiB
Go

package slug
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestNew(t *testing.T) {
t.Run("Test New", func(t *testing.T) {
s := New("Hello World")
assert.Equal(t, "hello-world", s.String())
})
t.Run("Test New with !", func(t *testing.T) {
s := New("Hello World!")
assert.Equal(t, "hello-world", s.String())
})
t.Run("Test New with unicode", func(t *testing.T) {
s := New("Ahoj Světe!") // hello world in Czech
assert.Equal(t, "ahoj-svete", s.String())
})
}
func TestValidate(t *testing.T) {
t.Run("Test Validate", func(t *testing.T) {
assert.NoError(t, Validate("hello-world"))
})
t.Run("Test Validate with !", func(t *testing.T) {
assert.ErrorIs(t, Validate("hello-world!"), ErrInvalidSlug)
})
t.Run("Test Validate with unicode", func(t *testing.T) {
assert.ErrorIs(t, Validate("ahoj-světe"), ErrInvalidSlug)
})
t.Run("Test Validate with empty string", func(t *testing.T) {
assert.ErrorIs(t, Validate(""), ErrInvalidSlug)
})
}
func TestSlug_String(t *testing.T) {
t.Run("Test String", func(t *testing.T) {
s := Slug("hello-world")
assert.Equal(t, "hello-world", s.String())
})
}
func TestNewString(t *testing.T) {
t.Run("Test NewString", func(t *testing.T) {
input := "Hello World"
expected := "hello-world"
stringSlug := NewString(input)
assert.Equal(t, expected, stringSlug)
assert.IsType(t, string(""), stringSlug)
})
}