Ejemplo n.º 1
0
 def testSimpleSingleLineComment(self):
     code = """<?php
 // this is a comment
 echo "Hello World";"""
     comments = php_parser.extract_comments(code)
     expected = [common.Comment(" this is a comment", 2, multiline=False)]
     self.assertEqual(comments, expected)
Ejemplo n.º 2
0
 def testStringThenComment(self):
     code = '''<?php
 echo "" /* "abc */;'''
     comments = php_parser.extract_comments(code)
     expected = [
         common.Comment(' "abc ', 2, multiline=True),
     ]
     self.assertEqual(comments, expected)
Ejemplo n.º 3
0
 def testCommentsOutsidePhpTag(self):
     code = '''<?php echo "Hi";
 ?>
 // This is no comment <?php
 // But this is'''
     comments = php_parser.extract_comments(code)
     expected = [common.Comment(' But this is', 4, multiline=False)]
     self.assertEqual(comments, expected)
Ejemplo n.º 4
0
 def testMultipleMultilineComments(self):
     code = '''<?php
 /* abc */ /* 123 */'''
     comments = php_parser.extract_comments(code)
     expected = [
         common.Comment(' abc ', 2, multiline=True),
         common.Comment(' 123 ', 2, multiline=True),
     ]
     self.assertEqual(comments, expected)
Ejemplo n.º 5
0
 def testHereDocString(self):
     code = '''<?php echo <<<Aä_0
 // Multi "
 # Line
 ?>
 <?php
 /* String */"\nAä_0;'''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [])
Ejemplo n.º 6
0
 def testMultilineString(self):
     code = '''<?php echo "Hi
 // Multi
 # Line
 ?>
 <?php
 /* String */
 ";'''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [])
Ejemplo n.º 7
0
 def testCommentedPhpTag(self):
     code = '''<?php
 # ?>
 /* Wouldn't be a commend if commented php end tag was misinterpreted */'''
     comments = php_parser.extract_comments(code)
     expected = [
         common.Comment(' ?>', 2, multiline=False),
         common.Comment(
             " Wouldn't be a commend if commented php end tag was misinterpreted ",
             3,
             multiline=True)
     ]
     self.assertEqual(comments, expected)
Ejemplo n.º 8
0
 def testFakeHereDocString(self):
     code = '''<?php echo "<<<Aä_0
 // Multi ";
 # Line
 ?>
 \nAä_0;\n
 <?php
 /* String */"'''
     comments = php_parser.extract_comments(code)
     expect = [
         common.Comment(" Line", 3, False),
         common.Comment(" String ", 9, True)
     ]
     self.assertEqual(comments, expect)
Ejemplo n.º 9
0
 def testOtherCommentedComment(self):
     code = '''<?php
 #// double comment'''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [common.Comment('// double comment', 2)])
Ejemplo n.º 10
0
 def testStringEscapedBackslashCharacter(self):
     code = r'''<?php
 echo "\\"; # This wouldn't be a comment, if the second " is misinterpreted as escaped
 '''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [])
Ejemplo n.º 11
0
 def testMultiLineCommentInStringLiteral(self):
     code = '''<?php
 echo "/* This is not a\\nmultiline comment */";'''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [])
Ejemplo n.º 12
0
 def testMultiLineCommentWithStars(self):
     code = """<?php
 /***************/"""
     comments = php_parser.extract_comments(code)
     expected = [common.Comment("*************", 2, multiline=True)]
     self.assertEqual(comments, expected)
Ejemplo n.º 13
0
 def testMultiLineComment(self):
     code = '''<?php
 /* multiline\ncomment */'''
     comments = php_parser.extract_comments(code)
     expected = [common.Comment(' multiline\ncomment ', 2, multiline=True)]
     self.assertEqual(comments, expected)
Ejemplo n.º 14
0
 def testSingleLineCommentInStringLiteral(self):
     code = '''<?php
 echo "// this is not a comment";'''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [])
Ejemplo n.º 15
0
 def testNoPhpTag(self):
     code = '''#// double comment'''
     comments = php_parser.extract_comments(code)
     self.assertEqual(comments, [])