mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-28 11:06:50 +00:00
Add some tests
This commit is contained in:
@@ -310,7 +310,6 @@ namespace {
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Extension\CoreExtension;
|
||||
use Twig\Extension\SandboxExtension;
|
||||
use Twig\Markup;
|
||||
@@ -1020,18 +1019,18 @@ function twig_compare($a, $b)
|
||||
return $a <=> $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pattern
|
||||
* @param string $subject
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws SyntaxError When an invalid pattern is used
|
||||
*/
|
||||
/**
|
||||
* @param string $pattern
|
||||
* @param string $subject
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws RuntimeError When an invalid pattern is used
|
||||
*/
|
||||
function twig_matches(string $regexp, string $str)
|
||||
{
|
||||
set_error_handler(function ($t, $m) use ($regexp) {
|
||||
throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
|
||||
throw new RuntimeError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
|
||||
});
|
||||
try {
|
||||
return preg_match($regexp, $str);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
Twig supports the "matches" operator with a great error message
|
||||
--TEMPLATE--
|
||||
{{ 'foo' matches '/o' }}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\RuntimeError: Regexp "/o" passed to "matches" is not valid: No ending delimiter '/' found in "index.twig" at line 2
|
||||
Reference in New Issue
Block a user