Strip comments in a shell script
diff --git a/ninja_test.go b/ninja_test.go
new file mode 100644
index 0000000..8bf9717
--- /dev/null
+++ b/ninja_test.go
@@ -0,0 +1,56 @@
+package main
+
+import "testing"
+
+func TestStripShellComment(t *testing.T) {
+ for _, tc := range []struct {
+ in string
+ want string
+ }{
+ {
+ in: `foo`,
+ want: `foo`,
+ },
+ {
+ in: `foo # bar`,
+ want: `foo `,
+ },
+ {
+ in: `foo '# bar'`,
+ want: `foo '# bar'`,
+ },
+ {
+ in: `foo '\'# bar'`,
+ want: `foo '\'`,
+ },
+ {
+ in: `foo "# bar"`,
+ want: `foo "# bar"`,
+ },
+ {
+ in: `foo "\"# bar"`,
+ want: `foo "\"# bar"`,
+ },
+ {
+ in: `foo "\\"# bar"`,
+ want: `foo "\\"`,
+ },
+ {
+ in: "foo `# bar`",
+ want: "foo `# bar`",
+ },
+ {
+ in: "foo `\\`# bar`",
+ want: "foo `\\`# bar`",
+ },
+ {
+ in: "foo `\\\\`# bar`",
+ want: "foo `\\\\`",
+ },
+ } {
+ got := stripShellComment(tc.in)
+ if got != tc.want {
+ t.Errorf(`stripShellComment(%q)=%q, want %q`, tc.in, got, tc.want)
+ }
+ }
+}