From ce9651df108421e6629ae15176ce84044b83b4ec Mon Sep 17 00:00:00 2001 From: theresa Date: Wed, 3 Mar 2021 15:41:32 +0100 Subject: [PATCH] Tests: Add tests for /pkg --- pkg/colors/colors_test.go | 3 +++ pkg/fs/birthtime_test.go | 18 ++++++++++++++++++ pkg/fs/cache_test.go | 9 ++++++++- pkg/fs/case_test.go | 9 +++++++++ pkg/txt/capitalization_test.go | 3 +++ pkg/txt/contains_test.go | 9 +++++++++ pkg/txt/is_test.go | 6 ++++++ pkg/txt/words_test.go | 16 ++++++++++++++++ 8 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 pkg/fs/birthtime_test.go diff --git a/pkg/colors/colors_test.go b/pkg/colors/colors_test.go index efa67d073..e964ed219 100644 --- a/pkg/colors/colors_test.go +++ b/pkg/colors/colors_test.go @@ -41,6 +41,9 @@ func TestChroma_Hex(t *testing.T) { assert.Equal(t, "9B", perception.Chroma.Hex()) }) } +func TestColor_Uint8(t *testing.T) { + assert.Equal(t, uint8(7), Cyan.Uint8()) +} func TestChroma_Value(t *testing.T) { lum := []Luminance{1, 16, 2, 4, 15, 16, 1, 0, 8} diff --git a/pkg/fs/birthtime_test.go b/pkg/fs/birthtime_test.go new file mode 100644 index 000000000..d438c9ae2 --- /dev/null +++ b/pkg/fs/birthtime_test.go @@ -0,0 +1,18 @@ +package fs + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBirthTime(t *testing.T) { + t.Run("time now", func(t *testing.T) { + result := BirthTime("/testdata/Test.jpg") + assert.NotEmpty(t, result) + }) + t.Run("mod time", func(t *testing.T) { + result := BirthTime("./testdata/CATYELLOW.jpg") + assert.NotEmpty(t, result) + }) +} diff --git a/pkg/fs/cache_test.go b/pkg/fs/cache_test.go index f4b87f7c2..cace5ad87 100644 --- a/pkg/fs/cache_test.go +++ b/pkg/fs/cache_test.go @@ -9,13 +9,20 @@ import ( ) func TestCachePath(t *testing.T) { - t.Run("error", func(t *testing.T) { + t.Run("hash too short", func(t *testing.T) { result, err := CachePath("/foo/bar", "123", "baz", false) assert.Equal(t, "", result) assert.EqualError(t, err, "cache: hash '123' is too short") }) + t.Run("namespace empty", func(t *testing.T) { + result, err := CachePath("/foo/bar", "123hjfju567695", "", false) + + assert.Equal(t, "", result) + assert.EqualError(t, err, "cache: namespace for hash '123hjfju567695' is empty") + }) + t.Run("1234567890abcdef", func(t *testing.T) { result, err := CachePath("/foo/bar", "1234567890abcdef", "baz", false) diff --git a/pkg/fs/case_test.go b/pkg/fs/case_test.go index 51b7ec94b..8fe1e3042 100644 --- a/pkg/fs/case_test.go +++ b/pkg/fs/case_test.go @@ -1,6 +1,7 @@ package fs import ( + "github.com/stretchr/testify/assert" "os" "testing" ) @@ -14,3 +15,11 @@ func TestCaseInsensitive(t *testing.T) { } }) } + +func TestIgnoreCase(t *testing.T) { + assert.False(t, ignoreCase) + IgnoreCase() + assert.True(t, ignoreCase) + ignoreCase = false + assert.False(t, ignoreCase) +} diff --git a/pkg/txt/capitalization_test.go b/pkg/txt/capitalization_test.go index 29a9a1db6..de75577aa 100644 --- a/pkg/txt/capitalization_test.go +++ b/pkg/txt/capitalization_test.go @@ -85,4 +85,7 @@ func TestTitle(t *testing.T) { t.Run("NewYears", func(t *testing.T) { assert.Equal(t, "Boston New Year's", Title("boston new year's")) }) + t.Run("empty", func(t *testing.T) { + assert.Empty(t, Title("")) + }) } diff --git a/pkg/txt/contains_test.go b/pkg/txt/contains_test.go index 4ac3d18bd..9e5c57028 100644 --- a/pkg/txt/contains_test.go +++ b/pkg/txt/contains_test.go @@ -37,6 +37,12 @@ func TestContainsSymbols(t *testing.T) { t.Run("réseau", func(t *testing.T) { assert.False(t, ContainsSymbols("réseau")) }) + t.Run("empty", func(t *testing.T) { + assert.False(t, ContainsSymbols("")) + }) + t.Run("...", func(t *testing.T) { + assert.True(t, ContainsSymbols("😉")) + }) } func TestContainsLetters(t *testing.T) { @@ -61,6 +67,9 @@ func TestContainsLetters(t *testing.T) { t.Run("réseau", func(t *testing.T) { assert.True(t, ContainsLetters("réseau")) }) + t.Run("Empty", func(t *testing.T) { + assert.Equal(t, false, ContainsLetters("")) + }) } func TestContainsASCIILetters(t *testing.T) { diff --git a/pkg/txt/is_test.go b/pkg/txt/is_test.go index 3578b345a..f4397c45d 100644 --- a/pkg/txt/is_test.go +++ b/pkg/txt/is_test.go @@ -39,6 +39,9 @@ func TestIs(t *testing.T) { assert.True(t, Is(unicode.L, "réseau")) assert.True(t, Is(unicode.Letter, "réseau")) }) + t.Run("empty", func(t *testing.T) { + assert.False(t, Is(unicode.Latin, "")) + }) } func TestIsASCII(t *testing.T) { @@ -84,4 +87,7 @@ func TestIsLatin(t *testing.T) { t.Run("réseau", func(t *testing.T) { assert.True(t, IsLatin("réseau")) }) + t.Run("empty", func(t *testing.T) { + assert.False(t, IsLatin("")) + }) } diff --git a/pkg/txt/words_test.go b/pkg/txt/words_test.go index 5939b55bd..0ced49666 100644 --- a/pkg/txt/words_test.go +++ b/pkg/txt/words_test.go @@ -43,6 +43,10 @@ func TestWords(t *testing.T) { result := Words("Île de la Réunion") assert.Equal(t, []string{"Île", "Réunion"}, result) }) + t.Run("empty", func(t *testing.T) { + result := Words("") + assert.Empty(t, result) + }) } func TestReplaceSpaces(t *testing.T) { @@ -73,6 +77,10 @@ func TestFilenameWords(t *testing.T) { result := FilenameWords("Île de la Réunion") assert.Equal(t, []string{"Île", "Réunion"}, result) }) + t.Run("empty", func(t *testing.T) { + result := FilenameWords("") + assert.Empty(t, result) + }) } func TestFilenameKeywords(t *testing.T) { @@ -100,6 +108,10 @@ func TestFilenameKeywords(t *testing.T) { result := FilenameKeywords("Île de la Réunion") assert.Equal(t, []string{"île", "réunion"}, result) }) + t.Run("empty", func(t *testing.T) { + result := FilenameKeywords("") + assert.Empty(t, result) + }) } func TestKeywords(t *testing.T) { @@ -139,6 +151,10 @@ func TestKeywords(t *testing.T) { result := Keywords("Île de la Réunion") assert.Equal(t, []string{"île", "réunion"}, result) }) + t.Run("empty", func(t *testing.T) { + result := Keywords("") + assert.Empty(t, result) + }) } func TestUniqueWords(t *testing.T) {