packages/bison-parser/tests/Unit/Ast/SymbolTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Ast;
6
7use BisonParser\Ast\Location;
8use BisonParser\Ast\Symbol;
9use BisonParser\Ast\SymbolKind;
10use PHPUnit\Framework\Attributes\CoversClass;
11use PHPUnit\Framework\Attributes\Small;
12use PHPUnit\Framework\Attributes\UsesClass;
13use PHPUnit\Framework\TestCase;
14
15#[CoversClass(Symbol::class)]
16#[UsesClass(Location::class)]
17#[UsesClass(SymbolKind::class)]
18#[Small]
19final class SymbolTest extends TestCase
20{
21    public function testIsIdentifier(): void
22    {
23        $identifier = new Symbol(SymbolKind::Identifier, 'expr', new Location(1, 1));
24        $literal = new Symbol(SymbolKind::CharLiteral, '+', new Location(1, 6));
25        $string = new Symbol(SymbolKind::String, 'number', new Location(1, 10));
26
27        self::assertTrue($identifier->isIdentifier());
28        self::assertFalse($literal->isIdentifier());
29        self::assertFalse($string->isIdentifier());
30        self::assertSame('1:6', (string) $literal->location);
31        self::assertNull($identifier->spelling);
32        self::assertSame("'\\101'", (new Symbol(SymbolKind::CharLiteral, 'A', new Location(1, 1), "'\\101'"))->spelling);
33    }
34}
35