Beispiel #1
0
 def testStringThenComment(self):
     code = r'"" /* "abc */'
     comments = c_parser.extract_comments(code)
     expected = [
         common.Comment(' "abc ', 1, multiline=True),
     ]
     self.assertEqual(comments, expected)
Beispiel #2
0
 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)
Beispiel #5
0
 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')
Beispiel #7
0
 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)
Beispiel #8
0
 def testTwoStringsFollowedByComment(self):
     code = r'"""" // foo'
     comments = c_parser.extract_comments(code)
     self.assertEqual(comments, [common.Comment(' foo', 1)])
Beispiel #9
0
 def testStringEscapedBackslashCharacter(self):
     code = r'"\\"'
     comments = c_parser.extract_comments(code)
     self.assertEqual(comments, [])
Beispiel #10
0
 def testMultiLineCommentInStringLiteral(self):
     code = 'char* msg = "/* This is not a\\nmultiline comment */"'
     comments = c_parser.extract_comments(code)
     self.assertEqual(comments, [])
Beispiel #11
0
 def testMultiLineCommentWithStars(self):
     code = "/***************/"
     comments = c_parser.extract_comments(code)
     expected = [common.Comment(code[2:-2], 1, multiline=True)]
     self.assertEqual(comments, expected)
Beispiel #12
0
 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)
Beispiel #13
0
 def testSingleLineCommentInStringLiteral(self):
     code = 'char* msg = "// this is not a comment"'
     comments = c_parser.extract_comments(code)
     self.assertEqual(comments, [])
Beispiel #14
0
 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)
Beispiel #15
0
 def testCommentStartInsideEscapedQuotesInStringLiteral(self):
     code = r'" \" /* \" "'
     comments = c_parser.extract_comments(code)
     self.assertEqual(comments, [])