@@ -20,16 +20,25 @@ Hello, world!
2020\end{document}` , removeComments (input ))
2121}
2222
23- func TestRemoveCommentsPreservesEscapedPercent (t * testing.T ) {
24- const input = `accuracy improved by 12\% over baseline % TODO: recheck`
25- assert .Equal (t , `accuracy improved by 12\% over baseline` , removeComments (input ))
26- }
27-
28- func TestRemoveCommentsDoubleBackslashBeforePercent (t * testing.T ) {
29- const input = `line one \\% this is a real comment after a line break
30- next line`
31- assert .Equal (t , `line one \\
32- next line` , removeComments (input ))
23+ func TestRemoveCommentsBackslashRunsBeforePercent (t * testing.T ) {
24+ cases := []struct {
25+ name string
26+ input string
27+ want string
28+ }{
29+ {"1 backslash (odd) preserves %" , `a\% keep` , `a\% keep` },
30+ {"2 backslashes (even) strips comment" , `a\\% drop` , `a\\` },
31+ {"3 backslashes (odd) preserves %" , `a\\\% keep` , `a\\\% keep` },
32+ {"4 backslashes (even) strips comment" , `a\\\\% drop` , `a\\\\` },
33+ {"5 backslashes (odd) preserves %" , `a\\\\\% keep` , `a\\\\\% keep` },
34+ {"3 backslashes at line start preserves %" , `\\\% keep` , `\\\% keep` },
35+ {"4 backslashes at line start strips comment" , `\\\\% drop` , `\\\\` },
36+ }
37+ for _ , tc := range cases {
38+ t .Run (tc .name , func (t * testing.T ) {
39+ assert .Equal (t , tc .want , removeComments (tc .input ))
40+ })
41+ }
3342}
3443
3544func TestLatexpand (t * testing.T ) {
0 commit comments