1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-27 04:14:44 +01:00
PHP-Parser/test/PHPParser/Tests/ParserTest.php
nikic 81e53ce0ff Insert comments when pretty printing
This changset also adds unit tests for Comments and adds a way to test the
pretty printer.
2012-05-11 16:18:14 +02:00

44 lines
1.2 KiB
PHP

<?php
require_once dirname(__FILE__) . '/CodeTestAbstract.php';
class PHPParser_Tests_ParserTest extends PHPParser_Tests_CodeTestAbstract
{
/**
* @dataProvider provideTestParse
*/
public function testParse($name, $code, $dump) {
$parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative);
$dumper = new PHPParser_NodeDumper;
$stmts = $parser->parse($code);
$this->assertEquals(
$this->canonicalize($dump),
$this->canonicalize($dumper->dump($stmts)),
$name
);
}
public function provideTestParse() {
return $this->getTests(dirname(__FILE__) . '/../../code/parser', 'test');
}
/**
* @dataProvider provideTestParseFail
*/
public function testParseFail($name, $code, $msg) {
$parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative);
try {
$parser->parse($code);
$this->fail(sprintf('"%s": Expected PHPParser_Error', $name));
} catch (PHPParser_Error $e) {
$this->assertEquals($msg, $e->getMessage(), $name);
}
}
public function provideTestParseFail() {
return $this->getTests(dirname(__FILE__) . '/../../code/parser', 'test-fail');
}
}