From d1839a82b3de836d5be572449818bfd34d7aae67 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 1 Sep 2015 20:12:05 +0200 Subject: [PATCH] pkg: stringutils: Add more tests to strslice Signed-off-by: Antonio Murdaca --- stringutils/strslice_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/stringutils/strslice_test.go b/stringutils/strslice_test.go index d0e6b1b..a587784 100644 --- a/stringutils/strslice_test.go +++ b/stringutils/strslice_test.go @@ -2,6 +2,7 @@ package stringutils import ( "encoding/json" + "reflect" "testing" ) @@ -103,3 +104,32 @@ func TestStrSliceToString(t *testing.T) { } } } + +func TestStrSliceLen(t *testing.T) { + var emptyStrSlice *StrSlice + slices := map[*StrSlice]int{ + NewStrSlice(""): 1, + NewStrSlice("one"): 1, + NewStrSlice("one", "two"): 2, + emptyStrSlice: 0, + } + for s, expected := range slices { + if s.Len() != expected { + t.Fatalf("Expected %d, got %d", s.Len(), expected) + } + } +} + +func TestStrSliceSlice(t *testing.T) { + var emptyStrSlice *StrSlice + slices := map[*StrSlice][]string{ + NewStrSlice("one"): {"one"}, + NewStrSlice("one", "two"): {"one", "two"}, + emptyStrSlice: nil, + } + for s, expected := range slices { + if !reflect.DeepEqual(s.Slice(), expected) { + t.Fatalf("Expected %v, got %v", s.Slice(), expected) + } + } +}