X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FCodeTestAbstract.php;fp=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FCodeTestAbstract.php;h=369ee41b8008cc6acc84170ac4212eac5084f623;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php b/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php new file mode 100644 index 000000000..369ee41b8 --- /dev/null +++ b/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php @@ -0,0 +1,61 @@ +getPathname(); + $fileContents = file_get_contents($fileName); + $fileContents = canonicalize($fileContents); + + // evaluate @@{expr}@@ expressions + $fileContents = preg_replace_callback( + '/@@\{(.*?)\}@@/', + function($matches) { + return eval('return ' . $matches[1] . ';'); + }, + $fileContents + ); + + // parse sections + $parts = preg_split("/\n-----(?:\n|$)/", $fileContents); + + // first part is the name + $name = array_shift($parts) . ' (' . $fileName . ')'; + $shortName = ltrim(str_replace($directory, '', $fileName), '/\\'); + + // multiple sections possible with always two forming a pair + $chunks = array_chunk($parts, 2); + foreach ($chunks as $i => $chunk) { + $dataSetName = $shortName . (count($chunks) > 1 ? '#' . $i : ''); + list($expected, $mode) = $this->extractMode($chunk[1]); + $tests[$dataSetName] = array($name, $chunk[0], $expected, $mode); + } + } + + return $tests; + } + + private function extractMode($expected) { + $firstNewLine = strpos($expected, "\n"); + if (false === $firstNewLine) { + $firstNewLine = strlen($expected); + } + + $firstLine = substr($expected, 0, $firstNewLine); + if (0 !== strpos($firstLine, '!!')) { + return [$expected, null]; + } + + $expected = (string) substr($expected, $firstNewLine + 1); + return [$expected, substr($firstLine, 2)]; + } +}