mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-08 21:05:37 +00:00
Fix unary operator precedence change
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Twig\Tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
|
||||
use Twig\Attribute\FirstClassTwigCallableReady;
|
||||
use Twig\Compiler;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
@@ -24,6 +25,7 @@ use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\FilterExpression;
|
||||
use Twig\Node\Expression\FunctionExpression;
|
||||
use Twig\Node\Expression\TestExpression;
|
||||
use Twig\Node\Expression\Unary\AbstractUnary;
|
||||
use Twig\Node\Expression\Variable\ContextVariable;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Parser;
|
||||
@@ -564,6 +566,28 @@ class ExpressionParserTest extends TestCase
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
|
||||
public function testUnaryPrecedenceChange()
|
||||
{
|
||||
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
|
||||
$env->addExtension(new class () extends AbstractExtension {
|
||||
public function getOperators()
|
||||
{
|
||||
$class = new class (new ConstantExpression('foo', 1), 1) extends AbstractUnary {
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('!');
|
||||
}
|
||||
};
|
||||
|
||||
return [['!' => ['precedence' => 50, 'class' => $class::class]], []];
|
||||
}
|
||||
});
|
||||
$parser = new Parser($env);
|
||||
|
||||
$parser->parse($env->tokenize(new Source('{{ !false ? "OK" : "KO" }}', 'index')));
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
|
||||
private static function createContextVariable(string $name, array $attributes): ContextVariable
|
||||
{
|
||||
$expression = new ContextVariable($name, 1);
|
||||
|
||||
Reference in New Issue
Block a user