Add unit test cases for quoted characters.
Commit d1f7d07f fixed a bug where one of the special characters requiring
quotation (by the standard) was not included in the quotation list. Add a test
to verify that all those characters get properly quoted. This would not fix the
absence of another one, but at least ensures we get coverage when more are
added.
diff --git a/shell_test.go b/shell_test.go
index 7ca6977..c5564a3 100644
--- a/shell_test.go
+++ b/shell_test.go
@@ -11,9 +11,8 @@
)
func TestQuote(t *testing.T) {
- tests := []struct {
- in, want string
- }{
+ type testCase struct{ in, want string }
+ tests := []testCase{
{"", "''"}, // empty is special
{"abc", "abc"}, // nothing to quote
{"--flag", "--flag"}, // "
@@ -29,6 +28,14 @@
{`a='b`, `'a='\''b'`}, // "
{`a=b'`, `'a=b'\'`}, // "
}
+ // Verify that all the designated special characters get quoted.
+ for _, c := range shouldQuote + mustQuote {
+ tests = append(tests, testCase{
+ in: string(c),
+ want: fmt.Sprintf(`'%c'`, c),
+ })
+ }
+
for _, test := range tests {
got := Quote(test.in)
if got != test.want {