Commit be3b7e13 authored by Christian Couder's avatar Christian Couder

parse_test: test command with optional arg

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent 8d6bfec8
......@@ -144,6 +144,12 @@ func TestArgumentParsing(t *testing.T) {
commands.StringArg("b", false, true, "another arg"),
},
},
"optionalsecond": {
Arguments: []commands.Argument{
commands.StringArg("a", true, false, "some arg"),
commands.StringArg("b", false, false, "another arg"),
},
},
"reversedoptional": {
Arguments: []commands.Argument{
commands.StringArg("a", false, false, "some arg"),
......@@ -213,6 +219,12 @@ func TestArgumentParsing(t *testing.T) {
test([]string{"optional", "value!"}, nil, []string{"value!"})
test([]string{"optional"}, nil, []string{})
test([]string{"optional", "value1", "value2"}, nil, []string{"value1", "value2"})
test([]string{"optionalsecond", "value!"}, nil, []string{"value!"})
test([]string{"optionalsecond", "value1", "value2"}, nil, []string{"value1", "value2"})
testFail([]string{"optionalsecond"}, "didn't provide any args, 1 required")
testFail([]string{"optionalsecond", "value1", "value2", "value3"}, "provided too many args, takes 2 maximum")
test([]string{"reversedoptional", "value1", "value2"}, nil, []string{"value1", "value2"})
test([]string{"reversedoptional", "value!"}, nil, []string{"value!"})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment