packages/sql-parser/tests/Unit/PostgreSql/Source/KeywordListTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\PostgreSql\Source;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use RuntimeException;
11use SqlParser\PostgreSql\Source\KeywordList;
12
13#[CoversClass(KeywordList::class)]
14#[Small]
15final class KeywordListTest extends TestCase
16{
17    public function testParse(): void
18    {
19        $source = "PG_KEYWORD(\"select\", SELECT, RESERVED_KEYWORD, BARE_LABEL)\nPG_KEYWORD(\"abort\", ABORT_P, UNRESERVED_KEYWORD, BARE_LABEL)\n";
20
21        self::assertSame(['keywords' => ['ABORT' => 'ABORT_P', 'SELECT' => 'SELECT']], (new KeywordList())->parse($source));
22    }
23
24    public function testParseRejectsAFileWithoutKeywords(): void
25    {
26        $this->expectException(RuntimeException::class);
27
28        (new KeywordList())->parse('int x;');
29    }
30}
31