File: TokenTest.php

package info (click to toggle)
php-parser 5.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 4,532 kB
  • sloc: php: 23,585; yacc: 1,272; makefile: 39; sh: 8
file content (49 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php declare(strict_types=1);

namespace PhpParser;

use PHPUnit\Framework\Attributes\DataProvider;

class TokenTest extends \PHPUnit\Framework\TestCase {
    public function testGetTokenName(): void {
        $token = new Token(\ord(','), ',');
        $this->assertSame(',', $token->getTokenName());
        $token = new Token(\T_WHITESPACE, ' ');
        $this->assertSame('T_WHITESPACE', $token->getTokenName());
    }

    public function testIs(): void {
        $token = new Token(\ord(','), ',');
        $this->assertTrue($token->is(\ord(',')));
        $this->assertFalse($token->is(\ord(';')));
        $this->assertTrue($token->is(','));
        $this->assertFalse($token->is(';'));
        $this->assertTrue($token->is([\ord(','), \ord(';')]));
        $this->assertFalse($token->is([\ord('!'), \ord(';')]));
        $this->assertTrue($token->is([',', ';']));
        $this->assertFalse($token->is(['!', ';']));
    }

    #[DataProvider('provideTestIsIgnorable')]
    public function testIsIgnorable(int $id, string $text, bool $isIgnorable): void {
        $token = new Token($id, $text);
        $this->assertSame($isIgnorable, $token->isIgnorable());
    }

    public static function provideTestIsIgnorable() {
        return [
            [\T_STRING, 'foo', false],
            [\T_WHITESPACE, ' ', true],
            [\T_COMMENT, '// foo', true],
            [\T_DOC_COMMENT, '/** foo */', true],
            [\T_OPEN_TAG, '<?php ', true],
        ];
    }

    public function testToString(): void {
        $token = new Token(\ord(','), ',');
        $this->assertSame(',', (string) $token);
        $token = new Token(\T_STRING, 'foo');
        $this->assertSame('foo', (string) $token);
    }
}