packages/bison-parser/tests/Unit/Ast/Rule/AlternativeTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Ast\Rule;
6
7use BisonParser\Ast\Location;
8use BisonParser\Ast\Rule\Action;
9use BisonParser\Ast\Rule\Alternative;
10use BisonParser\Ast\Rule\PrecItem;
11use BisonParser\Ast\Rule\SymbolItem;
12use BisonParser\Ast\Symbol;
13use BisonParser\Ast\SymbolKind;
14use PHPUnit\Framework\Attributes\CoversClass;
15use PHPUnit\Framework\Attributes\Small;
16use PHPUnit\Framework\Attributes\UsesClass;
17use PHPUnit\Framework\TestCase;
18
19#[CoversClass(Alternative::class)]
20#[UsesClass(Action::class)]
21#[UsesClass(Location::class)]
22#[UsesClass(PrecItem::class)]
23#[UsesClass(Symbol::class)]
24#[UsesClass(SymbolItem::class)]
25#[UsesClass(SymbolKind::class)]
26#[Small]
27final class AlternativeTest extends TestCase
28{
29 public function testSymbols(): void
30 {
31 $left = new Symbol(SymbolKind::Identifier, 'expr', new Location(2, 3));
32 $plus = new Symbol(SymbolKind::CharLiteral, '+', new Location(2, 8));
33 $alternative = new Alternative([
34 new SymbolItem($left, null),
35 new SymbolItem($plus, null),
36 new Action(null, ' $$ = $1; ', null, new Location(2, 12)),
37 new PrecItem(new Symbol(SymbolKind::Identifier, 'UMINUS', new Location(2, 30)), new Location(2, 24)),
38 ], new Location(2, 3));
39
40 self::assertSame([$left, $plus], $alternative->symbols());
41 self::assertSame('2:3', (string) $alternative->location);
42 }
43}
44