mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-13 00:12:43 +00:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
|
// 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)
|
||
|
}
|
||
|
}
|
||
|
getIS, err := f.GetIntSlice("is")
|
||
|
for i, v := range getIS {
|
||
|
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 from GetIntSlice", i, vals[i], v)
|
||
|
}
|
||
|
}
|
||
|
}
|