private function parseTestsFile($testsFile)
{
if (!($markdown = file($testsFile, FILE_SKIP_EMPTY_LINES))) {
return array();
}
$tests = array();
$prepend = '';
$mode = false;
$head = false;
$append = false;
$heading = '/^(#+)\\s+(.*)(\\s*)$/';
$code = '/^(```)(.*)/';
foreach ($markdown as $line) {
$matches = array();
$head = $head ? $head : false;
if (preg_match($heading, $line, $matches)) {
$mode = $matches[1];
$head = trim($matches[2]);
$tests[$head] = '';
continue;
}
if (preg_match($code, $line, $matches) && $head) {
$append = !$append;
continue;
}
if ($head && $mode && $append) {
switch ($mode) {
case '##':
$prepend .= $line;
break;
case '###':
$tests[$head] .= $line;
break;
}
}
}
foreach ($tests as $action => $test) {
if (!$test) {
unset($tests[$action]);
}
}
return array($prepend, $tests);
}