public void StripCppComments() { const string str_in = "123// comment \n" + "456/* block */789 \n" + "// many \n" + "// lines \n" + "// \"string\" \n" + "/* \"string\" */ \n" + "\"string \\\" /*a*/ //b\" \n" + "/not a comment\n" + "/*\n" + " more lines\n" + "*/\n" + "/*back to*//*back*/ comment\n"; const string str_out = "123\n" + "456789 \n" + "\n" + "\n" + "\n" + " \n" + "\"string \\\" /*a*/ //b\" \n" + "/not a comment\n" + "\n" + " comment\n"; var src = new StringSrc(str_in); var strip = new StripComments(src); for (int i = 0; i != str_out.Length; ++i, strip.Next()) { if (str_out[i] == strip.Peek) { continue; } Assert.Equal(str_out[i], strip.Peek); } Assert.Equal('\0', strip.Peek); }
public void StripAsmComments() { const string str_in = "; asm comments start with a ; character\r\n" + "mov 43 2\r\n" + "ldr $a 2 ; imaginary asm"; const string str_out = "\r\n" + "mov 43 2\r\n" + "ldr $a 2 "; var src = new StringSrc(str_in); var strip = new StripComments(src, comment_patterns: new InComment.Patterns(";", "\r\n", "", "")); for (int i = 0; i != str_out.Length; ++i, strip.Next()) { if (str_out[i] == strip.Peek) { continue; } Assert.Equal(str_out[i], strip.Peek); } Assert.Equal('\0', strip.Peek); }