Skip to content

Commit

Permalink
bug #10131 added lines to exceptions for the trans and transchoice ta…
Browse files Browse the repository at this point in the history
…gs (fabpot)

This PR was merged into the 2.3 branch.

Discussion
----------

added lines to exceptions for the trans and transchoice tags

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10120
| License       | MIT
| Doc PR        | n/a

Commits
-------

ee0470d added lines to exceptions for the trans and transchoice tags
  • Loading branch information
fabpot committed Jan 25, 2014
2 parents aedb919 + ee0470d commit eb74cb6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ public function testTrans($template, $expected, array $variables = array())
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
}

/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
*/
public function testTransUnknownKeyword()
{
$output = $this->getTemplate("{% trans \n\nfoo %}{% endtrans %}")->render();
}

/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2.
*/
public function testTransComplexBody()
{
$output = $this->getTemplate("{% trans %}\n{{ 1 + 2 }}{% endtrans %}")->render();
}

/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
*/
public function testTransChoiceComplexBody()
{
$output = $this->getTemplate("{% transchoice count %}\n{{ 1 + 2 }}{% endtranschoice %}")->render();
}

public function getTransTests()
{
return array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);

if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
throw new \Twig_Error_Syntax('A message must be a simple text.');
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename());
}

$stream->expect(\Twig_Token::BLOCK_END_TYPE);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function parse(\Twig_Token $token)
$stream->next();
$locale = $this->parser->getExpressionParser()->parseExpression();
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with" or "from" keyword.');
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
}

Expand All @@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);

if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text');
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename());
}

$stream->expect(\Twig_Token::BLOCK_END_TYPE);
Expand Down

0 comments on commit eb74cb6

Please sign in to comment.