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
|
<?php declare(strict_types=1);
namespace PhpParser;
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);
}
}
|