47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitize(t *testing.T) {
|
|
if res := Sanitize("abcdef0123ABCDEFéçè_ ?.!=îôù"); res != "abcdef0123abcdefece------iou" {
|
|
t.Errorf("unexpected Sanitize() answer '%s' != 'abcdef0123abcdefece------iou'", res)
|
|
}
|
|
}
|
|
|
|
func TestNullableString(t *testing.T) {
|
|
if res := NullableString("test"); res != "test" {
|
|
t.Errorf("unexepected NullableString() answer '%s' != 'test'", res)
|
|
}
|
|
|
|
if res := NullableString(""); res != nil {
|
|
t.Errorf("unexepected NullableString() answer '%s' != nil", res)
|
|
}
|
|
}
|
|
|
|
func TestNullableInt(t *testing.T) {
|
|
if res := NullableInt(3); res != 3 {
|
|
t.Errorf("unexepected NullableInt() answer %s != 3", res)
|
|
}
|
|
|
|
if res := NullableInt(0); res != nil {
|
|
t.Errorf("unexepected NullableInt() answer %s != nil", res)
|
|
}
|
|
}
|
|
|
|
func TestArrayContains(t *testing.T) {
|
|
if !ArrayContains([]string{"bird", "apple", "ocean", "fork", "anchor"}, "bird") {
|
|
t.Errorf("unexpected ArrayContains() false answer for 'bird'")
|
|
}
|
|
if ArrayContains([]string{"bird", "apple", "ocean", "fork", "anchor"}, "potato") {
|
|
t.Errorf("unexpected ArrayContains() true answer for 'potato'")
|
|
}
|
|
}
|
|
|
|
func TestAtoI(t *testing.T) {
|
|
if res := AtoI("3"); res != 3 {
|
|
t.Errorf("unexpected answer %d != 3", res)
|
|
}
|
|
}
|