From 9c1e8f8537a437da36d3a2c8402eb68a44f6dc21 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Tue, 13 Oct 2015 14:47:57 -0400 Subject: Use encoding/csv to parse string slices There was no way to escape or use a , in a string slice so use the encoding/csv library, rather than string.split() and let golang take care of the encoding issues. --- string_slice_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'string_slice_test.go') diff --git a/string_slice_test.go b/string_slice_test.go index 97602de..c7fdc70 100644 --- a/string_slice_test.go +++ b/string_slice_test.go @@ -139,3 +139,23 @@ func TestSSCalledTwice(t *testing.T) { } } } + +func TestSSWithComma(t *testing.T) { + var ss []string + f := setUpSSFlagSet(&ss) + + in := []string{`"one,two"`, `"three"`} + expected := []string{"one,two", "three"} + argfmt := "--ss=%s" + arg1 := fmt.Sprintf(argfmt, in[0]) + arg2 := fmt.Sprintf(argfmt, in[1]) + err := f.Parse([]string{arg1, arg2}) + if err != nil { + t.Fatal("expected no error; got", err) + } + for i, v := range ss { + if expected[i] != v { + t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v) + } + } +} -- cgit v1.2.3