packages/sql-semantics-sqlite/tests/Unit/Model/Statement/Spelling/LayoutTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Model\Statement\Spelling;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Statement\Spelling\Layout;
11use SqlSemantics\Platform\Sqlite\Model\Statement\Spelling\Spelled;
12
13#[CoversClass(Layout::class)]
14#[Small]
15final class LayoutTest extends TestCase
16{
17    public function testTextJoinsTheTokensWithTheirGapsButNotTheFirstGap(): void
18    {
19        $layout = new Layout([new Spelled('  ', 'a'), new Spelled(' ', '+'), new Spelled('/**/', '1')]);
20
21        self::assertSame('a +/**/1', $layout->text());
22    }
23
24    public function testLayoutRefusesAnEmptyTokenList(): void
25    {
26        $this->expectExceptionMessage('A layout spells at least one token.');
27
28        new Layout([]);
29    }
30
31    public function testTrailKeepsTheTriviaAfterTheLastTokenOutsideTheText(): void
32    {
33        $layout = new Layout([new Spelled('', '1')], ' /* c */ ');
34
35        self::assertSame(' /* c */ ', $layout->trail);
36        self::assertSame('1', $layout->text());
37    }
38}
39