Add more tests to the Lexer

This commit is contained in:
Fabien Potencier
2024-08-10 12:12:20 +02:00
parent 221e62cf63
commit 38250b91ca
+28
View File
@@ -401,4 +401,32 @@ bar
yield ['{{ ='];
yield ['{{ ..'];
}
/**
* @dataProvider getTemplateForStrings
*/
public function testStrings(string $expected)
{
$template = '{{ "'.$expected.'" }}';
$lexer = new Lexer(new Environment(new ArrayLoader()));
$stream = $lexer->tokenize(new Source($template, 'index'));
$stream->expect(Token::VAR_START_TYPE);
$stream->expect(Token::STRING_TYPE, $expected);
$template = "{{ '".$expected."' }}";
$lexer = new Lexer(new Environment(new ArrayLoader()));
$stream = $lexer->tokenize(new Source($template, 'index'));
$stream->expect(Token::VAR_START_TYPE);
$stream->expect(Token::STRING_TYPE, $expected);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function getTemplateForStrings()
{
yield ["日本では、春になると桜の花が咲きます。多くの人々は、公園や川の近くに集まり、お花見を楽しみます。桜の花びらが風に舞い、まるで雪のように見える瞬間は、とても美しいです。"];
yield ["في العالم العربي، يُعتبر الخط العربي أحد أجمل أشكال الفن. يُستخدم الخط في تزيين المساجد والكتب والمخطوطات القديمة. يتميز الخط العربي بجماله وتناسقه، ويُعتبر رمزًا للثقافة الإسلامية."];
}
}