packages/sql-parser/tests/Unit/Lexer/LexicalExceptionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lexer;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\Attributes\UsesClass;
10use PHPUnit\Framework\TestCase;
11use SqlParser\Lexer\LexicalException;
12use SqlParser\Lexer\SourcePosition;
13
14#[CoversClass(LexicalException::class)]
15#[UsesClass(SourcePosition::class)]
16#[UsesClass(\SqlParser\Lexer\SourceException::class)]
17#[Small]
18final class LexicalExceptionTest extends TestCase
19{
20 public function testUnterminated(): void
21 {
22 $exception = LexicalException::unterminated('string', "SELECT 'abc", 7);
23
24 self::assertSame('Unterminated string at line 1, column 8', $exception->getMessage());
25 self::assertSame(7, $exception->offset);
26 }
27
28 public function testUnexpectedCharacter(): void
29 {
30 self::assertSame("Unexpected '#' at line 1, column 8", LexicalException::unexpectedCharacter('SELECT #', 7)->getMessage());
31 self::assertSame('Unexpected end of input at line 1, column 7', LexicalException::unexpectedCharacter('SELECT', 6)->getMessage());
32 }
33
34 public function testUnknownTerminal(): void
35 {
36 self::assertSame('Terminal FOO is not part of the grammar at line 1, column 1', LexicalException::unknownTerminal('FOO', 'foo', 0)->getMessage());
37 }
38}
39