-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shell: convert the Each method into a range function
- Move (most of) the tests into a separate test package. - Update the examples.
- Loading branch information
1 parent
6a3c5af
commit 80cfc50
Showing
3 changed files
with
67 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2015, Michael J. Fromberger | ||
|
||
package shell | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestQuote(t *testing.T) { | ||
type testCase struct{ in, want string } | ||
tests := []testCase{ | ||
{"", "''"}, // empty is special | ||
{"abc", "abc"}, // nothing to quote | ||
{"--flag", "--flag"}, // " | ||
{"'abc", `\'abc`}, // single quote only | ||
{"abc'", `abc\'`}, // " | ||
{`shan't`, `shan\'t`}, // " | ||
{"--flag=value", `'--flag=value'`}, | ||
{"a b\tc", "'a b\tc'"}, | ||
{`a"b"c`, `'a"b"c'`}, | ||
{`'''`, `\'\'\'`}, | ||
{`\`, `'\'`}, | ||
{`'a=b`, `\''a=b'`}, // quotes and other stuff | ||
{`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 { | ||
t.Errorf("Quote %q: got %q, want %q", test.in, got, test.want) | ||
} | ||
} | ||
} |
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