2016-10-02 23:01:18 +03:00
|
|
|
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
// TODO autoload classes
|
2016-10-02 23:11:45 +03:00
|
|
|
require_once(__DIR__ . "/../lexer.php");
|
2016-10-06 11:01:41 +03:00
|
|
|
require_once(__DIR__ . "/../parser.php");
|
2016-10-02 23:11:45 +03:00
|
|
|
require_once(__DIR__ . "/../Token.php");
|
2016-10-02 23:01:18 +03:00
|
|
|
|
|
|
|
class CommentsTest extends TestCase {
|
|
|
|
// TODO test w/ multiple files
|
2016-10-06 11:01:41 +03:00
|
|
|
const FILENAME = __dir__ . "/cases/commentsFile.php";
|
|
|
|
const PARSER_POC_FILE = __dir__ . "/cases/parserPocFile.php";
|
|
|
|
|
|
|
|
private $lexer;
|
|
|
|
|
2016-10-02 23:01:18 +03:00
|
|
|
/**
|
|
|
|
* TODO not actually a test - just a convenience during initial development
|
|
|
|
*/
|
2016-10-02 23:40:16 +03:00
|
|
|
public function testCommentsFile() {
|
2016-10-13 04:26:42 +03:00
|
|
|
$this->lexer = new \PhpParser\Lexer(self::FILENAME);
|
|
|
|
$tokensArray = $this->lexer->getTokensArray();
|
|
|
|
|
2016-10-02 23:01:18 +03:00
|
|
|
$expected = array(
|
2016-11-02 03:18:23 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::ScriptSectionStartTag, 0, 0, 5),
|
2016-10-03 03:21:02 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::Name, 5, 56, 52),
|
2016-10-03 06:26:01 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::SlashToken, 57, 58, 2),
|
2016-10-03 03:21:02 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::Name, 59, 59, 1),
|
2016-10-03 06:51:00 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::SemicolonToken, 60, 60, 1),
|
2016-10-03 03:21:02 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::Name, 61, 63, 3),
|
2016-10-03 06:26:01 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::SlashEqualsToken, 64, 64, 2),
|
2016-10-12 01:30:00 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::DecimalLiteralToken, 66, 66, 1),
|
2016-10-03 06:51:00 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::SemicolonToken, 67, 67, 1),
|
2016-10-03 02:34:50 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::VariableName, 68, 70, 6),
|
2016-10-03 06:26:01 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::AndKeyword, 74, 76, 5),
|
2016-10-09 01:22:12 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::Name, 79, 81, 3),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::AsteriskAsteriskToken, 82, 82, 2),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::AsteriskAsteriskEqualsToken, 84, 84, 3),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::EndOfFileToken, 87, 97, 10)
|
2016-10-02 23:01:18 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($tokensArray as $index=>$token) {
|
|
|
|
$this->assertEquals($expected[$index], $token, "Awesome");
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 09:17:20 +03:00
|
|
|
|
|
|
|
public function testParserPocFile() {
|
2016-10-13 04:26:42 +03:00
|
|
|
$this->lexer = new \PhpParser\Lexer(self::PARSER_POC_FILE);
|
|
|
|
$tokensArray = $this->lexer->getTokensArray();
|
2016-10-03 09:17:20 +03:00
|
|
|
$expected = array(
|
2016-11-02 03:18:23 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::ScriptSectionStartTag, 0, 0, 5),
|
2016-10-03 09:17:20 +03:00
|
|
|
new PhpParser\Token(PhpParser\TokenKind::ClassKeyword, 5, 7, 7),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::Name, 12, 13, 2),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::OpenBraceToken, 14, 16, 3),
|
|
|
|
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::FunctionKeyword, 17, 56, 47),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::Name, 64, 65, 4),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::OpenParenToken, 68, 68, 1),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::VariableName, 69, 69, 8),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::CloseParenToken, 77, 77, 1),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::OpenBraceToken, 78, 78, 1),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::EchoKeyword, 79, 88, 13),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::VariableName, 92, 92, 8),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::SemicolonToken, 100, 100, 1),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::PublicKeyword, 101, 107, 12),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::VariableName, 113, 114, 3),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::SemicolonToken, 116, 116, 1),
|
|
|
|
new PhpParser\Token(PhpParser\TokenKind::EndOfFileToken, 117,117,0)
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($tokensArray as $index=>$token) {
|
|
|
|
$this->assertEquals($expected[$index], $token, "Awesome");
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 23:01:18 +03:00
|
|
|
}
|