packages/bison-parser/tests/Unit/Ast/Declaration/CodePropsTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Ast\Declaration;
6
7use BisonParser\Ast\Declaration\CodeProps;
8use BisonParser\Ast\Location;
9use BisonParser\Ast\Symbol;
10use BisonParser\Ast\SymbolKind;
11use BisonParser\Ast\Tag;
12use PHPUnit\Framework\Attributes\CoversClass;
13use PHPUnit\Framework\Attributes\Small;
14use PHPUnit\Framework\Attributes\UsesClass;
15use PHPUnit\Framework\TestCase;
16
17#[CoversClass(CodeProps::class)]
18#[UsesClass(Location::class)]
19#[UsesClass(Symbol::class)]
20#[UsesClass(SymbolKind::class)]
21#[UsesClass(Tag::class)]
22#[Small]
23final class CodePropsTest extends TestCase
24{
25    public function testLocation(): void
26    {
27        $declaration = new CodeProps(true, ' fprintf(yyo, "%d", $$); ', [new Symbol(SymbolKind::Identifier, 'NUM', new Location(3, 30)), new Tag(Tag::ANY, new Location(3, 34))], new Location(3, 1));
28
29        self::assertSame('3:1', (string) $declaration->location());
30        self::assertTrue($declaration->printer);
31        self::assertSame(' fprintf(yyo, "%d", $$); ', $declaration->code);
32        self::assertCount(2, $declaration->targets);
33    }
34}
35