@@ -40,11 +40,6 @@ func TestNormalizeArgs(t *testing.T) {
4040 input : []string {"-xzv" },
4141 expected : []string {"-x" , "-z" , "-v" },
4242 },
43- {
44- name : "terminator excludes all after" ,
45- input : []string {"--foo" , "bar" , "--" , "--ignored" , "positional" },
46- expected : []string {"--foo=bar" },
47- },
4843 {
4944 name : "positional args are skipped" ,
5045 input : []string {"--foo" , "bar" , "main.go" , "--baz" , "qux" },
@@ -490,3 +485,88 @@ func TestArgEntry_String(t *testing.T) {
490485 })
491486 }
492487}
488+
489+ func TestProcessAllArgs (t * testing.T ) {
490+ t .Parallel ()
491+
492+ tests := []struct {
493+ name string
494+ input []string
495+ expected []string
496+ }{
497+ {
498+ name : "empty input" ,
499+ input : []string {},
500+ expected : []string {},
501+ },
502+ {
503+ name : "only positional args" ,
504+ input : []string {"pos1" , "pos2" , "pos3" },
505+ expected : []string {"pos1" , "pos2" , "pos3" },
506+ },
507+ {
508+ name : "only flags with embedded values" ,
509+ input : []string {"--flag=value" , "--other=val" },
510+ expected : []string {"--flag=value" , "--other=val" },
511+ },
512+ {
513+ name : "only boolean flags" ,
514+ input : []string {"--verbose" , "--debug" },
515+ expected : []string {"--verbose" , "--debug" },
516+ },
517+ {
518+ name : "flags with separate values (regression test)" ,
519+ input : []string {"--config" , "dev.toml" , "--output" , "result.txt" },
520+ expected : []string {"--config=dev.toml" , "--output=result.txt" },
521+ },
522+ {
523+ name : "mixed flags and positional args maintaining order" ,
524+ input : []string {"pos1" , "--flag=value" , "pos2" , "--verbose" , "pos3" },
525+ expected : []string {"pos1" , "--flag=value" , "pos2" , "--verbose=pos3" },
526+ },
527+ {
528+ name : "flag with separate value followed by positional" ,
529+ input : []string {"--config" , "dev.toml" , "positional" },
530+ expected : []string {"--config=dev.toml" , "positional" },
531+ },
532+ {
533+ name : "positional followed by flag with separate value" ,
534+ input : []string {"positional" , "--config" , "dev.toml" },
535+ expected : []string {"positional" , "--config=dev.toml" },
536+ },
537+ {
538+ name : "complex mix with various flag formats" ,
539+ input : []string {"pos1" , "--flag=embedded" , "--other" , "separate" , "--bool" , "pos2" },
540+ expected : []string {"pos1" , "--flag=embedded" , "--other=separate" , "--bool=pos2" },
541+ },
542+ {
543+ name : "short flags with separate values" ,
544+ input : []string {"-f" , "value" , "-x" , "other" },
545+ expected : []string {"-f=value" , "-x=other" },
546+ },
547+ {
548+ name : "combined short flags" ,
549+ input : []string {"-xyz" , "pos1" },
550+ expected : []string {"-x" , "-y" , "-z" , "pos1" },
551+ },
552+ {
553+ name : "flag followed by another flag (no value consumption)" ,
554+ input : []string {"--verbose" , "--debug" , "pos1" },
555+ expected : []string {"--verbose" , "--debug=pos1" },
556+ },
557+ {
558+ name : "multiple consecutive flags with separate values" ,
559+ input : []string {"--first" , "val1" , "--second" , "val2" , "--third" , "val3" },
560+ expected : []string {"--first=val1" , "--second=val2" , "--third=val3" },
561+ },
562+ }
563+
564+ for _ , tc := range tests {
565+ t .Run (tc .name , func (t * testing.T ) {
566+ t .Parallel ()
567+
568+ actual := ProcessAllArgs (tc .input )
569+ require .Equal (t , tc .expected , actual , "ProcessAllArgs should preserve order and normalize flags correctly" )
570+ })
571+ }
572+ }
0 commit comments