diff --git a/src/parser/aast/api/AASTNode.php b/src/parser/aast/api/AASTNode.php --- a/src/parser/aast/api/AASTNode.php +++ b/src/parser/aast/api/AASTNode.php @@ -293,7 +293,7 @@ } if (!$left) { - return null; + return ''; } return preg_replace("/^.*\n/s", '', $left->getValue()); diff --git a/src/parser/aast/api/AASTTree.php b/src/parser/aast/api/AASTTree.php --- a/src/parser/aast/api/AASTTree.php +++ b/src/parser/aast/api/AASTTree.php @@ -130,6 +130,10 @@ return $this->tree[0]; } + final public function getNodes() { + return $this->tree; + } + protected function buildTree(array $tree) { $ii = count($this->tree); $nodes = array(); diff --git a/src/parser/xhpast/api/__tests__/XHPASTNodeTestCase.php b/src/parser/xhpast/api/__tests__/XHPASTNodeTestCase.php --- a/src/parser/xhpast/api/__tests__/XHPASTNodeTestCase.php +++ b/src/parser/xhpast/api/__tests__/XHPASTNodeTestCase.php @@ -19,7 +19,7 @@ $this->assertStringVariables(array(), "<<<'EOT'\n\$a\nEOT"); } - private function assertStringVariables($expected, $string) { + private function assertStringVariables(array $expected, $string) { $statement = XHPASTTree::newStatementFromString($string); $this->assertEqual( $expected, @@ -58,6 +58,30 @@ } } + public function testGetIndentation() { + $dir = dirname(__FILE__).'/indentation/'; + $files = id(new FileFinder($dir)) + ->withType('f') + ->withSuffix('php.test') + ->find(); + + foreach ($files as $file) { + list($tree, $expect) = $this->readTestData($dir.'/'.$file); + + foreach ($tree->getNodes() as $node) { + $id = (string)$node->getID(); + $this->assertEqual( + idx($expect, $id), + $node->getIndentation(), + pht( + 'Indentation for node %d in file "%s": %s.', + $node->getID(), + $file, + $node->getConcreteString())); + } + } + } + /** * Reads and parses test data from a specified file. * diff --git a/src/parser/xhpast/api/__tests__/indentation/class.php.test b/src/parser/xhpast/api/__tests__/indentation/class.php.test new file mode 100644 --- /dev/null +++ b/src/parser/xhpast/api/__tests__/indentation/class.php.test @@ -0,0 +1,28 @@ +