2020-02-02 02:00:47 +01:00
|
|
|
package txt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-20 22:27:18 +02:00
|
|
|
func TestUnknownWord(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.True(t, UnknownWord(""))
|
|
|
|
})
|
|
|
|
t.Run("qx", func(t *testing.T) {
|
|
|
|
assert.True(t, UnknownWord("qx"))
|
|
|
|
})
|
|
|
|
t.Run("atz", func(t *testing.T) {
|
|
|
|
assert.True(t, UnknownWord("atz"))
|
|
|
|
})
|
|
|
|
t.Run("xqx", func(t *testing.T) {
|
|
|
|
assert.True(t, UnknownWord("xqx"))
|
|
|
|
})
|
2021-09-20 22:28:20 +02:00
|
|
|
t.Run("kuh", func(t *testing.T) {
|
|
|
|
assert.False(t, UnknownWord("kuh"))
|
|
|
|
})
|
|
|
|
t.Run("muh", func(t *testing.T) {
|
|
|
|
assert.False(t, UnknownWord("muh"))
|
|
|
|
})
|
2021-09-20 22:27:18 +02:00
|
|
|
t.Run("桥", func(t *testing.T) {
|
|
|
|
assert.False(t, UnknownWord("桥"))
|
|
|
|
})
|
|
|
|
t.Run("桥船", func(t *testing.T) {
|
|
|
|
assert.False(t, UnknownWord("桥船"))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-02 02:00:47 +01:00
|
|
|
func TestWords(t *testing.T) {
|
2020-12-27 16:37:28 +01:00
|
|
|
t.Run("桥", func(t *testing.T) {
|
|
|
|
result := Words("桥")
|
|
|
|
assert.Equal(t, []string{"桥"}, result)
|
|
|
|
})
|
2020-12-30 13:59:27 +01:00
|
|
|
t.Run("桥船", func(t *testing.T) {
|
|
|
|
result := Words("桥船")
|
|
|
|
assert.Equal(t, []string{"桥船"}, result)
|
|
|
|
})
|
|
|
|
t.Run("桥船猫", func(t *testing.T) {
|
|
|
|
result := Words("桥船猫")
|
|
|
|
assert.Equal(t, []string{"桥船猫"}, result)
|
|
|
|
})
|
|
|
|
t.Run("谢谢!", func(t *testing.T) {
|
|
|
|
result := Words("谢谢!")
|
|
|
|
assert.Equal(t, []string{"谢谢"}, result)
|
|
|
|
})
|
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!")
|
2021-05-05 12:32:49 +02:00
|
|
|
assert.Equal(t, []string{"I'm", "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-05-18 11:12:40 +02:00
|
|
|
t.Run("Österreich Urlaub", func(t *testing.T) {
|
|
|
|
result := Words("Österreich Urlaub")
|
|
|
|
assert.Equal(t, []string{"Österreich", "Urlaub"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Schäferhund", func(t *testing.T) {
|
|
|
|
result := Words("Schäferhund")
|
|
|
|
assert.Equal(t, []string{"Schäferhund"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Île de la Réunion", func(t *testing.T) {
|
|
|
|
result := Words("Île de la Réunion")
|
2021-05-04 15:02:54 +02:00
|
|
|
assert.Equal(t, []string{"Île", "de", "la", "Réunion"}, result)
|
2020-05-18 11:12:40 +02:00
|
|
|
})
|
2021-03-03 15:41:32 +01:00
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
result := Words("")
|
|
|
|
assert.Empty(t, result)
|
|
|
|
})
|
2021-05-05 12:23:19 +02:00
|
|
|
t.Run("trim", func(t *testing.T) {
|
|
|
|
result := Words(" -foo- -")
|
|
|
|
assert.Equal(t, []string{"foo"}, result)
|
|
|
|
})
|
2021-05-05 12:32:49 +02:00
|
|
|
t.Run("McDonalds", func(t *testing.T) {
|
|
|
|
result := Words(" McDonald's FOO'bar-'")
|
|
|
|
assert.Equal(t, []string{"McDonald's", "FOO'bar"}, result)
|
|
|
|
})
|
|
|
|
// McDonald's
|
2020-02-02 02:00:47 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:03:37 +02:00
|
|
|
func TestReplaceSpaces(t *testing.T) {
|
|
|
|
t.Run("I love Cats", func(t *testing.T) {
|
|
|
|
result := ReplaceSpaces("I love Cats", "dog")
|
|
|
|
assert.Equal(t, "IdoglovedogCats", 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-05-18 11:17:14 +02:00
|
|
|
t.Run("Österreich Urlaub", func(t *testing.T) {
|
|
|
|
result := FilenameWords("Österreich Urlaub")
|
|
|
|
assert.Equal(t, []string{"Österreich", "Urlaub"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Schäferhund", func(t *testing.T) {
|
|
|
|
result := FilenameWords("Schäferhund")
|
|
|
|
assert.Equal(t, []string{"Schäferhund"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Île de la Réunion", func(t *testing.T) {
|
|
|
|
result := FilenameWords("Île de la Réunion")
|
|
|
|
assert.Equal(t, []string{"Île", "Réunion"}, result)
|
|
|
|
})
|
2021-03-03 15:41:32 +01:00
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
result := FilenameWords("")
|
|
|
|
assert.Empty(t, result)
|
|
|
|
})
|
2020-04-16 15:57:07 +02:00
|
|
|
}
|
|
|
|
|
2021-05-04 15:02:54 +02:00
|
|
|
func TestAddToWords(t *testing.T) {
|
|
|
|
t.Run("I'm a lazy-BRoWN fox!", func(t *testing.T) {
|
|
|
|
result := AddToWords([]string{"foo", "bar", "fox"}, "Yellow banana, apple; pan-pot")
|
|
|
|
assert.Equal(t, []string{"apple", "banana", "bar", "foo", "fox", "pan-pot", "yellow"}, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMergeWords(t *testing.T) {
|
|
|
|
t.Run("I'm a lazy-BRoWN fox!", func(t *testing.T) {
|
|
|
|
result := MergeWords("I'm a lazy-BRoWN fox!", "Yellow banana, apple; pan-pot")
|
2021-05-05 12:32:49 +02:00
|
|
|
assert.Equal(t, "apple, banana, fox, i'm, lazy-brown, pan-pot, yellow", result)
|
2021-05-04 15:02:54 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-16 23:30:30 +02:00
|
|
|
func TestFilenameKeywords(t *testing.T) {
|
2020-12-27 16:37:28 +01:00
|
|
|
t.Run("桥.jpg", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("桥.jpg")
|
|
|
|
assert.Equal(t, []string{"桥"}, result)
|
|
|
|
})
|
2020-04-16 23:30:30 +02:00
|
|
|
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-05-18 11:17:14 +02:00
|
|
|
t.Run("Österreich Urlaub", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("Österreich Urlaub")
|
|
|
|
assert.Equal(t, []string{"österreich", "urlaub"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Schäferhund", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("Schäferhund")
|
|
|
|
assert.Equal(t, []string{"schäferhund"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Île de la Réunion", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("Île de la Réunion")
|
|
|
|
assert.Equal(t, []string{"île", "réunion"}, result)
|
|
|
|
})
|
2021-03-03 15:41:32 +01:00
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
result := FilenameKeywords("")
|
|
|
|
assert.Empty(t, result)
|
|
|
|
})
|
2020-04-16 23:30:30 +02:00
|
|
|
}
|
|
|
|
|
2020-02-02 02:00:47 +01:00
|
|
|
func TestKeywords(t *testing.T) {
|
2020-12-30 13:59:27 +01:00
|
|
|
t.Run("桥", func(t *testing.T) {
|
|
|
|
result := Keywords("桥")
|
|
|
|
assert.Equal(t, []string{"桥"}, result)
|
|
|
|
})
|
|
|
|
t.Run("桥船", func(t *testing.T) {
|
|
|
|
result := Keywords("桥船")
|
|
|
|
assert.Equal(t, []string{"桥船"}, result)
|
|
|
|
})
|
|
|
|
t.Run("桥船猫", func(t *testing.T) {
|
|
|
|
result := Keywords("桥船猫")
|
|
|
|
assert.Equal(t, []string{"桥船猫"}, result)
|
|
|
|
})
|
|
|
|
t.Run("谢谢!", func(t *testing.T) {
|
|
|
|
result := Keywords("谢谢!")
|
|
|
|
assert.Equal(t, []string{"谢谢"}, result)
|
|
|
|
})
|
2020-02-02 02:00:47 +01:00
|
|
|
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-05-18 11:17:14 +02:00
|
|
|
t.Run("Österreich Urlaub", func(t *testing.T) {
|
|
|
|
result := Keywords("Österreich Urlaub")
|
|
|
|
assert.Equal(t, []string{"österreich", "urlaub"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Schäferhund", func(t *testing.T) {
|
|
|
|
result := Keywords("Schäferhund")
|
|
|
|
assert.Equal(t, []string{"schäferhund"}, result)
|
|
|
|
})
|
|
|
|
t.Run("Île de la Réunion", func(t *testing.T) {
|
|
|
|
result := Keywords("Île de la Réunion")
|
|
|
|
assert.Equal(t, []string{"île", "réunion"}, result)
|
|
|
|
})
|
2021-03-03 15:41:32 +01:00
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
result := Keywords("")
|
|
|
|
assert.Empty(t, result)
|
|
|
|
})
|
2020-02-02 02:00:47 +01:00
|
|
|
}
|
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)
|
|
|
|
})
|
|
|
|
}
|
2020-05-28 21:20:42 +02:00
|
|
|
|
|
|
|
func TestRemoveFromWords(t *testing.T) {
|
|
|
|
t.Run("brown apple", func(t *testing.T) {
|
|
|
|
result := RemoveFromWords([]string{"lazy", "jpg", "Brown", "apple", "brown", "new-york", "JPG"}, "brown apple")
|
|
|
|
assert.Equal(t, []string{"jpg", "lazy", "new-york"}, result)
|
|
|
|
})
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
result := RemoveFromWords([]string{"lazy", "jpg", "Brown", "apple"}, "")
|
|
|
|
assert.Equal(t, []string{"apple", "brown", "jpg", "lazy"}, result)
|
|
|
|
})
|
|
|
|
}
|
2022-01-03 13:30:34 +01:00
|
|
|
|
|
|
|
func TestStopwordsOnly(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.False(t, StopwordsOnly(""))
|
|
|
|
})
|
|
|
|
t.Run("FoldersDateienFile", func(t *testing.T) {
|
|
|
|
assert.True(t, StopwordsOnly("Folders Dateien File"))
|
|
|
|
})
|
|
|
|
t.Run("FoldersDateienFile", func(t *testing.T) {
|
|
|
|
assert.False(t, StopwordsOnly("Folders Dateien Meme File"))
|
|
|
|
})
|
|
|
|
t.Run("qx", func(t *testing.T) {
|
|
|
|
assert.True(t, StopwordsOnly("qx"))
|
|
|
|
})
|
|
|
|
t.Run("atz", func(t *testing.T) {
|
|
|
|
assert.True(t, StopwordsOnly("atz"))
|
|
|
|
})
|
|
|
|
t.Run("xqx", func(t *testing.T) {
|
|
|
|
assert.True(t, StopwordsOnly("xqx"))
|
|
|
|
})
|
|
|
|
t.Run("kuh", func(t *testing.T) {
|
|
|
|
assert.False(t, StopwordsOnly("kuh"))
|
|
|
|
})
|
|
|
|
t.Run("muh", func(t *testing.T) {
|
|
|
|
assert.False(t, StopwordsOnly("muh"))
|
|
|
|
})
|
|
|
|
t.Run("桥", func(t *testing.T) {
|
|
|
|
assert.False(t, StopwordsOnly("桥"))
|
|
|
|
})
|
|
|
|
t.Run("桥船", func(t *testing.T) {
|
|
|
|
assert.False(t, StopwordsOnly("桥船"))
|
|
|
|
})
|
|
|
|
}
|