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) }) }