2022-04-15 09:42:07 +02:00
|
|
|
package clean
|
2021-12-15 12:24:05 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestName(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", Name(""))
|
|
|
|
})
|
|
|
|
t.Run("BillGates", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "William Henry Gates III", Name("William Henry Gates III"))
|
|
|
|
})
|
|
|
|
t.Run("Quotes", func(t *testing.T) {
|
2022-09-30 00:42:19 +02:00
|
|
|
assert.Equal(t, "william HenRy gates'", Name("william \"HenRy\" gates' "))
|
2021-12-15 12:24:05 +01:00
|
|
|
})
|
|
|
|
t.Run("Slash", func(t *testing.T) {
|
2022-09-30 00:42:19 +02:00
|
|
|
assert.Equal(t, "william McCorn / gates'", Name("william\\ \"McCorn\" / gates' "))
|
2021-12-15 12:24:05 +01:00
|
|
|
})
|
|
|
|
t.Run("SpecialCharacters", func(t *testing.T) {
|
|
|
|
assert.Equal(t,
|
2022-09-30 00:42:19 +02:00
|
|
|
"'', '', '~', '', '/', '', '', '&', '|', '+', '=', '', Foo '@', '!', '?', ':', '', '', '', McBar '', ''",
|
2021-12-15 12:24:05 +01:00
|
|
|
Name("'\"', '`', '~', '\\\\', '/', '*', '%', '&', '|', '+', '=', '$', Foo '@', '!', '?', ':', ';', '<', '>', McBar '{', '}'"),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
t.Run("Chinese", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "陈 赵", Name(" 陈 赵"))
|
|
|
|
})
|
2023-06-26 15:57:56 +02:00
|
|
|
t.Run("Control Character", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "William Henry Gates III", Name("William Henry Gates III"+string(rune(1))))
|
|
|
|
})
|
|
|
|
t.Run("Space", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", Name(" "))
|
|
|
|
})
|
2021-12-15 12:24:05 +01:00
|
|
|
}
|
2022-09-30 00:42:19 +02:00
|
|
|
|
|
|
|
func TestNameCapitalized(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "", NameCapitalized(""))
|
|
|
|
})
|
|
|
|
t.Run("BillGates", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "William Henry Gates III", NameCapitalized("William Henry Gates III"))
|
|
|
|
})
|
|
|
|
t.Run("Quotes", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "William HenRy Gates'", NameCapitalized("william \"HenRy\" gates' "))
|
|
|
|
})
|
|
|
|
t.Run("Slash", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "William McCorn / Gates'", NameCapitalized("william\\ \"McCorn\" / gates' "))
|
|
|
|
})
|
|
|
|
t.Run("SpecialCharacters", func(t *testing.T) {
|
|
|
|
assert.Equal(t,
|
|
|
|
"'', '', '~', '', '/', '', '', '&', '|', '+', '=', '', Foo '@', '!', '?', ':', '', '', '', McBar '', ''",
|
|
|
|
Name("'\"', '`', '~', '\\\\', '/', '*', '%', '&', '|', '+', '=', '$', Foo '@', '!', '?', ':', ';', '<', '>', McBar '{', '}'"),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
t.Run("Chinese", func(t *testing.T) {
|
|
|
|
assert.Equal(t, "陈 赵", NameCapitalized(" 陈 赵"))
|
|
|
|
})
|
|
|
|
}
|