pkg: stringutils: Add more tests to strslice

Signed-off-by: Antonio Murdaca <runcom@linux.com>
This commit is contained in:
Antonio Murdaca 2015-09-01 20:12:05 +02:00
parent 82415adc81
commit cac8f4f0d0
1 changed files with 30 additions and 0 deletions

View File

@ -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)
}
}
}