Skip to content

Commit

Permalink
Assert: match() minor refactoring of whitespace normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Aug 5, 2016
1 parent 7d29c02 commit 7b7ecde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public static function isMatching($pattern, $actual)
$utf8 = preg_match('#\x80-\x{10FFFF}]#u', $pattern) ? 'u' : '';
$patterns = static::$patterns + [
'[.\\\\+*?[^$(){|\x00\#]' => '\$0', // preg quoting
'[\t ]*\r?\n' => "[\\t ]*\n", // right trim
'[\t ]*\r?\n' => '[\t ]*\r?\n', // right trim
];
$pattern = '#^' . preg_replace_callback('#' . implode('|', array_keys($patterns)) . '#U' . $utf8, function ($m) use ($patterns) {
foreach ($patterns as $re => $replacement) {
Expand All @@ -496,7 +496,6 @@ public static function isMatching($pattern, $actual)
}
}
}, rtrim($pattern)) . '\s*$#sU' . $utf8;
$actual = str_replace("\r\n", "\n", $actual);
}

$res = preg_match($pattern, $actual);
Expand Down
8 changes: 6 additions & 2 deletions tests/Framework/Assert.match.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ require __DIR__ . '/../bootstrap.php';
$matches = [
['1', '1'],
['1', 1],
['a', "a \t\r\n\t \n"],
["a \t\r\n", 'a'],
["a\nb", "a\r\nb"],
["a\r\nb", "a\nb"],
["a\t \nb", "a\nb"],
["a\nb", "a\t \nb"],
["a\t\r\n\t ", 'a'],
['a', "a\t\r\n\t "],
['%a%', 'a b'],
['%a?%', 'a b'],
['%a?%', ''],
Expand Down

0 comments on commit 7b7ecde

Please sign in to comment.