From be3b7e13e3a2edbb730ffef2240f50f754073b5a Mon Sep 17 00:00:00 2001 From: Christian Couder <chriscool@tuxfamily.org> Date: Wed, 20 May 2015 22:47:14 +0200 Subject: [PATCH] parse_test: test command with optional arg License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org> --- commands/cli/parse_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commands/cli/parse_test.go b/commands/cli/parse_test.go index fe2c863c3..2c42ddcc4 100644 --- a/commands/cli/parse_test.go +++ b/commands/cli/parse_test.go @@ -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!"}) -- GitLab