packages/sql-parser/tests/Unit/Lexer/SourceExceptionTest.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\SourceException;
13use SqlParser\Lexer\SourcePosition;
14
15#[CoversClass(SourceException::class)]
16#[UsesClass(LexicalException::class)]
17#[UsesClass(SourcePosition::class)]
18#[Small]
19final class SourceExceptionTest extends TestCase
20{
21 public function testCarriesTheOffsetAndPosition(): void
22 {
23 $exception = LexicalException::unterminated('string', "SELECT\n'abc", 7);
24
25 self::assertSame('Unterminated string at line 2, column 1', $exception->getMessage());
26 self::assertSame(7, $exception->offset);
27 self::assertSame(2, $exception->position->line);
28 self::assertSame(1, $exception->position->column);
29 }
30}
31