;;; phps-mode-test-lex-analyzer.el --- Tests for functions -*- lexical-binding: t -*- ;; Copyright (C) 2018-2021 Free Software Foundation, Inc. ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; Run from terminal make functions-test ;;; Code: (require 'ert) (require 'phps-mode) (require 'phps-mode-test) (defun phps-mode-test-lex-analyzer--process-changes () "Test `phps-mode-lex-analyzer--process-changes'." (phps-mode-test--with-buffer "\n\n") (should (equal (phps-mode-lex-analyzer--process-changes) '((RUN-FULL-LEXER) (FOUND-NO-HEAD-TOKENS 1))))) (phps-mode-test--with-buffer "\n\n\n' . print_r($store_vars, true) . '';\necho 'search_ids:
' . print_r($search_ids, true) . '
';\n}" "Alternative indentation on line echo" (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "' . print_r($store_vars, true) . '';\n echo 'search_ids:
' . print_r($search_ids, true) . '
';\n}" )))) (phps-mode-test--with-buffer "\n'def',\n);" "Alternative indentation on lines after lines ending with T_DOUBLE_ARROW" (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "\n 'def',\n);" )))) (phps-mode-test--with-buffer " true,\n\n);" "Alternative indentation after comma ended double arrow assignment" (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents " true,\n \n);" )))) (phps-mode-test--with-buffer "getResponseBodyDecoded();\n // TODO Here\n" "Line after multi-line assignment with object-operator" (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "$applications =\n $transaction->getResponseBodyDecoded();\n// TODO Here\n" )))) (phps-mode-test--with-buffer "
' . __('Data', 'something')\n . ':
' . print_r($decodedData, true) . '
';\necho '
';\n" "Two echo statements, one spans two lines" (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "
' . __('Data', 'something')\n . ':
' . print_r($decodedData, true) . '
';\necho '
';\n " )))) (phps-mode-test--with-buffer "id ===\n \\MyClass::METHOD_ID\n ) {\n" "Multi-line if statement testing equality in two lines" (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "id ===\n \\MyClass::METHOD_ID\n) {\n " )))) (phps-mode-test--with-buffer "" "Multi-line if block after opening parenthesis" (execute-kbd-macro "")) (execute-kbd-macro "if (true) {") (execute-kbd-macro (kbd "")) (execute-kbd-macro "if (") (execute-kbd-macro (kbd "")) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "" "HEREDOC in arguments example" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "\n \n" "Regular if-expression but inside scripting tags" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (1 0)) (3 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " 0\n && $letter > 0\n);" "Do while loop with multi-line condition" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " 0\n && $letter > 0\n);" "Do while loop with multi-line condition" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "" "Concatenated assignment string with function call" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "" "Concatenated assignment string with function call" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (1 0)) (7 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "" "Concatenated echo string with function call" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "" "Concatenated echo string with function call" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (1 0)) (7 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " [\n 'label' => __('No'),\n 'value' => 0,\n ],\n];" "Assignment with square bracketed array" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1 0)) (7 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " 123\n ))\n);" "Assignment with double-dimensional array with double arrow assignment inside function call" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " array(array(\n 'errorTo'\n ))\n);" "Assignment with three-dimensional array with double arrow assignment" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "myMethod(myClass::class)\n ->myMethod2($myArgument2);\n }" "Object-oriented file with bracket-less namespace with multiple levels, class that extends and implements and functions with optional arguments" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "myFunction()\n ->mySecondaryFunction();" "Indentation of chained class method calls outside of assignments and conditionals" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "meMethod()\n ->mySecondMethod()\n ->myThirdMethod()\n->myFourthFunction(\n $myVariable\n);" "Indentation for chained object operators in assignment with method call with arguments" (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (1 0)) (7 (2 0)) (8 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "myMethod3)\n && $myVar->myMethod\n && $myVar->myMethod2;\n" "Indentation for chained object operators in assignment" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " [\n 'hello' => true\n ]\n];\n\n$array = array(\n 'second' => array(\n 'third' => true\n )\n);" "Indent multi-dimensional arrays without trailing commas" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0 0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (2 0)) (11 (1 0)) (12 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))) (phps-mode-test--with-buffer "\n \n \n \n \n \n \n" "A mixed HTML and PHP file." ;; (message "Indent: %s" (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))) (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (1 0)) (5 (1 0)) (6 (0 0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (0 0)) (11 (0 0)) (12 (0 0)) (13 (1 0)) (14 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) ) (phps-mode-test--with-buffer " $b) {\n $foo->bar($arg1);\n } else {\n BazClass::bar($arg2, $arg3);\n }\n }\n\n final public static function bar()\n {\n // method body\n }\n}\n" "PSR-2 : 1.1. Example" ;; (message "Indent: %s" (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))) (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (0 0)) (7 (0 0)) (8 (0 0)) (9 (0 0)) (10 (1 0)) (11 (1 0)) (12 (2 0)) (13 (3 0)) (14 (2 0)) (15 (3 0)) (16 (2 0)) (17 (3 0)) (18 (2 0)) (19 (1 0)) (20 (1 0)) (21 (1 0)) (22 (1 0)) (23 (2 0)) (24 (1 0)) (25 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "bar($arg1);\nFoo::bar($arg2, $arg3);" "PSR-2 : 4.6. Method and Function Calls : Example 1" (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "bar(\n $longArgument,\n $longerArgument,\n $muchLongerArgument\n);" "PSR-2 : 4.6. Method and Function Calls : Example 2" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer " $value) {\n // foreach body\n}" "PSR-2 : 5.5. foreach" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "bar(\n $arg1,\n function ($arg2) use ($var1) {\n // body\n },\n $arg3\n);" "PSR-2 : 6. Closures : Example 3" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (2 0)) (6 (1 0)) (7 (1 0)) (8 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) ) (defun phps-mode-test-lex-analyzer--get-lines-indent-multi-line-assignments () "Test for multi-line assignments." (phps-mode-test--with-buffer "\n 'hello'\n);" "Array assignment with double arrow elements on four lines" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "getTail()\n ->getBottom();" "Multi-line assignments" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (2 0)) (7 (2 0)) (8 (3 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) ) (defun phps-mode-test-lex-analyzer--get-lines-indent-inline-if () "Test for inline if indentations." (phps-mode-test--with-buffer "<?php if ($myCondition) {\n if ($mySeconCondition) {\n echo $title2;\n\n } ?>Bla bla" "Mixed HTML/PHP with if expression and token-less lines" ;; (message "Tokens: %s" phps-mode-lexer-tokens) ;; (message "Indent: %s" (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))) (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (2 0)) (5 (1 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "<?php\nif ($myCondition) {\n if ($mySecondCondition) {\n echo $title;\n } else if ($mySecondCondition) {\n echo $title4;\n } else {\n echo $title2;\n echo $title3;\n }\n} ?>Bla bla" "Mixed HTML/PHP with if expression 2" (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2 0)) (7 (1 0)) (8 (2 0)) (9 (2 0)) (10 (1 0)) (11 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) (phps-mode-test--with-buffer "var = 'abc123';\n} else {\n $this->var = 'def456';\n}\n" "Regular else expression indent calculation" ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point)) (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 0))) (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))) ) (defun phps-mode-test-lex-analyzer--get-lines-indent-switch-case () "Test for switch-case indentation." (phps-mode-test--with-buffer "<?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title;\n\n} ?>Bla bla" "Curly bracket test" (goto-char 69) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "<?php if ($myCondition) {\n if ($mySeconCondition) {\necho $title;\n\n} ?>Bla bla")))) (phps-mode-test--with-buffer "<?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title1;\n} ?>Bla bla" "Curly bracket test 2" (goto-char 75) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "<?php if ($myCondition) {\nif ($mySeconCondition) {\n echo $title1;\n} ?>Bla bla")))) (phps-mode-test--with-buffer "<?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title2;\n\n} ?>Bla bla" "Curly bracket test 3" (goto-char 98) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "<?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title2;\n\n } ?>Bla bla")))) (phps-mode-test--with-buffer "<?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title3;\n\n}\n?>\nBla bla" "Curly bracket test 4" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (goto-char 110) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "<?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title3;\n\n}\n?>\n Bla bla")))) (phps-mode-test--with-buffer "id}\",'__return_empty_array'\n);" "Round bracket test 2" (goto-char 25) (phps-mode-lex-analyzer--indent-line) ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "id}\",'__return_empty_array'\n);")))) (phps-mode-test--with-buffer "var\n) && !empty($this->var)\n) {\n$this->var = 'abc123';\n}\n" "Nested if-expression" (goto-char 54) (phps-mode-lex-analyzer--indent-line) ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "var\n) && !empty($this->var)\n) {\n$this->var = 'abc123';\n}\n")))) (phps-mode-test--with-buffer "var = 'abc123';\n } else {\n $this->var = 'def456';\n}\n" "Regular else expression" (goto-char 68) (phps-mode-lex-analyzer--indent-line) ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "var = 'abc123';\n} else {\n $this->var = 'def456';\n}\n")))) (phps-mode-test--with-buffer "var = 'abc123';\n } else if (mySeconCondition()) {\n $this->var = 'def456';\n}\n" "Regular else if test" (goto-char 68) (phps-mode-lex-analyzer--indent-line) ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "var = 'abc123';\n} else if (mySeconCondition()) {\n $this->var = 'def456';\n}\n")))) ;; Square bracket (phps-mode-test--with-buffer " [\n 'hello',\n],\n];\n" "Square bracket test 1" (goto-char 51) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents " [\n 'hello',\n ],\n];\n")))) (phps-mode-test--with-buffer " 'abc',\n ),\n $var5\n);\n" "Function arguments with associate array indentation" (goto-char 65) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents " 'abc',\n ),\n $var5\n);\n")))) (phps-mode-test--with-buffer "getHead()\n->getTail();\n" "Multi-line assignment indentation test 1" ;; (message "Tokens: %s" phps-mode-lexer-tokens) (goto-char 35) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "getHead()\n ->getTail();\n")))) (phps-mode-test--with-buffer "var)):\n$this->var = 'abc123';\n endif;" "Alternative control structure if expression" (goto-char 60) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "var)):\n$this->var = 'abc123';\nendif;")))) (phps-mode-test--with-buffer "var)):\n$this->var = 'abc123';\nendif;" "Alternative control structure test" (goto-char 35) (phps-mode-lex-analyzer--indent-line) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "var)):\n $this->var = 'abc123';\nendif;")))) (phps-mode-test--with-buffer "\n\n<?php echo $title; ?>\n\n\n
\n\n" "A mixed HTML and PHP file, each PHP command is inside HTML markup" (indent-region (point-min) (point-max)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "\n \n <?php echo $title; ?>\n \n \n
\n \n")))) (phps-mode-test--with-buffer "\n\n<?php echo $title; ?>\n\n\">\n
\n\n" "A mixed HTML and PHP file, each PHP command is inside HTML markup, one PHP inside markup tag" (indent-region (point-min) (point-max)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "\n \n <?php echo $title; ?>\n \n \">\n
\n \n")))) (phps-mode-test--with-buffer "\n \n <?php $myTitle; ?>\n \n \n \n

My title

\n \n
\n A lot of other stuff.\n
\n \n \n" "Indent mixed HTML and one-line PHP lines." (indent-region (point-min) (point-max)) (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) (should (equal buffer-contents "\n \n <?php $myTitle; ?>\n \n \n \n

My title

\n \n
\n A lot of other stuff.\n
\n \n \n")))) (phps-mode-test--with-buffer "addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" : \"\") . \" was here.\");\n }\n \n /**\n *\n */\n public function myFunction2()\n {\n }\n\n /**\n * It's good\n */\n public function myFunction3()\n {\n }\n\n /**\n *\n */\n public function myFunction4()\n {\n }\n}\n" "Imenu with double quoted string with variable inside it and concatenated string" (should (equal (phps-mode-lex-analyzer--get-imenu) '(("MyNamespace" ("MyClass" ("__construct" . 92) ("myFunction1" . 193) ("myFunction2" . 365) ("myFunction3" . 445) ("myFunction4" . 515))))))) (phps-mode-test--with-buffer "\n\nMyTitle\n\n\n

My paragraph

\n\n" 0 0 0 0 0 )))) (should (equal '(2 2 1 0) (nth 0 (phps-mode-lex-analyzer--get-inline-html-indentation "\n

My paragraph

\n\n" 2 2 0 0 0 )))) (should (equal '(0) (nth 0 (phps-mode-lex-analyzer--get-inline-html-indentation "" 0 0 0 0 0 )))) (should (equal '(0 1 2 1 0) (nth 0 (phps-mode-lex-analyzer--get-inline-html-indentation "\n" 0 0 0 0 0 )))) ) (defun phps-mode-test-lex-analyzer--bookkeeping () "Test the bookkeeping." (phps-mode-test--with-buffer " $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 ($c = 456);\n" "Bookkeeping of conditional assignments" (should (equal (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-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) (list (list 332 334) 1) (list " id $b" 1) (list (list 373 375) 1) (list (list 393 395) 1) (list " id $c" 1) (list (list 457 459) 1))))) (phps-mode-test--with-buffer "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 echo 'Hit';\n }\n if ($this->var4) {\n echo 'Hit';\n }\n if ($this->var5) {\n echo 'Miss';\n }\n if (paren1) {\n echo 'Hit';\n }\n }\n}\n\nif ($this) {\n echo 'Miss';\n}\nif (self) {\n echo 'Miss';\n}\nif (paren1) {\n echo 'Miss';\n}" "Bookkeeping of class properties" ;; (message "Bookkeeping: %s" (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-bookkeeping) t)) (should (equal (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-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) (list (list 508 513) 1) (list (list 515 519) 1) (list (list 569 574) 1) (list (list 576 580) 0) (list (list 688 693) 0))))) (phps-mode-test--with-buffer "random();\n $this->random['abc'] = 123;\n }\n}" "Method calls should be avoied in bookkeeping" ;; (message "Bookkeeping: %s" (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-bookkeeping) t)) (should (equal (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-bookkeeping) t) (list (list " class myClass function __construct id $this" 1) (list (list 89 94) 1) (list (list 114 119) 1))))) (phps-mode-test--with-buffer " &$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-lex-analyzer--get-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--with-buffer " $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-lex-analyzer--get-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 $x3" 1) (list (list 102 105) 1) (list (list 110 113) 1) (list " id $x4" 1) (list (list 115 118) 1) (list (list 144 147) 1) (list " arrow function 5 id $x5" 1) (list (list 152 155) 1) (list (list 165 168) 1) (list " arrow function 6 id $x6" 1) (list (list 174 177) 1) (list (list 182 185) 1) (list " arrow function 7 id $x7" 1) (list (list 191 194) 1) (list (list 199 202) 1) (list " arrow function 8 id $x8" 1) (list (list 207 210) 1) (list " arrow function 8 id $rest" 1) (list (list 215 220) 1) (list (list 225 230) 1))))) (phps-mode-test--with-buffer " 'random');\nif ($z->name) {\n echo 'Hit';\n}" "Bookkeeping object properties." (should (equal (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-bookkeeping) t) (list (list " id $z" 1) (list (list 7 9) 1) (list (list 52 54) 1))))) (phps-mode-test--with-buffer " $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-lex-analyzer--get-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--with-buffer "