def testStringThenComment(self): code = r'"" /* "abc */' comments = c_parser.extract_comments(code) expected = [ common.Comment(' "abc ', 1, multiline=True), ] self.assertEqual(comments, expected)
def testMultipleMultilineComments(self): code = '/* abc */ /* 123 */' comments = c_parser.extract_comments(code) expected = [ common.Comment(' abc ', 1, multiline=True), common.Comment(' 123 ', 1, multiline=True), ] self.assertEqual(comments, expected)
def testCommentedMultilineComment(self): code = '''// What if i start a /* here int main(){return 0;} // and ended it here */''' comments = c_parser.extract_comments(code) expected = [ common.Comment(" What if i start a /* here", 1, False), common.Comment(" and ended it here */", 3, False) ] self.assertEqual(comments, expected)
def testMultilineCommentedComment(self): code = '''/*// here int main(){return 0;} */// and ended it here */''' comments = c_parser.extract_comments(code) expected = [ common.Comment('// here\n int main(){return 0;}\n ', 1, True), common.Comment(' and ended it here */', 3, False) ] self.assertEqual(comments, expected)
def ExtractComments(self, text, mock_open): mock_file = StringIO(text) mock_open.return_value = mock_file return c_parser.extract_comments('filename')
def ExtractComments(self, text, mock_open): mock_file = StringIO(text) mock_open.return_value = mock_file return c_parser.extract_comments('filename')
def testSimpleMain(self): code = "// this is a comment\nint main() {\nreturn 0;\n}\n" comments = c_parser.extract_comments(code) expected = [common.Comment(code[2:20], 1, multiline=False)] self.assertEqual(comments, expected)
def testTwoStringsFollowedByComment(self): code = r'"""" // foo' comments = c_parser.extract_comments(code) self.assertEqual(comments, [common.Comment(' foo', 1)])
def testStringEscapedBackslashCharacter(self): code = r'"\\"' comments = c_parser.extract_comments(code) self.assertEqual(comments, [])
def testMultiLineCommentInStringLiteral(self): code = 'char* msg = "/* This is not a\\nmultiline comment */"' comments = c_parser.extract_comments(code) self.assertEqual(comments, [])
def testMultiLineCommentWithStars(self): code = "/***************/" comments = c_parser.extract_comments(code) expected = [common.Comment(code[2:-2], 1, multiline=True)] self.assertEqual(comments, expected)
def testMultiLineComment(self): code = '/* multiline\ncomment */' comments = c_parser.extract_comments(code) expected = [common.Comment(code[2:-2], 1, multiline=True)] self.assertEqual(comments, expected)
def testSingleLineCommentInStringLiteral(self): code = 'char* msg = "// this is not a comment"' comments = c_parser.extract_comments(code) self.assertEqual(comments, [])
def testSingleLineComment(self): code = '// single line comment' comments = c_parser.extract_comments(code) expected = [common.Comment(code[2:], 1, multiline=False)] self.assertEqual(comments, expected)
def testCommentStartInsideEscapedQuotesInStringLiteral(self): code = r'" \" /* \" "' comments = c_parser.extract_comments(code) self.assertEqual(comments, [])