Skip to content

Commit

Permalink
Check if normal PHP parsed with SBP stay valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien committed Apr 25, 2014
1 parent d898745 commit 9c56b7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/sbp/sbp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,9 @@ static public function parse($content)
'#(catch\s*\([^\)]+\)\s*)([^\s\{])#'
=> '$1{} $2',

'#\(('.self::PARENTHESES.')\)#'
=> '$1'

));
return $content;
}
Expand Down
27 changes: 19 additions & 8 deletions tests/sbp/spbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@ protected function assertParse($from, $to, $message = null)
return $this->assertTrue($from === $to, $message.", it return\"$parsed\"\n\n");
}

protected function assertParseFile($from, $message = null)
static protected function matchContent($from, $to)
{
if(is_null($message))
{
$message = "sbp::fileParse(\"$from\") do match the compiled file";
}
$trim = static::IGNORE_BRACES ? "{}\n\r\t " : "\n\r\t ";
$out = trim(file_get_contents($from));
$in = trim(sbp::testContent(preg_replace('#^(.+)(/[^/]+)$#', '$1/.src$2', $from)));
$in = trim(sbp::testContent($to));
$to = str_replace(array("\n", "\r", "\t", ' '), '', $out);
$from = str_replace(array("\n", "\r", "\t", ' '), '', $in);
$to = preg_replace('#/\*.*\*/#U', '', $to);
$from = preg_replace('#/\*.*\*/#U', '', $from);
$trim = static::IGNORE_BRACES ? "{}\n\r\t " : "\n\r\t ";
$lastDiffKey = -2 * static::WRAP_LINES;
$lastPrintedKey = $lastDiffKey;
if($from !== $to)
Expand Down Expand Up @@ -93,7 +89,22 @@ protected function assertParseFile($from, $message = null)
}
}
}
return $this->assertTrue($from === $to, $message);
return ($from === $to);
}

protected function assertParseFile($from, $message = null, $keepMessage = null)
{
if(is_null($message))
{
$message = "sbp::fileParse(\"$from\") do match the compiled file";
}
if(is_null($keepMessage))
{
$keepMessage = "Normal PHP in compiled \"$from\" must be keeped intact if reparsed";
}
$to = preg_replace('#^(.+)(/[^/]+)$#', '$1/.src$2', $from);
$this->assertTrue(static::matchContent($from, $to), $message);
$this->assertTrue(static::matchContent($from, $from), $keepMessage);
}

public function testParse()
Expand Down

0 comments on commit 9c56b7f

Please sign in to comment.