Page MenuHomePhabricator

D14695.diff
No OneTemporary

D14695.diff

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 @@
+<?php
+
+final class SomeClass {
+ public function someMethod() {}
+}
+~~~~~~~~~~
+{
+ "0": "",
+ "1": "",
+ "2": "",
+ "3": "",
+ "4": "",
+ "5": "",
+ "6": "",
+ "7": "",
+ "8": "",
+ "9": "",
+ "10": "",
+ "11": " ",
+ "12": " ",
+ "13": " ",
+ "14": "",
+ "15": " ",
+ "16": " ",
+ "17": "",
+ "18": " ",
+ "19": " "
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 12, 11:34 AM (21 h, 5 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
9217478
Default Alt Text
D14695.diff (2 KB)

Event Timeline