Skip to content

Commit

Permalink
minor #4562 Add some tests on balanced brackets (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Add some tests on balanced brackets

Commits
-------

3b605c4 Add some tests on balanced brackets
  • Loading branch information
fabpot committed Jan 30, 2025
2 parents 69f8d40 + 3b605c4 commit 4b4a630
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,25 @@ public static function getTemplateForInlineCommentsForComment()
Some regular comment # this is an inline comment
#}'];
}

/**
* @dataProvider getTemplateForUnclosedBracketInExpression
*/
public function testUnclosedBracketInExpression(string $template, string $bracket)
{
$lexer = new Lexer(new Environment(new ArrayLoader()));

$this->expectException(SyntaxError::class);
$this->expectExceptionMessage(\sprintf('Unclosed "%s" in "index" at line 1.', $bracket));

$lexer->tokenize(new Source($template, 'index'));
}

public static function getTemplateForUnclosedBracketInExpression()
{
yield ['{{ (1 + 3 }}', '('];
yield ['{{ obj["a" }}', '['];
yield ['{{ ({ a: 1) }}', '{'];
yield ['{{ (([1]) + 3 }}', '('];
}
}

0 comments on commit 4b4a630

Please sign in to comment.