diff options
| author | Eric Paris <[email protected]> | 2015-06-01 00:49:55 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-06-22 15:21:40 -0400 |
| commit | 6dc14aaf8d96f367a07b4ce939aad8506532c2ee (patch) | |
| tree | 2b3cd48914e7eb4d744a33951f2dbb62f0f693f9 /int_slice_test.go | |
| parent | 29224ee030bd4e687e95d1d8df55303269b49337 (diff) | |
Much like stringSlice, add intSlice flag type
Diffstat (limited to 'int_slice_test.go')
| -rw-r--r-- | int_slice_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/int_slice_test.go b/int_slice_test.go new file mode 100644 index 0000000..fed4782 --- /dev/null +++ b/int_slice_test.go @@ -0,0 +1,39 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pflag + +import ( + "fmt" + "strconv" + "strings" + "testing" +) + +func setUpISFlagSet(isp *[]int) *FlagSet { + f := NewFlagSet("test", ContinueOnError) + f.IntSliceVar(isp, "is", []int{}, "Command seperated list!") + return f +} + +func TestIS(t *testing.T) { + var is []int + f := setUpISFlagSet(&is) + + vals := []string{"1", "2", "4", "3"} + arg := fmt.Sprintf("--is=%s", strings.Join(vals, ",")) + err := f.Parse([]string{arg}) + if err != nil { + t.Fatal("expected no error; got", err) + } + for i, v := range is { + d, err := strconv.Atoi(vals[i]) + if err != nil { + t.Fatalf("got error: %v", err) + } + if d != v { + t.Fatalf("expected is[%d] to be %s but got: %d", i, vals[i], v) + } + } +} |
