packages/lemon-parser/tests/Unit/Ast/Declaration/FallbackTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Ast\Declaration;
6
7use LemonParser\Ast\Declaration\Fallback;
8use LemonParser\Ast\Location;
9use LemonParser\Ast\Symbol;
10use PHPUnit\Framework\Attributes\CoversClass;
11use PHPUnit\Framework\Attributes\Small;
12use PHPUnit\Framework\Attributes\UsesClass;
13use PHPUnit\Framework\TestCase;
14
15#[CoversClass(Fallback::class)]
16#[UsesClass(Location::class)]
17#[UsesClass(Symbol::class)]
18#[Small]
19final class FallbackTest extends TestCase
20{
21 public function testFallback(): void
22 {
23 $declaration = new Fallback([new Symbol('ID', new Location(3, 11)), new Symbol('ABORT', new Location(3, 14))], new Location(3, 1));
24
25 self::assertSame('ID', $declaration->fallback()?->name);
26 self::assertNull((new Fallback([], new Location(4, 1)))->fallback());
27 }
28
29 public function testTokens(): void
30 {
31 $declaration = new Fallback([new Symbol('ID', new Location(3, 11)), new Symbol('ABORT', new Location(3, 14)), new Symbol('AFTER', new Location(3, 20))], new Location(3, 1));
32
33 self::assertSame(['ABORT', 'AFTER'], array_map(static fn (Symbol $symbol): string => $symbol->name, $declaration->tokens()));
34 self::assertSame([], (new Fallback([], new Location(4, 1)))->tokens());
35 }
36
37 public function testLocation(): void
38 {
39 self::assertSame('3:1', (string) (new Fallback([], new Location(3, 1)))->location());
40 }
41}
42