From 1ceb032c43c28e6511309bcd3e3e40e3026f5294 Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Mon, 1 Aug 2016 19:31:54 -0700 Subject: Fix string_slice with empty value Currently, if you don't set any value for a StringSliceVar, it will end-up failing with an EOF error. It fails because the CSV parser for the value can't read anything. Special case when the string is empty to return an empty list. --- string_slice_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'string_slice_test.go') diff --git a/string_slice_test.go b/string_slice_test.go index c7fdc70..ed7cbfc 100644 --- a/string_slice_test.go +++ b/string_slice_test.go @@ -39,6 +39,23 @@ func TestEmptySS(t *testing.T) { } } +func TestEmptySSValue(t *testing.T) { + var ss []string + f := setUpSSFlagSet(&ss) + err := f.Parse([]string{"--ss="}) + if err != nil { + t.Fatal("expected no error; got", err) + } + + getSS, err := f.GetStringSlice("ss") + if err != nil { + t.Fatal("got an error from GetStringSlice():", err) + } + if len(getSS) != 0 { + t.Fatalf("got ss %v with len=%d but expected length=0", getSS, len(getSS)) + } +} + func TestSS(t *testing.T) { var ss []string f := setUpSSFlagSet(&ss) -- cgit v1.2.3