2020-02-02 02:00:47 +01:00
|
|
|
package txt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWords(t *testing.T) {
|
2020-04-16 15:57:07 +02:00
|
|
|
t.Run("I'm a lazy-brown fox!", func(t *testing.T) {
|
|
|
|
result := Words("I'm a lazy-BRoWN fox!")
|
|
|
|
assert.Equal(t, []string{"lazy-BRoWN", "fox"}, result)
|
2020-02-02 02:00:47 +01:00
|
|
|
})
|
|
|
|
t.Run("no result", func(t *testing.T) {
|
|
|
|
result := Words("x")
|
|
|
|
assert.Equal(t, []string(nil), result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:57:07 +02:00
|
|
|
func TestFilenameWords(t *testing.T) {
|
|
|
|
t.Run("I'm a lazy-brown fox!", func(t *testing.T) {
|
|
|
|
result := FilenameWords("I'm a lazy-BRoWN fox!")
|
|
|
|
assert.Equal(t, []string{"lazy", "BRoWN", "fox"}, result)
|
|
|
|
})
|
|
|
|
t.Run("no result", func(t *testing.T) {
|
|
|
|
result := FilenameWords("x")
|
|
|
|
assert.Equal(t, []string(nil), result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-16 23:30:30 +02:00
|
|
|
func TestFilenameKeywords(t *testing.T) {
|
|
|
|
t.Run("I'm a lazy-brown var fox.jpg!", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("I'm a lazy-brown var fox.jpg!")
|
|
|
|
assert.Equal(t, []string{"lazy", "brown", "fox"}, result)
|
|
|
|
})
|
|
|
|
t.Run("no result", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("x")
|
|
|
|
assert.Equal(t, []string(nil), result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-02 02:00:47 +01:00
|
|
|
func TestKeywords(t *testing.T) {
|
|
|
|
t.Run("I'm a lazy brown fox!", func(t *testing.T) {
|
|
|
|
result := Keywords("I'm a lazy BRoWN img!")
|
|
|
|
assert.Equal(t, []string{"lazy", "brown"}, result)
|
|
|
|
})
|
|
|
|
t.Run("no result", func(t *testing.T) {
|
|
|
|
result := Keywords("was")
|
|
|
|
assert.Equal(t, []string(nil), result)
|
|
|
|
})
|
|
|
|
}
|
2020-03-25 12:39:07 +01:00
|
|
|
|
|
|
|
func TestUniqueWords(t *testing.T) {
|
|
|
|
t.Run("many", func(t *testing.T) {
|
2020-04-16 23:30:30 +02:00
|
|
|
result := UniqueWords([]string{"lazy", "jpg", "Brown", "apple", "brown", "new-york", "JPG"})
|
|
|
|
assert.Equal(t, []string{"apple", "brown", "jpg", "lazy", "new-york"}, result)
|
2020-03-25 12:39:07 +01:00
|
|
|
})
|
|
|
|
t.Run("one", func(t *testing.T) {
|
|
|
|
result := UniqueWords([]string{"lazy"})
|
|
|
|
assert.Equal(t, []string{"lazy"}, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUniqueKeywords(t *testing.T) {
|
|
|
|
t.Run("many", func(t *testing.T) {
|
2020-04-16 21:49:31 +02:00
|
|
|
result := UniqueKeywords("lazy, Brown, apple, new-york, brown, ...")
|
2020-04-16 15:57:07 +02:00
|
|
|
assert.Equal(t, []string{"apple", "brown", "lazy", "new-york"}, result)
|
2020-03-25 12:39:07 +01:00
|
|
|
})
|
|
|
|
t.Run("one", func(t *testing.T) {
|
|
|
|
result := UniqueKeywords("")
|
|
|
|
assert.Equal(t, []string(nil), result)
|
|
|
|
})
|
|
|
|
}
|