packages/sql-faker/tests/Unit/Compiler/GrammarParseExceptionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\Compiler;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use SqlFaker\Compiler\GrammarParseException;
10
11#[CoversClass(GrammarParseException::class)]
12final class GrammarParseExceptionTest extends TestCase
13{
14 public function testNoRulesParsedNamesTheBisonGrammar(): void
15 {
16 self::assertSame(
17 'No grammar rules parsed from the Bison grammar.',
18 GrammarParseException::noRulesParsed('Bison')->getMessage(),
19 );
20 }
21
22 public function testNoRulesParsedNamesTheLemonGrammar(): void
23 {
24 self::assertSame(
25 'No grammar rules parsed from the Lemon grammar.',
26 GrammarParseException::noRulesParsed('Lemon')->getMessage(),
27 );
28 }
29
30 public function testUnreadableSourceNamesThePathThatWasAskedFor(): void
31 {
32 self::assertSame(
33 'Failed to read: /no/such/parse.y',
34 GrammarParseException::unreadableSource('/no/such/parse.y')->getMessage(),
35 );
36 }
37
38 public function testUnexpectedCharacterNamesTheCharacterAndWhereItSits(): void
39 {
40 self::assertSame(
41 "Unexpected character '#' at offset 12",
42 GrammarParseException::unexpectedCharacter('#', 12)->getMessage(),
43 );
44 }
45
46 public function testDanglingSlashNamesWhereTheSlashSits(): void
47 {
48 self::assertSame("Unexpected '/' at offset 7", GrammarParseException::danglingSlash(7)->getMessage());
49 }
50
51 public function testNamelessDirectiveNamesWhereThePercentSignSits(): void
52 {
53 self::assertSame("Unexpected '%' at offset 3", GrammarParseException::namelessDirective(3)->getMessage());
54 }
55
56 public function testUnterminatedTypeTagNamesWhereTheTagOpened(): void
57 {
58 self::assertSame(
59 'Unterminated type tag starting at offset 42',
60 GrammarParseException::unterminatedTypeTag(42)->getMessage(),
61 );
62 }
63}
64