Skip to content

Commit

Permalink
Merge pull request #1673 from luhring/strip-comments-tests
Browse files Browse the repository at this point in the history
test(compile): basic tests for stripComments
  • Loading branch information
luhring authored Dec 1, 2024
2 parents 52689d3 + 66eb0e9 commit 6d88b8b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/build/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,32 @@ func TestCompileTest(t *testing.T) {
t.Errorf("subpackage test packages: want %v, got %v", want, got)
}
}

func Test_stripComments(t *testing.T) {
tests := []struct {
in, want string
}{
{"", ""},
{"# foo\n", ""},
{"\n", ""},
{"#!/bin/bash\n", "#!/bin/bash\n"},
{"#!/bin/bash\n# foo\n", "#!/bin/bash\n"},
{"#!/bin/bash\nfoo\n", "#!/bin/bash\nfoo\n"},
{"#!/bin/bash\nfoo\n# bar\n", "#!/bin/bash\nfoo\n"},
{"#!/bin/bash\nfoo\nbar\n", "#!/bin/bash\nfoo\nbar\n"},
{"#!/bin/bash\nfoo\n# bar\nbaz\n", "#!/bin/bash\nfoo\nbaz\n"},
}

for _, test := range tests {
t.Run(test.in, func(t *testing.T) {
got, err := stripComments(test.in)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if got != test.want {
t.Errorf("stripComments(%q): want %q, got %q", test.in, test.want, got)
}
})
}
}

0 comments on commit 6d88b8b

Please sign in to comment.