-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
text: improves ToArgv to handle unfinished quotes
- Loading branch information
Showing
4 changed files
with
64 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package text | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestToArgv(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
give string | ||
want []string | ||
}{ | ||
{ | ||
name: "command without quotes", | ||
give: "_test a b c", | ||
want: []string{"_test", "a", "b", "c"}, | ||
}, | ||
{ | ||
name: "command with quotes", | ||
give: "_test \"my long\" \"command with quotes\"", | ||
want: []string{"_test", "my long", "command with quotes"}, | ||
}, | ||
{ | ||
name: "different type of quotes", | ||
give: "_test “my long“ 'command with quotes'", | ||
want: []string{"_test", "my long", "command with quotes"}, | ||
}, | ||
{ | ||
name: "mixed quotes and no quotes", | ||
give: "_test \"my long\" abc \"command with quotes\"", | ||
want: []string{"_test", "my long", "abc", "command with quotes"}, | ||
}, | ||
{ | ||
name: "unfinished quotes", | ||
give: "_test \"my long\" abc \"command that's not finished", | ||
want: []string{"_test", "my long", "abc", "command that's not finished"}, | ||
}, | ||
{ | ||
name: "escape character at the end", | ||
give: "_test \"my long\" abc \"command with quotes\"\\", | ||
want: []string{"_test", "my long", "abc", "command with quotes"}, | ||
}, | ||
{ | ||
name: "quote at the beginning", | ||
give: "\"_test\" \"my long\" abc \"command with quotes\"", | ||
want: []string{"_test", "my long", "abc", "command with quotes"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := ToArgv(tt.give) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |