예제 #1
0
func TestIntArray(t *testing.T) {
	p := op.NewParser("", 0)
	a := p.IntArray("-a")
	assertEqual(t, *a, []int{}, "IntArray did not default to empty array")
	b := p.IntArray("-b", op.Nargs(3), op.Store)
	assertEqual(t, *b, []int{}, "IntArray with Nargs did not default to empty array")
	args, err := p.ParseArgs([]string{"-a", "1", "-a", "2", "-b", "5", "6", "7"})
	checkArgs(t, args, err)
	assertEqual(t, *a, []int{1, 2}, "IntArray did not append successfully")
	assertEqual(t, *b, []int{5, 6, 7}, "IntArray did not parse Nargs(3) successfully")
}
예제 #2
0
func TestStringArray(t *testing.T) {
	p := op.NewParser("", 0)
	a := p.StringArray("-a")
	assertEqual(t, *a, []string{}, "StringArray did not default to empty array")
	b := p.StringArray("-b", op.Nargs(3), op.Store)
	assertEqual(t, *b, []string{}, "StringArray with Nargs did not default to empty array")
	c := p.StringArray("-c", op.Default([]string{"first"}))
	assertEqual(t, *c, []string{"first"}, "StringArray with default did not get correct default")
	args, err := p.ParseArgs([]string{"-a", "one", "-a", "two", "-b", "foo", "bar", "baz", "-c", "second"})
	checkArgs(t, args, err)
	assertEqual(t, *a, []string{"one", "two"}, "StringArray did not append successfully")
	assertEqual(t, *b, []string{"foo", "bar", "baz"}, "StringArray did not parse Nargs(3) successfully")
	assertEqual(t, *c, []string{"first", "second"}, "StringArray did not append to default successfully")
}