Eyrie-Templates/tests/Parser/ParserTest.php

51 lines
1.5 KiB
PHP
Raw Normal View History

2026-01-06 23:29:10 +00:00
<?php
declare(strict_types=1);
namespace Eyrie\Tests\Parser;
use Eyrie\Parser\Lexer;
use Eyrie\Parser\Parser;
use Eyrie\Parser\Node\RootNode;
use Eyrie\Parser\Node\TextNode;
use Eyrie\Parser\Node\ExpressionNode;
use PHPUnit\Framework\TestCase;
class ParserTest extends TestCase
{
public function testParseSimpleText(): void
{
$lexer = new Lexer('Hello World');
$parser = new Parser($lexer->tokenize());
$root = $parser->parse();
$this->assertInstanceOf(RootNode::class, $root);
$this->assertCount(1, $root->children);
$this->assertInstanceOf(TextNode::class, $root->children[0]);
$this->assertEquals('Hello World', $root->children[0]->content);
}
public function testParseExpression(): void
{
$lexer = new Lexer('<< name >>');
$parser = new Parser($lexer->tokenize());
$root = $parser->parse();
$this->assertCount(1, $root->children);
$this->assertInstanceOf(ExpressionNode::class, $root->children[0]);
$this->assertEquals('name', $root->children[0]->expression);
}
public function testParseMixed(): void
{
$lexer = new Lexer('Hello << name >>!');
$parser = new Parser($lexer->tokenize());
$root = $parser->parse();
$this->assertCount(3, $root->children);
$this->assertInstanceOf(TextNode::class, $root->children[0]);
$this->assertInstanceOf(ExpressionNode::class, $root->children[1]);
$this->assertInstanceOf(TextNode::class, $root->children[2]);
}
}