From ae2941c938817573acf89796a2a0ee95aa46114c Mon Sep 17 00:00:00 2001 From: odino Date: Wed, 18 Sep 2019 18:40:47 +0400 Subject: [PATCH] Added a bunch more tests --- util/util_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/util/util_test.go b/util/util_test.go index 2f62bb53..8cf83df0 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -26,3 +26,53 @@ func TestUnaliasPath(t *testing.T) { } } } + +func TestUniqueStrings(t *testing.T) { + tests := []struct { + strings []string + len int + }{ + {[]string{"a", "b", "c"}, 3}, + {[]string{"a", "a", "a"}, 1}, + } + + for _, tt := range tests { + if len(UniqueStrings(tt.strings)) != tt.len { + t.Fatalf("expected %d, got %d", tt.len, len(UniqueStrings(tt.strings))) + } + } +} + +func TestContains(t *testing.T) { + tests := []struct { + strings []string + match string + expected bool + }{ + {[]string{"a", "b", "c"}, "a", true}, + {[]string{"a", "a", "a"}, "d", false}, + } + + for _, tt := range tests { + if tt.expected != Contains(tt.strings, tt.match) { + t.Fatalf("expected %v", tt.expected) + } + } +} + +func TestIsNumber(t *testing.T) { + tests := []struct { + number string + expected bool + }{ + {"12", true}, + {"12a", false}, + {"12.2", true}, + } + + for _, tt := range tests { + if tt.expected != IsNumber(tt.number) { + t.Fatalf("expected %v (%s)", tt.expected, tt.number) + } + } +}