2021-09-03 19:02:26 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2022-01-03 12:09:00 +01:00
|
|
|
"strings"
|
2021-09-03 19:02:26 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestToASCII(t *testing.T) {
|
|
|
|
result := ToASCII("幸福 = Happiness.")
|
|
|
|
assert.Equal(t, " = Happiness.", result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTrim(t *testing.T) {
|
2022-01-03 12:09:00 +01:00
|
|
|
t.Run("Foo", func(t *testing.T) {
|
|
|
|
result := Trim("Foo", 16)
|
|
|
|
assert.Equal(t, "Foo", result)
|
|
|
|
assert.Equal(t, 3, len(result))
|
|
|
|
})
|
|
|
|
t.Run("TrimFoo", func(t *testing.T) {
|
|
|
|
result := Trim(" Foo ", 16)
|
|
|
|
assert.Equal(t, "Foo", result)
|
|
|
|
assert.Equal(t, 3, len(result))
|
|
|
|
})
|
|
|
|
t.Run("TooLong", func(t *testing.T) {
|
|
|
|
result := Trim(" 幸福 Hanzi are logograms developed for the writing of Chinese! ", 16)
|
|
|
|
assert.Equal(t, "幸福 Hanzi are", result)
|
|
|
|
assert.Equal(t, 16, len(result))
|
|
|
|
})
|
|
|
|
t.Run("ToASCII", func(t *testing.T) {
|
|
|
|
result := Trim(ToASCII(strings.ToLower(" 幸福 Hanzi are logograms developed for the writing of Chinese! ")), TrimTypeString)
|
|
|
|
assert.Equal(t, "hanzi are logograms developed for the wr", result)
|
|
|
|
assert.Equal(t, 40, len(result))
|
|
|
|
})
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
result := Trim("", 999)
|
|
|
|
assert.Equal(t, "", result)
|
|
|
|
assert.Equal(t, 0, len(result))
|
|
|
|
})
|
2021-09-03 19:02:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSanitizeTypeString(t *testing.T) {
|
|
|
|
result := SanitizeTypeString(" 幸福 Hanzi are logograms developed for the writing of Chinese! ")
|
2022-01-03 12:09:00 +01:00
|
|
|
assert.Equal(t, "hanzi are logograms developed for the wr", result)
|
|
|
|
assert.Equal(t, TrimTypeString, len(result))
|
2021-09-03 19:02:26 +02:00
|
|
|
}
|