Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F18712932
D14695.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D14695.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 30, 5:34 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
9217478
Default Alt Text
D14695.diff (2 KB)
Attached To
Mode
D14695: Add unit tests for `AASTNode::getIndentation`
Attached
Detach File
Event Timeline
Log In to Comment