From aeb8e3d7410e6eace0e009bd5012fd1600b9ab03 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Fri, 8 Nov 2024 08:02:43 +0100 Subject: [PATCH] parse arg test --- plan/command/command_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/plan/command/command_test.go b/plan/command/command_test.go index 44e2c09..14b440d 100644 --- a/plan/command/command_test.go +++ b/plan/command/command_test.go @@ -69,6 +69,36 @@ func TestParseArgs(t *testing.T) { Flags: map[string]string{}, }, }, + { + name: "just main", + args: []string{"one", "two three", "four"}, + expAS: &command.ArgSet{ + Main: "one two three four", + Flags: map[string]string{}, + }, + }, + { + name: "with flags", + args: []string{"-flag1", "value1", "one", "two", "-flag2", "value2", "-flag3", "value3"}, + expAS: &command.ArgSet{ + Main: "one two", + Flags: map[string]string{ + "flag1": "value1", + "flag2": "value2", + "flag3": "value3", + }, + }, + }, + { + name: "flag without value", + args: []string{"one", "two", "-flag1"}, + expErr: true, + }, + { + name: "split main", + args: []string{"one", "-flag1", "value1", "two"}, + expErr: true, + }, } { t.Run(tc.name, func(t *testing.T) { actAS, actErr := command.ParseArgs(tc.args)