From 66757999fb5aa554d1277a21ba59a5f2e6ca0271 Mon Sep 17 00:00:00 2001 From: GrĂ©goire DuchĂȘne Date: Sat, 3 Dec 2022 10:37:56 +0000 Subject: Have FlagTSlice{,Var} take an optional separator This separator, when passed, allows for multiple values to be passed at a time. --- flag_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'flag_test.go') diff --git a/flag_test.go b/flag_test.go index 1492e7a..ccbfadb 100644 --- a/flag_test.go +++ b/flag_test.go @@ -36,10 +36,10 @@ func TestFlagTSlice(s *testing.T) { t := core.T{T: s} fs := flag.NewFlagSet("", flag.PanicOnError) - fl := core.FlagTSlice(fs, "test", []int{42}, "", strconv.Atoi) + fl := core.FlagTSlice(fs, "test", []int{42}, "", strconv.Atoi, ",") t.AssertEqual([]int{42}, *fl) - t.AssertErrorIs(nil, fs.Parse([]string{"-test=1", "-test=2", "-test=42"})) - t.AssertEqual([]int{1, 2, 42}, *fl) + t.AssertErrorIs(nil, fs.Parse([]string{"-test=1", "-test=2", "-test=42,84"})) + t.AssertEqual([]int{1, 2, 42, 84}, *fl) } func TestFlagTSliceVar(s *testing.T) { @@ -47,8 +47,8 @@ func TestFlagTSliceVar(s *testing.T) { fs := flag.NewFlagSet("", flag.PanicOnError) var fl []int - core.FlagTSliceVar(fs, &fl, "test", []int{42}, "", strconv.Atoi) + core.FlagTSliceVar(fs, &fl, "test", []int{42}, "", strconv.Atoi, ",") t.AssertEqual([]int{42}, fl) - t.AssertErrorIs(nil, fs.Parse([]string{"-test=1", "-test=2", "-test=42"})) - t.AssertEqual([]int{1, 2, 42}, fl) + t.AssertErrorIs(nil, fs.Parse([]string{"-test=1", "-test=2", "-test=42,84"})) + t.AssertEqual([]int{1, 2, 42, 84}, fl) } -- cgit v1.2.3-70-g09d2