blob: 8bf9717f0f4af1551a7729c4425a3f178fbc0ee0 [file] [log] [blame]
Shinichiro Hamaji246cd232015-05-27 17:08:23 +09001package main
2
3import "testing"
4
5func TestStripShellComment(t *testing.T) {
6 for _, tc := range []struct {
7 in string
8 want string
9 }{
10 {
11 in: `foo`,
12 want: `foo`,
13 },
14 {
15 in: `foo # bar`,
16 want: `foo `,
17 },
18 {
19 in: `foo '# bar'`,
20 want: `foo '# bar'`,
21 },
22 {
23 in: `foo '\'# bar'`,
24 want: `foo '\'`,
25 },
26 {
27 in: `foo "# bar"`,
28 want: `foo "# bar"`,
29 },
30 {
31 in: `foo "\"# bar"`,
32 want: `foo "\"# bar"`,
33 },
34 {
35 in: `foo "\\"# bar"`,
36 want: `foo "\\"`,
37 },
38 {
39 in: "foo `# bar`",
40 want: "foo `# bar`",
41 },
42 {
43 in: "foo `\\`# bar`",
44 want: "foo `\\`# bar`",
45 },
46 {
47 in: "foo `\\\\`# bar`",
48 want: "foo `\\\\`",
49 },
50 } {
51 got := stripShellComment(tc.in)
52 if got != tc.want {
53 t.Errorf(`stripShellComment(%q)=%q, want %q`, tc.in, got, tc.want)
54 }
55 }
56}