packages/sql-faker/tests/Unit/Compiler/Lemon/LemonTextTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\Compiler\Lemon;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use SqlFaker\Compiler\Lemon\LemonText;
10
11#[CoversClass(LemonText::class)]
12final class LemonTextTest extends TestCase
13{
14 public function testWithoutCommentsRemovesBlockAndLineComments(): void
15 {
16 self::assertSame(
17 "cmd ::= SELECT. \n",
18 (new LemonText())->withoutComments("/* a rule */cmd ::= SELECT. // and a note\n"),
19 );
20 }
21
22 public function testWithoutCommentsLeavesGrammarAlone(): void
23 {
24 self::assertSame('cmd ::= SELECT.', (new LemonText())->withoutComments('cmd ::= SELECT.'));
25 }
26
27 public function testWithoutDirectiveBlocksRemovesTheCTheParserIsBuiltFrom(): void
28 {
29 self::assertSame(
30 "\ncmd ::= SELECT.",
31 (new LemonText())->withoutDirectiveBlocks("%include {cmd ::= NOTHING.}\ncmd ::= SELECT."),
32 );
33 }
34
35 public function testWithoutDirectiveBlocksRemovesTheDeclarationsThatConfigureTheParser(): void
36 {
37 self::assertSame(
38 "\ncmd ::= SELECT.",
39 (new LemonText())->withoutDirectiveBlocks("%token_prefix TK_\ncmd ::= SELECT."),
40 );
41 }
42}
43