Commits

John Chandler  committed 33194c9

Added tests for parsing of single include/require statements

  • Participants
  • Parent commits fe57b9d

Comments (0)

Files changed (2)

File qadpid/parser.py

 """
 Parser Code
 """
+import re
+
+INCLUDE_RE = re.compile( '(?P<type>include|require)(?:_once)? "(?P<filename>[^"]+)"' )
 
 class PHPFileParser( object ):
     """ PHP File Parser """
     def parse( self, file_text ):
         """ parse the file_text and return a list of include/require dependencies """
+        match = INCLUDE_RE.search( file_text )
+        if match:
+            return [ (match.group("type"), match.group("filename") ) ]
+        
         return []
     

File tests/test_parser.py

         """ Test for empty file contents """
         self.assertEquals( PHPFileParser().parse(""), [] )
 
+    def test_parse_one_include( self ):
+        """ Test for presence of one include statement """
+        self.assertEquals( PHPFileParser().parse('include "foo.php"'), [ ("include", "foo.php")] )
+
+    def test_parse_one_require( self ):
+        """ Test for presence of one require statement """
+        self.assertEquals( PHPFileParser().parse('require "foo.php"'), [ ("require", "foo.php")] )
+
+    def test_parse_one_include_once( self ):
+        """ Test for presence of one include_once statement """
+        self.assertEquals( PHPFileParser().parse('include_once "foo.php"'), [ ("include", "foo.php")] )
+
+    def test_parse_one_require_once( self ):
+        """ Test for presence of one require_once statement """
+        self.assertEquals( PHPFileParser().parse('require_once "foo.php"'), [ ("require", "foo.php")] )
+
 
 if __name__ == '__main__':
     unittest.main()