zoe             Sun Jul  5 22:07:00 2009 UTC

  Modified files:              
    /phpruntests/src/testcase   rtPhpTest.php rtPhpTestFile.php 
  Log:
  more work on the parser
  
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/rtPhpTest.php?r1=1.14&r2=1.15&diff_format=u
Index: phpruntests/src/testcase/rtPhpTest.php
diff -u phpruntests/src/testcase/rtPhpTest.php:1.14 
phpruntests/src/testcase/rtPhpTest.php:1.15
--- phpruntests/src/testcase/rtPhpTest.php:1.14 Sun Jul  5 17:22:15 2009
+++ phpruntests/src/testcase/rtPhpTest.php      Sun Jul  5 22:07:00 2009
@@ -41,35 +41,35 @@
     public function parse()
     {
         $lastSection = end($this->sectionHeadings);
+        $start=0;
 
         foreach($this->sectionHeadings as $keyNumber => $sectionKey) {
+
             if($keyNumber < count($this->sectionHeadings) - 1) {
                 $nextKey = $this->sectionHeadings[$keyNumber + 1];
             }
+
             $tempArray=array();
-            foreach($this->contents as $lineNumber => $line) {
-                if($line == "--".$sectionKey."--") {
+            for($index=$start; $index<count($this->contents); $index++)
+            if($this->contents[$index] == "--".$sectionKey."--") {
                 //Found the beginning of the section
-                
-                    for($contentsLine=$lineNumber + 1; 
$contentsLine<count($this->contents); $contentsLine ++) {
-                         
-                        if( ($this->contents[$contentsLine] == 
"--".$nextKey."--") || ($contentsLine == count($this->contents))) {
+
+                for($contentsLine=$index + 1; 
$contentsLine<count($this->contents); $contentsLine ++) {
+                     
+                    if( ($this->contents[$contentsLine] == "--".$nextKey."--") 
|| ($contentsLine == count($this->contents))) {
                         //Found the end of the section OR the end of the test
-                            $lineNumber --;
-                            $sectionContents = array();
-                            foreach($tempArray as $line) {
-                            //Check for a ===DONE== 
-                                $sectionContents[] = $line;
-                                if(stripos($line, "===done===") !== false) {
-                                    break;
-                                }
-                            }
-                            $testSection = rtSection::getInstance($sectionKey, 
$sectionContents);
+                        $start = $contentsLine - 1;
+                        if($this->isFileSection($sectionKey)) {
+                            $tempArray = $this->removeDone($tempArray);
+                        }
+
+                        if(count($tempArray) > 0) {
+                            $testSection = rtSection::getInstance($sectionKey, 
$tempArray);
                             $this->sections[$sectionKey] = $testSection;
-                            break;
-                        } else {
-                            $tempArray[] = $this->contents[$contentsLine];
                         }
+                        break;
+                    } else {
+                        $tempArray[] = $this->contents[$contentsLine];
                     }
                 }
             }
@@ -84,6 +84,7 @@
         $this->expectSection = $this->setExpectSection();
 
         $this->fileSection->setExecutableFileName($this->getName());
+
     }
 
 
@@ -164,18 +165,33 @@
 
 
     /**
-     * Identify a section heading
+     * Identify a FILE section
      *
      */
-    private function isSectionKey($line)
+    private function isFileSection($key)
     {
-        if (in_array($line, $this->sectionHeadings)) {
+        if (strpos($key, "FILE") !== false) {
             return true;
         }
         return false;
     }
 
 
+    /*
+     * Strip the lines after ===DONE=== from the file section of a test
+     */
+    private function removeDone($array) {
+        $result = array();
+        foreach($array as $line) {
+            $result[] = $line;
+            if(stripos($line, "===done===") !== false) {
+                break;
+            }
+        }
+        return $result;
+    }
+
+
     /**
      * Set the test's file section
      */
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/rtPhpTestFile.php?r1=1.7&r2=1.8&diff_format=u
Index: phpruntests/src/testcase/rtPhpTestFile.php
diff -u phpruntests/src/testcase/rtPhpTestFile.php:1.7 
phpruntests/src/testcase/rtPhpTestFile.php:1.8
--- phpruntests/src/testcase/rtPhpTestFile.php:1.7      Sun Jul  5 17:22:15 2009
+++ phpruntests/src/testcase/rtPhpTestFile.php  Sun Jul  5 22:07:00 2009
@@ -44,32 +44,21 @@
 
         public function normaliseLineEndings()
         {
-            $tempArray = array();
             for ($i=0; $i<count($this->testContents); $i++) {
                 //This is not nice but there are a huge number of tests with 
random spacs at the end of the section header
-                //and empty sections.
                 if (preg_match("/^\s*--([A-Z]+(_[A-Z]+|))--/", 
$this->testContents[$i], $matches)) {
-                    //look ahead to next section unless this is the last test 
section. 
-                    //if the EXPECT section is empty (missing) it will be 
caught by preconditions.
-                    //If the next line is also a section heading than skip 
adding it to the test case or headings.
-                    if($i< count($this->testContents) - 1) {
-                        if (!preg_match("/--([A-Z]+(_[A-Z]+|))--/", 
$this->testContents[$i+1])) {
-                            $this->sectionHeadings[] = $matches[1];
-                            $tempArray[] = "--".$matches[1]."--";
-                        }
-                    }
+                    $this->sectionHeadings[] = $matches[1];
+                    $this->testContents[$i] = '--' . $matches[1] . '--';
                 } else {
-                    $tempArray[] = rtrim($this->testContents[$i], 
$this->carriageReturn.$this->newLine);
+                    $this->testContents[$i] = rtrim($this->testContents[$i], 
$this->carriageReturn.$this->newLine);
                 }
             }
-            $this->testContents = $tempArray;
-           
         }
 
         public function arePreConditionsMet()
         {
             foreach ($this->preConditions as $preCondition) {
-                $condition = new $preCondition;               
+                $condition = new $preCondition;
                 if (!$condition->isMet($this->sectionHeadings)) {
                     $this->testExitMessage = $condition->getMessage();
                     return false;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to