photoprism/pkg/txt/strings_test.go
2020-04-28 17:03:37 +02:00

79 lines
1.9 KiB
Go

package txt
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestContainsNumber(t *testing.T) {
t.Run("True", func(t *testing.T) {
assert.Equal(t, true, ContainsNumber("f3abcde"))
})
t.Run("False", func(t *testing.T) {
assert.Equal(t, false, ContainsNumber("abcd"))
})
}
func TestIsSeparator(t *testing.T) {
t.Run("rune A", func(t *testing.T) {
assert.Equal(t, false, isSeparator('A'))
})
t.Run("rune 99", func(t *testing.T) {
assert.Equal(t, false, isSeparator('9'))
})
t.Run("rune /", func(t *testing.T) {
assert.Equal(t, true, isSeparator('/'))
})
t.Run("rune \\", func(t *testing.T) {
assert.Equal(t, true, isSeparator('\\'))
})
t.Run("rune ♥ ", func(t *testing.T) {
assert.Equal(t, false, isSeparator('♥'))
})
t.Run("rune space", func(t *testing.T) {
assert.Equal(t, true, isSeparator(' '))
})
t.Run("rune '", func(t *testing.T) {
assert.Equal(t, false, isSeparator('\''))
})
t.Run("rune ý", func(t *testing.T) {
assert.Equal(t, false, isSeparator('ý'))
})
}
func TestUcFirst(t *testing.T) {
t.Run("photo-lover", func(t *testing.T) {
assert.Equal(t, "Photo-lover", UcFirst("photo-lover"))
})
t.Run("cat", func(t *testing.T) {
assert.Equal(t, "Cat", UcFirst("Cat"))
})
t.Run("empty string", func(t *testing.T) {
assert.Equal(t, "", UcFirst(""))
})
}
func TestTitle(t *testing.T) {
t.Run("Browse your life in pictures", func(t *testing.T) {
assert.Equal(t, "Browse Your Life In Pictures", Title("Browse your life in pictures"))
})
t.Run("photo-lover", func(t *testing.T) {
assert.Equal(t, "Photo-Lover", Title("photo-lover"))
})
}
func TestBool(t *testing.T) {
t.Run("not empty", func(t *testing.T) {
assert.Equal(t, true, Bool("Browse your life in pictures"))
})
t.Run("no", func(t *testing.T) {
assert.Equal(t, false, Bool("no"))
})
t.Run("false", func(t *testing.T) {
assert.Equal(t, false, Bool("false"))
})
t.Run("empty", func(t *testing.T) {
assert.Equal(t, false, Bool(""))
})
}