Chris@0: getPathname(); Chris@0: $fileContents = file_get_contents($fileName); Chris@0: $fileContents = canonicalize($fileContents); Chris@0: Chris@0: // evaluate @@{expr}@@ expressions Chris@0: $fileContents = preg_replace_callback( Chris@0: '/@@\{(.*?)\}@@/', Chris@0: function($matches) { Chris@0: return eval('return ' . $matches[1] . ';'); Chris@0: }, Chris@0: $fileContents Chris@0: ); Chris@0: Chris@0: // parse sections Chris@0: $parts = preg_split("/\n-----(?:\n|$)/", $fileContents); Chris@0: Chris@0: // first part is the name Chris@0: $name = array_shift($parts) . ' (' . $fileName . ')'; Chris@0: $shortName = ltrim(str_replace($directory, '', $fileName), '/\\'); Chris@0: Chris@0: // multiple sections possible with always two forming a pair Chris@0: $chunks = array_chunk($parts, 2); Chris@0: foreach ($chunks as $i => $chunk) { Chris@0: $dataSetName = $shortName . (count($chunks) > 1 ? '#' . $i : ''); Chris@0: list($expected, $mode) = $this->extractMode($chunk[1]); Chris@0: $tests[$dataSetName] = array($name, $chunk[0], $expected, $mode); Chris@0: } Chris@0: } Chris@0: Chris@0: return $tests; Chris@0: } Chris@0: Chris@0: private function extractMode($expected) { Chris@0: $firstNewLine = strpos($expected, "\n"); Chris@0: if (false === $firstNewLine) { Chris@0: $firstNewLine = strlen($expected); Chris@0: } Chris@0: Chris@0: $firstLine = substr($expected, 0, $firstNewLine); Chris@0: if (0 !== strpos($firstLine, '!!')) { Chris@0: return [$expected, null]; Chris@0: } Chris@0: Chris@0: $expected = (string) substr($expected, $firstNewLine + 1); Chris@0: return [$expected, substr($firstLine, 2)]; Chris@0: } Chris@0: }