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 )
}
2022-03-30 20:36:25 +02:00
func TestClip ( t * testing . T ) {
2022-01-03 12:09:00 +01:00
t . Run ( "Foo" , func ( t * testing . T ) {
2022-03-30 20:36:25 +02:00
result := Clip ( "Foo" , 16 )
2022-01-03 12:09:00 +01:00
assert . Equal ( t , "Foo" , result )
assert . Equal ( t , 3 , len ( result ) )
} )
t . Run ( "TrimFoo" , func ( t * testing . T ) {
2022-03-30 20:36:25 +02:00
result := Clip ( " Foo " , 16 )
2022-01-03 12:09:00 +01:00
assert . Equal ( t , "Foo" , result )
assert . Equal ( t , 3 , len ( result ) )
} )
t . Run ( "TooLong" , func ( t * testing . T ) {
2022-03-30 20:36:25 +02:00
result := Clip ( " 幸福 Hanzi are logograms developed for the writing of Chinese! " , 16 )
2022-01-03 12:09:00 +01:00
assert . Equal ( t , "幸福 Hanzi are" , result )
assert . Equal ( t , 16 , len ( result ) )
} )
t . Run ( "ToASCII" , func ( t * testing . T ) {
2022-03-30 20:36:25 +02:00
result := Clip ( ToASCII ( strings . ToLower ( " 幸福 Hanzi are logograms developed for the writing of Chinese! Expressions in an index may not ...!" ) ) , ClipStringType )
assert . Equal ( t , "hanzi are logograms developed for the writing of chinese! expres" , result )
assert . Equal ( t , 64 , len ( result ) )
2022-01-03 12:09:00 +01:00
} )
t . Run ( "Empty" , func ( t * testing . T ) {
2022-03-30 20:36:25 +02:00
result := Clip ( "" , 999 )
2022-01-03 12:09:00 +01:00
assert . Equal ( t , "" , result )
assert . Equal ( t , 0 , len ( result ) )
} )
2021-09-03 19:02:26 +02:00
}
2022-03-30 20:36:25 +02:00
func TestSanitizeStringType ( t * testing . T ) {
result := SanitizeStringType ( " 幸福 Hanzi are logograms developed for the writing of Chinese! Expressions in an index may not ...!" )
assert . Equal ( t , "Hanzi are logograms developed for the writing of Chinese! Expres" , result )
assert . Equal ( t , ClipStringType , len ( result ) )
}
func TestSanitizeStringTypeLower ( t * testing . T ) {
result := SanitizeStringTypeLower ( " 幸福 Hanzi are logograms developed for the writing of Chinese! Expressions in an index may not ...!" )
assert . Equal ( t , "hanzi are logograms developed for the writing of chinese! expres" , result )
assert . Equal ( t , ClipStringType , len ( result ) )
2021-09-03 19:02:26 +02:00
}