1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

parse_test: test command with optional arg

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
Christian Couder
2015-05-20 22:47:14 +02:00
parent 8d6bfec890
commit be3b7e13e3

View File

@ -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!"})