parse arg test

This commit is contained in:
Erik Winter 2024-11-08 08:02:43 +01:00
parent 8255c4b18b
commit aeb8e3d741
1 changed files with 30 additions and 0 deletions

View File

@ -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)