branch: externals/phps-mode
commit 8652f7162ee1e8cc82ea024f6f63e017dea63ea4
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Started on bookkeeping generation via parser SDT
---
phps-mode-ast.el | 119 +++++++++++++++--------
test/phps-mode-test-ast.el | 229 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 306 insertions(+), 42 deletions(-)
diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index dcbe8cce64..5a272f61ed 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -114,6 +114,19 @@
(nth 2 args))
phps-mode-parser--table-translations)
+;; inner_statement_list -> (inner_statement_list inner_statement)
+(puthash
+ 134
+ (lambda(args _terminals)
+ ;; (message "inner_statement_list: %S" args)
+ (let ((ast-object))
+ (if (car args)
+ (setq ast-object (append (car args) (cdr args)))
+ (setq ast-object (cdr args)))
+ ;; (message "ast-object: %S" ast-object)
+ ast-object))
+ phps-mode-parser--table-translations)
+
;; function_declaration_statement -> (function returns_ref T_STRING
backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags "{"
inner_statement_list "}" backup_fn_flags)
(puthash
174
@@ -221,6 +234,30 @@
phps-mode-parser--table-translations)
+;; expr -> (variable "=" expr)
+(puthash
+ 337
+ (lambda(args terminals)
+ (message "expr: %S %S" args terminals)
+ (let ((ast-object
+ (list
+ 'type
+ 'assign-variable
+ 'name
+ (nth 0 args)
+ 'start
+ (car (cdr (nth 0 terminals)))
+ 'end
+ (cdr (cdr (nth 0 terminals)))
+ 'value
+ (nth 2 args))))
+ ;; (message "Method: %S" ast-object)
+ ;; (message "args: %S" args)
+ ;; (message "terminals: %S" terminals)
+ ast-object))
+ phps-mode-parser--table-translations)
+
+
;; Functions:
@@ -230,7 +267,9 @@
(namespace)
(namespace-children)
(ast))
- ;; (message "translation:\n%S\n\n" translation)
+
+ (message "\nTranslation:\n%S\n\n" translation)
+
(when translation
(dolist (item translation)
(when (listp item)
@@ -285,45 +324,49 @@
(dolist (item ast)
(let ((children (plist-get item 'children))
(item-type (plist-get item 'type))
+ (item-index (plist-get item 'index))
(parent))
- (if (and
- (or
- (equal item-type 'namespace)
- (equal item-type 'class)
- (equal item-type 'interface))
- children)
- (progn
- (dolist (child children)
- (let ((grand-children (plist-get child 'children))
- (child-type (plist-get child 'type))
- (subparent))
- (if (and
- (or
- (equal child-type 'class)
- (equal child-type 'interface))
- grand-children)
- (progn
- (dolist (grand-child grand-children)
+ (when (and
+ item-type
+ item-index)
+ (if (and
+ (or
+ (equal item-type 'namespace)
+ (equal item-type 'class)
+ (equal item-type 'interface))
+ children)
+ (progn
+ (dolist (child children)
+ (let ((grand-children (plist-get child 'children))
+ (child-type (plist-get child 'type))
+ (subparent))
+ (if (and
+ (or
+ (equal child-type 'class)
+ (equal child-type 'interface))
+ grand-children)
+ (progn
+ (dolist (grand-child grand-children)
+ (push
+ `(,(plist-get grand-child 'name) . ,(plist-get
grand-child 'index))
+ subparent))
(push
- `(,(plist-get grand-child 'name) . ,(plist-get
grand-child 'index))
- subparent))
- (push
- (append
- (list (plist-get child 'name))
- (reverse subparent))
- parent))
- (push
- `(,(plist-get child 'name) . ,(plist-get child 'index))
- parent)))
- )
- (push
- (append
- (list (plist-get item 'name))
- (reverse parent))
- imenu-index))
- (push
- `(,(plist-get item 'name) . ,(plist-get item 'index))
- imenu-index))))
+ (append
+ (list (plist-get child 'name))
+ (reverse subparent))
+ parent))
+ (push
+ `(,(plist-get child 'name) . ,(plist-get child
'index))
+ parent)))
+ )
+ (push
+ (append
+ (list (plist-get item 'name))
+ (reverse parent))
+ imenu-index))
+ (push
+ `(,(plist-get item 'name) . ,(plist-get item 'index))
+ imenu-index)))))
(setq
phps-mode-ast--imenu
(reverse imenu-index)))
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index e1d50acb2d..05e7647903 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -27,6 +27,7 @@
(require 'ert)
(require 'phps-mode)
+(require 'phps-mode-test)
(require 'phps-mode-ast)
(defun phps-mode-test-ast--buffer-contents (buffer-contents name logic)
@@ -130,9 +131,9 @@
'(("MyNamespaceA" ("aFunctionA" . 46) ("MyClass" ("__construct" . 205)
("myFunction1" . 338) ("myFunction2" . 542) ("myFunction3" . 646)
("myFunction4" . 740))) ("aFunctionB" . 807) ("MyClass" ("__construct" . 925)
("myFunction1" . 1058) ("myFunction2" . 1262) ("myFunction3" . 1366)
("myFunction4" . 1460)))))))
(phps-mode-test-ast--buffer-contents
- "<?php\nnamespace myNamespace {\n class myClass extends myAbstract {\n
public function myFunctionA() {}\n protected function myFunctionB()
{}\n }\n}\n"
- "Imenu object-oriented file with namespace, class that extends and functions"
- (lambda()
+ "<?php\nnamespace myNamespace {\n class myClass extends myAbstract {\n
public function myFunctionA() {}\n protected function myFunctionB()
{}\n }\n}\n"
+ "Imenu object-oriented file with namespace, class that extends and
functions"
+ (lambda()
(phps-mode-ast-generate)
(should
(equal
@@ -215,7 +216,227 @@
"Run test for bookkeeping generation."
(message "-- Running tests for bookkeeping generation... --\n")
-
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$var = 'abc';\n\nif ($var2) {\n echo 'This never
happens';\n}\nif ($var) {\n echo 'This happens';\n}"
+ "Bookkeeping in root level variable assignments #1."
+ (lambda()
+ (let ((parse (phps-mode-parser-parse)))
+ (message "Left-to-right with left-most derivation:\n%S\n" parse)
+ (dolist (production-number (reverse parse))
+ (let ((production
+ (phps-mode-parser--get-grammar-production-by-number
+ production-number)))
+ (message
+ "%d: %S -> %S"
+ production-number
+ (car (car production))
+ (car (cdr production))))))
+ (phps-mode-ast-generate)
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $var" 1) (list (list 8 12) 1) (list (list 27
32) 0) (list (list 73 77) 1))))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$var = 'abc';\n\nif ($var) {\n echo 'This never
happens';\n}\nif ($var2) {\n echo 'This happens';\n}"
+ "Bookkeeping in root level variable assignments #2."
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $var" 1) (list (list 8 12) 1) (list (list 27 31)
1) (list (list 72 77) 0)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$var2 = 4;\n\nfunction myFunction($var)\n{\n $var3 = 3;\n
if ($var) {\n echo 'Hit';\n }\n if ($var2) {\n echo
'Miss';\n }\n if ($var3) {\n echo 'Hit';\n }\n}\n\nfunction
myFunction2($abc)\n{\n if ($var) {\n echo 'Miss';\n }\n if
($abc) {\n echo 'Hit';\n }\n}\n\nif ($var) {\n echo 'Miss';\n}\nif
($var2) {\n echo 'Hit';\n}"
+ "Bookkeeping in function level with variable assignments."
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" id $var2" 1) ((8 13) 1) (" function myFunction id $var" 1)
((40 44) 1) (" function myFunction id $var3" 1) ((52 57) 1) ((71 75) 1) ((113
118) 0) ((157 162) 1) (" function myFunction2 id $abc" 1) ((216 220) 1) ((232
236) 0) ((275 279) 1) ((316 320) 0) ((347 352) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n// Super-globals\n\nif ($_GET) {\n echo 'Hit';\n}\nif ($_POST)
{\n echo 'Hit';\n}\nif ($_COOKIE) {\n echo 'Hit';\n}\nif ($_SESSION) {\n
echo 'Hit';\n}\nif ($_REQUEST) {\n echo 'Hit';\n}\nif ($GLOBALS) {\n
echo 'Hit';\n}\nif ($_SERVER) {\n echo 'Hit';\n}\nif ($_FILES) {\n echo
'Hit';\n}\nif ($_ENV) {\n echo 'Hit';\n}\nif ($argc) {\n echo
'Hit';\n}\nif ($argv) {\n echo 'Hit';\n}\nif ($http_​response_​header) {\n
echo 'Hit';\n}"
+ "Bookkeeping of super-globals"
+ (should
+ (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list (list 30 35) 1) (list (list 61 67) 1) (list (list 93 101) 1)
(list (list 127 136) 1) (list (list 162 171) 1) (list (list 197 205) 1) (list
(list 231 239) 1) (list (list 265 272) 1) (list (list 298 303) 1) (list (list
329 334) 1) (list (list 360 365) 1) (list (list 391 414) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nnamespace myNamespaceA {\n $var = 123;\n class myClassA {\n
private $var2 = 123;\n function myFunctionA($var3) {\n
$var4 = 123;\n if ($var) {\n echo 'Miss';\n
}\n if ($var2) {\n echo 'Miss';\n }\n
if ($var3) {\n echo 'Hit';\n }\n if
($var4) {\n echo 'Hit';\n }\n }\n\n
function myFuncti [...]
+ "Bookkeeping in maximum level with namespaces, classes and functions."
+ (should
+ (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping 1)
+ (list (list " id $var" 1) (list (list 37 41) 1) (list " namespace
myNamespaceA class myClassA id $var2" 1) (list (list 86 91) 1) (list "
namespace myNamespaceA class myClassA function myFunctionA id $this" 1) (list "
namespace myNamespaceA class myClassA function myFunctionA id $var3" 1) (list
(list 128 133) 1) (list " namespace myNamespaceA class myClassA function
myFunctionA id $var4" 1) (list (list 149 154) 1) (list (list 178 182) 0) (list
(list 245 250) 0) (list (list 313 318) 1 [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n// Conditional assignments\n\n$items = array(1, 2, 3);\nforeach
($items as $item) {\n if ($item) {\n echo 'Hit';\n }\n}\nforeach
($items as $key => $value) {\n if ($key || $value) {\n echo 'Hit';\n
}\n}\nfor ($i = 0; $i < count($items); $i++) {\n if ($i) {\n echo
'Hit';\n }\n}\nif ($a = 123) {\n if ($a) {\n echo 'Hit';\n
}\n}\nwhile ($b = 123) {\n if ($a) {\n echo 'Hit';\n }\n}\ndo {\n
echo 'Hit';\n} while ( [...]
+ "Bookkeeping of conditional assignments"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $items" 1) (list (list 36 42) 1) (list (list 70
76) 1) (list " id $item" 1) (list (list 80 85) 1) (list (list 97 102) 1) (list
(list 143 149) 1) (list " id $key" 1) (list (list 153 157) 1) (list " id
$value" 1) (list (list 161 167) 1) (list (list 179 183) 1) (list (list 187 193)
1) (list " id $i" 1) (list (list 230 232) 1) (list (list 238 240) 1) (list
(list 249 255) 1) (list (list 258 260) 1) (list (list 274 276) 1) (list " id
$a" 1) (list (list 312 314) 1) [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n// Class properties\n\nclass myParent {}\n\nclass myClass extends
myParent {\n private $var1 = 123;\n protected static $var2;\n public
$var3;\n var $var4;\n function __construct() {\n if ($this) {\n
echo 'Hit';\n }\n if ($this->var1) {\n echo
'Hit';\n }\n if (self::$var1) {\n echo 'Miss';\n
}\n if (self::$var2) {\n echo 'Hit';\n }\n if
($this->var3) {\n [...]
+ "Bookkeeping of class properties"
+ ;; (message "Bookkeeping: %s" (phps-mode-test--hash-to-list
phps-mode-ast--bookkeeping t))
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " class myParent id $var1" 1) (list (list 93 98) 1)
(list " class myParent static id $var2" 1) (list (list 127 132) 1) (list "
class myParent id $var3" 1) (list (list 145 150) 1) (list " class myParent id
$var4" 1) (list (list 160 165) 1) (list " class myParent function __construct
id $this" 1) (list (list 208 213) 1) (list (list 263 268) 1) (list (list 270
274) 1) (list (list 330 335) 0) (list (list 392 397) 1) (list (list 447 452) 1)
(list (list 454 458) 1) (lis [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\ntry {\n \n} catch (\\Exception $e) {\n if ($e) {\n
echo 'Hit';\n }\n}\n\nif ($e) {\n echo 'Miss';\n}\n"
+ "Bookkeeping of try catch variable assignment"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $e" 1) (list (list 39 41) 1) (list (list 53 55)
1) (list (list 92 94) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$example = function ($test) {\n if ($test) {\n echo
'Hit';\n }\n if ($example) {\n echo 'Miss';\n }\n};\n$example2
= function ($test2) use ($example) {\n if ($test2) {\n echo 'Hit';\n
}\n if ($example) {\n echo 'Hit';\n }\n if ($example2) {\n
echo 'Miss';\n }\n if ($example3) {\n echo 'Miss';\n
}\n};\nif ($test) {\n echo 'Miss';\n}\nif ($test2) {\n echo 'Miss';\n}"
+ "Bookkeeping of anonymous function variable assignments"
+ ;; (message "Bookkeeping: %s" (phps-mode-test--hash-to-list
phps-mode-ast--bookkeeping t))
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $example" 1) (list (list 8 16) 1) (list "
anonymous function 1 id $test" 1) (list (list 29 34) 1) (list (list 46 51) 1)
(list (list 89 97) 0) (list " id $example2" 1) (list (list 131 140) 1) (list "
anonymous function 2 id $test2" 1) (list (list 153 159) 1) (list " anonymous
function 2 id $example" 1) (list (list 166 174) 1) (list (list 186 192) 1)
(list (list 230 238) 1) (list (list 276 285) 0) (list (list 324 333) 0) (list
(list 371 376) 0) (list (list 403 [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\nclass myClass {\n function random() {}\n function
__construct()\n {\n $this->random();\n $this->random['abc'] =
123;\n }\n}"
+ "Method calls should be avoided in bookkeeping"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " class myClass function __construct id $this" 1)
(list (list 89 94) 1) (list (list 114 119) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n$items = array(1, 2, 3);\nforeach ($items as &$item) {\n if
($item) {\n echo 'Hit';\n }\n}\nforeach ($items as $key => &$item2)
{\n if ($item) {\n echo 'Hit';\n }\n}"
+ "Bookkeeping of foreach reference variable declaration"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $items" 1) (list (list 7 13) 1) (list (list 41
47) 1) (list " id $item" 1) (list (list 52 57) 1) (list (list 69 74) 1) (list
(list 115 121) 1) (list " id $key" 1) (list (list 125 129) 1) (list " id
$item2" 1) (list (list 134 140) 1) (list (list 152 157) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n[$random, $bandom] = myValues();\nif ($random) {\n echo
'Hit';\n}\nif ($bandom) {\n echo 'Hit';\n}\n\narray($random2, $bandom2) =
myValues2();\nif ($random2) {\n echo 'Hit';\n}\nif ($bandom3) {\n echo
'Hit';\n}\n\n "
+ "Bookkeeping of variable declarations in array"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $random" 1) (list (list 9 16) 1) (list " id
$bandom" 1) (list (list 18 25) 1) (list (list 45 52) 1) (list (list 78 85) 1)
(list " id $random2" 1) (list (list 114 122) 1) (list " id $bandom2" 1) (list
(list 124 132) 1) (list (list 153 161) 1) (list (list 187 195) 0)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$var = 123;\n\nfunction test($abc) {\n global $var;\n if
($var) {\n echo 'Hit';\n }\n}"
+ "Bookkeeping of global variable declaration in function"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $var" 1) (list (list 8 12) 1) (list " function
test id $abc" 1) (list (list 35 39) 1) (list " function test id $var" 1) (list
(list 54 58) 1) (list (list 68 72) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n$y = 1;\n$fn1 = fn($x) => $x + $y;\n$z = 1;\n$fn = fn($x2) =>
fn($y2) => $x2 * $y2 + $z;\nfn(array $x3) => $x3;\n$x4 = 4;\nstatic fn(): int
=> $x4;\nfn($x5 = 42) => $x5;\nfn(&$x6) => $x6;\nfn&($x7) => $x7;\nfn($x8,
...$rest) => $rest;"
+ "Bookkeeping in arrow functions"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $y" 1) (list (list 7 9) 1) (list " id $fn1" 1)
(list (list 15 19) 1) (list " arrow function 1 id $x" 1) (list (list 25 27) 1)
(list (list 32 34) 1) (list (list 37 39) 1) (list " id $z" 1) (list (list 41
43) 1) (list " id $fn" 1) (list (list 49 52) 1) (list " arrow function 2 id
$x2" 1) (list (list 58 61) 1) (list " arrow function 2 id $y2" 1) (list (list
69 72) 1) (list (list 77 80) 1) (list (list 83 86) 1) (list (list 89 91) 1)
(list " arrow function 3 id $x [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n$z = (object) array('name' => 'random');\nif ($z->name) {\n echo
'Hit';\n}"
+ "Bookkeeping object properties."
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $z" 1) (list (list 7 9) 1) (list (list 52 54)
1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\nif (!$var = false) {\n echo 'Hit';\n}\n"
+ "Bookkeeping negative conditional assignment"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " id $var" 1) (list (list 12 16) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nif (isset($x)) {\n if ($x) {\n echo 'Hit';\n if
(isset($i, $u)) {\n if ($i) {\n echo 'Hit';\n
}\n if ($u) {\n echo 'Hit';\n }\n
if ($x) {\n echo 'Hit';\n }\n }\n
if ($i) {\n echo 'Miss';\n }\n if ($u) {\n
echo 'Miss';\n }\n }\n}\nif ($x) {\n echo 'Miss';\n}\n\nif
(!empty($y)) {\n if ( [...]
+ "Bookkeeping of isset() and !empty() scoped variables."
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " defined 1 id $x" 1) (list (list 18 20) 1) (list
(list 33 35) 1) (list " defined 2 id $i" 1) (list (list 77 79) 1) (list "
defined 2 id $u" 1) (list (list 81 83) 1) (list (list 104 106) 1) (list (list
168 170) 1) (list (list 232 234) 1) (list (list 302 304) 0) (list (list 355
357) 0) (list (list 408 410) 0) (list " defined 3 id $y" 1) (list (list 445
447) 1) (list (list 460 462) 1) (list " defined 4 id $k" 1) (list (list 505
507) 1) (list " defined 4 id $L" 1) (l [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\ninterface myInterface\n{\n function myFunction1();\n function
myFunction2($x);\n}\n"
+ "Bookkeeping variable in interface function"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ (list (list " class myInterface function myFunction2 id $x" 1)
(list (list 84 86) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nfunction myFunction1()\n{\n return isset($a);\n}\n\nfunction
myFunction2()\n{\n $b = 2;\n if ($b) {\n echo 'Hit';\n }\n
if ($b) {\n echo 'Hit';\n }\n}\n"
+ "Bookkeeping after definition condition"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '(((50 52) 0) (" function myFunction2 id $b" 1) ((87 89) 1) ((103
105) 1) ((143 145) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$a = array(1, 2, 3);\nforeach ($a as $uri => $page)\n{\n if
(isset($pages)) {\n if ($a) {\n echo 'Hit';\n }\n
if ($uri) {\n echo 'Hit';\n }\n if ($page) {\n
echo 'Hit';\n }\n }\n}\n"
+ "Bookkeeping of foreach variable inside if (isset()) block"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" id $a" 1) ((8 10) 1) ((38 40) 1) (" id $uri" 1) ((44 48) 1)
(" id $page" 1) ((52 57) 1) (" defined 1 id $pages" 1) ((75 81) 1) ((98 100) 1)
((150 154) 1) ((204 209) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\nif (isset($b)) {\n $b = false;\n}\n$c = 2;\n\nif ($c) {\n
echo 'Hit';\n}\n"
+ "Bookkeeping of variable after isset() block"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" defined 1 id $b" 2) ((17 19) 1) ((28 30) 1) (" id $c" 1) ((42
44) 1) ((55 57) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\nif (!isset($a)) {\n if ($a) {\n echo 'Miss';\n }\n}"
+ "Bookkeeping for variable in negative isset() conditional"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '(((18 20) 0) ((33 35) 0)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nfunction myFunction($a, $b, $c, $d)\n{\n global $f, $g;\n
if (isset($f)) {\n if (!empty($g)) {\n if ($a) {\n
echo 'Hit';\n }\n if ($b) {\n echo
'Hit';\n }\n if ($c) {\n echo 'Hit';\n
}\n if ($d) {\n echo 'Hit';\n }\n
}\n }\n}\n"
+ "Bookkeeping variables inside nested isset() !empty() blocks"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" function myFunction id $a" 1) ((28 30) 1) (" function
myFunction id $b" 1) ((32 34) 1) (" function myFunction id $c" 1) ((36 38) 1)
(" function myFunction id $d" 1) ((40 42) 1) (" function myFunction id $f" 1)
((57 59) 1) (" function myFunction id $g" 1) ((61 63) 1) (" function myFunction
defined 1 id $f" 1) ((79 81) 1) (" function myFunction defined 2 id $g" 1)
((105 107) 1) ((128 130) 1) ((192 194) 1) ((256 258) 1) ((320 322) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$var = 123;\n\nfunction test($abc) {\n static $var;\n if
($var) {\n echo 'Hit';\n }\n}"
+ "Bookkeeping of static variable declaration in function"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" id $var" 1) ((8 12) 1) (" function test id $abc" 1) ((35 39)
1) (" function test id $var" 1) ((54 58) 1) ((68 72) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nglobal $a, $b;\n\nif ($a) {\n echo 'Hit';\n}\n\nfunction
myFunction($c)\n{\n global $a;\n if ($a) {\n echo 'Hit';\n }\n
if ($b) {\n echo 'Miss';\n }\n}\n"
+ "Bookkeeping of global variables in functional-oriented file"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" id $a" 1) ((15 17) 1) (" id $b" 1) ((19 21) 1) ((28 30) 1) ("
function myFunction id $c" 1) ((73 75) 1) (" function myFunction id $a" 1) ((90
92) 1) ((102 104) 1) ((142 144) 0)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nstatic $a;\n\nif ($a) {}\n\nfunction test()\n{\n static $a;\n
if ($a) {}\n}\n\nclass There\n{\n function here()\n {\n static
$a;\n if ($a) {}\n }\n}"
+ "Bookkeeping of static variables in different scopes without namespaces"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" id $a" 1) ((15 17) 1) ((24 26) 1) (" function test id $a" 1)
((61 63) 1) ((73 75) 1) (" class There function here id $this" 1) (" class
There function here id $a" 1) ((138 140) 1) ((154 156) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\nnamespace Here\n{\n function here()\n {\n static
$a;\n if ($a) {}\n }\n class There\n {\n public function
Near()\n {\n static $a;\n if ($a) {}\n }\n
}\n}\nnamespace\n{\n static $a;\n if ($a) {}\n}\n"
+ "Bookkeeping of static variables in different scopes with namespaces"
+ (should (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" namespace Here function here id $a" 1) ((66 68) 1) ((82 84)
1) (" namespace Here class There function Near id $this" 1) (" namespace Here
class There function Near id $a" 1) ((177 179) 1) ((197 199) 1) (" id $a" 1)
((245 247) 1) ((257 259) 1)))))
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\nclass There\n{\n private $variable;\n private \\My\\Random
$variable2;\n private string $variable3;\n private static $variable4;\n
private static \\My\\Random $variable5;\n private static string
$variable6;\n function here()\n {\n if ($this->variable) {}\n
if ($this->variable2) {}\n if ($this->variable3) {}\n if
($this->variable4) {}\n if (self::$variable4) {}\n if
(self::$variable5) {}\n if (self::$varia [...]
+ "Bookkeeping of typed class variables"
+ (should
+ (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" class There id $variable" 1) ((33 42) 1) (" class There id
$variable2" 1) ((67 77) 1) (" class There id $variable3" 1) ((98 108) 1) ("
class There static id $variable4" 1) ((129 139) 1) (" class There static id
$variable5" 1) ((171 181) 1) (" class There static id $variable6" 1) ((209 219)
1) (" class There function here id $this" 1) ((259 264) 1) ((266 274) 1) ((291
296) 1) ((298 307) 1) ((324 329) 1) ((331 340) 1) ((357 362) 1) ((364 373) 0)
((396 406) 1) ((429 439) 1) ((462 [...]
+
+ (phps-mode-test-ast--buffer-contents
+ "<?php\n\n$a = $b = $c = 3;\n\nif ($a) {\n echo 'a=',$a;\n} else {\n
echo '$a is undefined!';\n}\nif ($b) {\n echo 'b=',$b;\n} else {\n echo
'$b is undefined!';\n}\nif ($c) {\n echo 'c=',$c;\n} else {\n echo '$c is
undefined!';\n}"
+ "Bookkeeping of typed class variables"
+ (should
+ (equal
+ (phps-mode-test--hash-to-list phps-mode-ast--bookkeeping t)
+ '((" id $a" 1) ((8 10) 1) (" id $b" 1) ((13 15) 1) (" id $c" 1) ((18 20)
1) ((31 33) 1) ((51 53) 1) ((99 101) 1) ((119 121) 1) ((167 169) 1) ((187 189)
1)))))
(message "\n-- Ran tests for bookkeeping generation. --"))