branch: externals/phps-mode commit a65c8af30899890ce1564313f9371e46c4c7eedd Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Extract ast code into separate file and test --- Makefile | 6 +- phps-mode-ast.el | 291 ++++++++++++++++++++++++++++++++++ test/phps-mode-test-ast.el | 148 ++++++++++++++++++ test/phps-mode-test-parser.el | 351 ------------------------------------------ 4 files changed, 444 insertions(+), 352 deletions(-) diff --git a/Makefile b/Makefile index 7207e62119..f425653679 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,11 @@ compile: find . -name "*.el" -exec $(EMACS_CMD) -f batch-byte-compile {} \; .PHONY: tests -tests: test-integration test-lexer test-lex-analyzer test-parser test-syntax-table +tests: test-integration test-lexer test-lex-analyzer test-parser test-syntax-table test-ast + +.PHONY: test-ast +test-ast: + $(EMACS_CMD) -l test/phps-mode-test-ast.el .PHONY: test-integration test-integration: diff --git a/phps-mode-ast.el b/phps-mode-ast.el new file mode 100644 index 0000000000..66e7f44091 --- /dev/null +++ b/phps-mode-ast.el @@ -0,0 +1,291 @@ +;;; phps-mode-ast.el --- Abstract Syntax Tree 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 <http://www.gnu.org/licenses/>. + + +;;; Commentary: + + +;;; Code: + + +(require 'phps-mode-parser) + + +;;; Variables: + + +(defvar-local + phps-mode-ast--current-namespace + nil + "Current namespace for AST.") + +(defvar-local + phps-mode-ast--current-namespace-children + nil + "Children for current namespace for AST.") + +(defvar-local + phps-mode-ast--tree + nil + "Tree for current buffer.") + +(defvar-local + phps-mode-ast--imenu + nil + "Imenu for current buffer.") + +;; top_statement_list -> (top_statement_list top_statement) +(puthash + 79 + (lambda(args _terminals) + ;; (message "top_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) + +;; top_statement -> (T_NAMESPACE namespace_declaration_name ";") +(puthash + 106 + (lambda(args terminals) + (let ((ast-object + (list + 'type + 'namespace + 'name + (nth 1 args) + 'index + (car (cdr (nth 1 terminals))) + 'start + (car (cdr (nth 2 terminals))) + 'end + 'max))) + ;; (message "Namespace %S" ast-object) + ;; (message "args: %S" args) + ;; (message "terminals: %S" terminals) + (setq + phps-mode-ast--current-namespace + ast-object) + ast-object)) + phps-mode-parser--table-translations) + +;; top_statement -> (T_NAMESPACE namespace_declaration_name "{" top_statement_list "}") +(puthash + 107 + (lambda(args terminals) + (let ((ast-object + (list + 'type + 'namespace + 'name + (nth 1 args) + 'index + (car (cdr (nth 1 terminals))) + 'start + (car (cdr (nth 2 terminals))) + 'end + (car (cdr (nth 4 terminals))) + 'children + (nth 3 args)))) + ;; (message "Namespace %S" ast-object) + ;; (message "args: %S" args) + ;; (message "terminals: %S" terminals) + ;; (message "ast-object: %S" ast-object) + (push + ast-object + phps-mode-ast--tree) + ast-object)) + phps-mode-parser--table-translations) + +;; top_statement -> (T_NAMESPACE "{" top_statement_list "}") +(puthash + 108 + (lambda(args _terminals) + ;; (message "T_NAMESPACE: %S" args) + (when (nth 2 args) + (setq + phps-mode-ast--tree + (append phps-mode-ast--tree (nth 2 args)))) + (nth 2 args)) + 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 + (lambda(args terminals) + (let ((ast-object + (list + 'type + 'function + 'name + (nth 2 args) + 'index + (car (cdr (nth 2 terminals))) + 'start + (car (cdr (nth 9 terminals))) + 'end + (car (cdr (nth 11 terminals)))))) + ;; (message "Function: %S" ast-object) + ;; (message "args: %S" args) + ;; (message "terminals: %S" terminals) + (when phps-mode-ast--current-namespace + (push + ast-object + phps-mode-ast--current-namespace-children)) + ast-object)) + phps-mode-parser--table-translations) + +;; class_declaration_statement -> (T_CLASS T_STRING extends_from implements_list backup_doc_comment "{" class_statement_list "}") +(puthash + 180 + (lambda(args terminals) + (let ((ast-object + (list + 'type + 'class + 'name + (nth 1 args) + 'index + (car (cdr (nth 1 terminals))) + 'start + (car (cdr (nth 5 terminals))) + 'end + (car (cdr (nth 7 terminals))) + 'children + (nth 6 args)))) + ;; (message "Class %S" ast-object) + ;; (message "args: %S" args) + ;; (message "terminals: %S" terminals) + (when phps-mode-ast--current-namespace + (push + ast-object + phps-mode-ast--current-namespace-children)) + ast-object)) + phps-mode-parser--table-translations) + +;; class_statement_list -> (class_statement_list class_statement) +(puthash + 276 + (lambda(args _terminals) + ;; (message "class_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) + +;; attributed_class_statement -> (method_modifiers function returns_ref identifier backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags method_body backup_fn_flags) +(puthash + 280 + (lambda(args terminals) + (let ((ast-object + (list + 'type + 'method + 'name + (nth 3 args) + 'index + (car (cdr (nth 3 terminals))) + 'start + (car (cdr (car (nth 10 terminals)))) + 'end + (cdr (cdr (car (cdr (cdr (nth 10 terminals))))))))) + ;; (message "Method: %S" ast-object) + ;; (message "args: %S" args) + ;; (message "terminals: %S" terminals) + ast-object)) + phps-mode-parser--table-translations) + + +;; Functions: + + +(defun phps-mode-ast-generate () + "Generate AST for current buffer." + (setq + phps-mode-ast--current-namespace + nil) + (setq + phps-mode-ast--tree + nil) + (let ((_translation (phps-mode-parser-translate))) + + ;; (message "translation: %S" translation) + + (when phps-mode-ast--current-namespace + (plist-put + phps-mode-ast--current-namespace + 'children + (reverse phps-mode-ast--current-namespace-children)) + (push + phps-mode-ast--current-namespace + phps-mode-ast--tree)) + + (let ((imenu-index)) + (dolist (item phps-mode-ast--tree) + (let ((children (plist-get item 'children)) + (item-type (plist-get item 'type)) + (parent)) + (if (and + (or + (equal item-type 'namespace) + (equal item-type 'class)) + children) + (progn + (dolist (child children) + (let ((grand-children (plist-get child 'children)) + (child-type (plist-get child 'type)) + (subparent)) + (if (and + (equal child-type 'class) + grand-children) + (progn + (dolist (grand-child grand-children) + (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)))) + (setq + phps-mode-ast--imenu + (reverse imenu-index))))) + + +(provide 'phps-mode-ast) +;;; phps-mode-ast.el ends here diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el new file mode 100644 index 0000000000..544cc8d5b8 --- /dev/null +++ b/test/phps-mode-test-ast.el @@ -0,0 +1,148 @@ +;;; phps-mode-test-ast.el --- Tests for AST -*- lexical-binding: t -*- + +;; Copyright (C) 2017-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 <http://www.gnu.org/licenses/>. + + +;;; Commentary: + +;; Run from terminal make test-parser + + +;;; Code: + +(require 'ert) +(require 'phps-mode) +(require 'phps-mode-ast) + +(defun phps-mode-test-ast--buffer-contents (buffer-contents name logic) + (with-temp-buffer + ;; Setup buffer + (insert buffer-contents) + (message + "Testing buffer %S with buffer-contents:\n%S\n" + name + (buffer-substring-no-properties (point-min) (point-max))) + + ;; Setup lexer + (setq + phps-mode-lexer--generated-tokens + nil) + (setq + phps-mode-lexer--state + 'ST_INITIAL) + (setq + phps-mode-lexer--states + nil) + (setq + phps-mode-lexer--state-stack + nil) + (setq + phps-mode-lexer--heredoc-label + nil) + (setq + phps-mode-lexer--heredoc-label-stack + nil) + (setq + phps-mode-lexer--nest-location-stack + nil) + + ;; Run lexer + (setq + semantic-lex-analyzer + #'phps-mode-lex-analyzer--re2c-lex) + (setq + semantic-lex-syntax-table + phps-mode-syntax-table) + (semantic-lex-buffer) + (setq + phps-mode-parser-tokens + (phps-mode-lex-analyzer--generate-parser-tokens + phps-mode-lexer--generated-tokens)) + + ;; Run test + (funcall logic) + (message "Passed %s" name))) + +(defun phps-mode-test-ast-imenu () + "Run test for imenu generation." + (message "-- Running tests for imenu generation... --\n") + + (phps-mode-test-ast--buffer-contents + "<?php\n\nnamespace MyNamespace;\n\nfunction aFunction() {\n /**\n * With some contents\n */\n}\n\nclass MyClass\n{\n\n /**\n *\n */\n public function __construct()\n {\n if ($test) {\n }\n }\n\n /**\n *\n */\n public function myFunction1()\n {\n $this->addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" : \"\") . \" was here.\");\n }\n \n /**\n *\n */\n public function myFunction2()\n [...] + "Passed imenu-generation via parser AST for basic object oriented file" + (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) + ;; (message "\nAST:\n%S\n" phps-mode-ast--tree) + ;; (message "imenu-index:\n%S\n" phps-mode-ast--imenu) + + (should + (equal + phps-mode-ast--imenu + '(("MyNamespace" ("aFunction" . 41) ("MyClass" ("__construct" . 160) ("myFunction1" . 261) ("myFunction2" . 433) ("myFunction3" . 513) ("myFunction4" . 583)))))))) + + (phps-mode-test-ast--buffer-contents + "<?php\n\nnamespace MyNamespaceA\n{\n function aFunctionA() {\n /**\n * With some contents\n */\n }\n class MyClass\n {\n\n /**\n *\n */\n public function __construct()\n {\n if ($test) {\n }\n }\n\n /**\n *\n */\n public function myFunction1()\n {\n $this->addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" : \"\") . \" was h [...] + "Passed imenu-generation via parser AST for advanced object oriented file" + (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) + ;; (message "\nAST:\n%S\n" phps-mode-ast--tree) + ;; (message "imenu-index:\n%S\n" phps-mode-ast--imenu) + (should + (equal + phps-mode-ast--imenu + '(("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))))))) + + (message "\n-- Ran tests for imenu generation. --")) + +(defun phps-mode-test-ast () + "Run test for ast." + (message "-- Running all tests for ast... --\n") + + (phps-mode-test-ast-imenu) + + (message "\n-- Ran all tests for ast. --")) + +(phps-mode-test-ast) + +(provide 'phps-mode-test-ast) + + +;;; phps-mode-test-ast.el ends here diff --git a/test/phps-mode-test-parser.el b/test/phps-mode-test-parser.el index d7de43b546..f6648b92af 100644 --- a/test/phps-mode-test-parser.el +++ b/test/phps-mode-test-parser.el @@ -27,8 +27,6 @@ (require 'ert) (require 'phps-mode) -(require 'phps-mode-lex-analyzer) -(require 'phps-mode-parser) (defun phps-mode-test-parser--buffer-contents (buffer-contents name logic) (with-temp-buffer @@ -306,359 +304,10 @@ (message "\n-- Ran tests for parser parse. --")) -(defun phps-mode-test-parser-translate () - "Run test for parse translation." - (message "-- Running tests for parser translation... --\n") - - (let ((ast) - (ast-current-namespace) - (ast-current-namespace-children)) - - ;; top_statement_list -> (top_statement_list top_statement) - (puthash - 79 - (lambda(args _terminals) - ;; (message "top_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) - - ;; top_statement -> (T_NAMESPACE namespace_declaration_name ";") - (puthash - 106 - (lambda(args terminals) - (let ((ast-object - (list - 'type - 'namespace - 'name - (nth 1 args) - 'index - (car (cdr (nth 1 terminals))) - 'start - (car (cdr (nth 2 terminals))) - 'end - 'max))) - ;; (message "Namespace %S" ast-object) - ;; (message "args: %S" args) - ;; (message "terminals: %S" terminals) - (setq - ast-current-namespace - ast-object) - ast-object)) - phps-mode-parser--table-translations) - - ;; top_statement -> (T_NAMESPACE namespace_declaration_name "{" top_statement_list "}") - (puthash - 107 - (lambda(args terminals) - (let ((ast-object - (list - 'type - 'namespace - 'name - (nth 1 args) - 'index - (car (cdr (nth 1 terminals))) - 'start - (car (cdr (nth 2 terminals))) - 'end - (car (cdr (nth 4 terminals))) - 'children - (nth 3 args)))) - ;; (message "Namespace %S" ast-object) - ;; (message "args: %S" args) - ;; (message "terminals: %S" terminals) - ;; (message "ast-object: %S" ast-object) - (push - ast-object - ast) - ast-object)) - phps-mode-parser--table-translations) - - ;; top_statement -> (T_NAMESPACE "{" top_statement_list "}") - (puthash - 108 - (lambda(args _terminals) - (message "T_NAMESPACE: %S" args) - (when (nth 2 args) - (setq - ast - (append ast (nth 2 args)))) - (nth 2 args)) - 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 - (lambda(args terminals) - (let ((ast-object - (list - 'type - 'function - 'name - (nth 2 args) - 'index - (car (cdr (nth 2 terminals))) - 'start - (car (cdr (nth 9 terminals))) - 'end - (car (cdr (nth 11 terminals)))))) - ;; (message "Function: %S" ast-object) - ;; (message "args: %S" args) - ;; (message "terminals: %S" terminals) - (when ast-current-namespace - (push - ast-object - ast-current-namespace-children)) - ast-object)) - phps-mode-parser--table-translations) - - ;; class_declaration_statement -> (T_CLASS T_STRING extends_from implements_list backup_doc_comment "{" class_statement_list "}") - (puthash - 180 - (lambda(args terminals) - (let ((ast-object - (list - 'type - 'class - 'name - (nth 1 args) - 'index - (car (cdr (nth 1 terminals))) - 'start - (car (cdr (nth 5 terminals))) - 'end - (car (cdr (nth 7 terminals))) - 'children - (nth 6 args)))) - ;; (message "Class %S" ast-object) - ;; (message "args: %S" args) - ;; (message "terminals: %S" terminals) - (when ast-current-namespace - (push - ast-object - ast-current-namespace-children)) - ast-object)) - phps-mode-parser--table-translations) - - ;; class_statement_list -> (class_statement_list class_statement) - (puthash - 276 - (lambda(args _terminals) - ;; (message "class_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) - - ;; attributed_class_statement -> (method_modifiers function returns_ref identifier backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags method_body backup_fn_flags) - (puthash - 280 - (lambda(args terminals) - (let ((ast-object - (list - 'type - 'method - 'name - (nth 3 args) - 'index - (car (cdr (nth 3 terminals))) - 'start - (car (cdr (car (nth 10 terminals)))) - 'end - (cdr (cdr (car (cdr (cdr (nth 10 terminals))))))))) - ;; (message "Method: %S" ast-object) - ;; (message "args: %S" args) - ;; (message "terminals: %S" terminals) - ast-object)) - phps-mode-parser--table-translations) - - (phps-mode-test-parser--buffer-contents - "<?php\n\nnamespace MyNamespace;\n\nfunction aFunction() {\n /**\n * With some contents\n */\n}\n\nclass MyClass\n{\n\n /**\n *\n */\n public function __construct()\n {\n if ($test) {\n }\n }\n\n /**\n *\n */\n public function myFunction1()\n {\n $this->addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" : \"\") . \" was here.\");\n }\n \n /**\n *\n */\n public function myFunction2() [...] - "Imenu with double quoted string with variable inside it and concatenated string" - (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)))))) - (let ((_translation (phps-mode-parser-translate)) - (imenu-index)) - ;; (message "translation: %S" translation) - - (when ast-current-namespace - (plist-put - ast-current-namespace - 'children - (reverse ast-current-namespace-children)) - (push - ast-current-namespace - ast)) - - (message "\nAST:\n%S\n" ast) - - (dolist (item ast) - (let ((children (plist-get item 'children)) - (item-type (plist-get item 'type)) - (parent)) - (if (and - (or - (equal item-type 'namespace) - (equal item-type 'class)) - children) - (progn - (dolist (child children) - (let ((grandchildren (plist-get child 'children)) - (child-type (plist-get child 'type)) - (subparent)) - (if (and - (equal child-type 'class) - grandchildren) - (progn - (dolist (grandchild grandchildren) - (push - `(,(plist-get grandchild 'name) . ,(plist-get grandchild '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)))) - - (message "imenu-index:\n%S\n" imenu-index) - - (should - (equal - imenu-index - '(("MyNamespace" ("aFunction" . 41) ("MyClass" ("__construct" . 160) ("myFunction1" . 261) ("myFunction2" . 433) ("myFunction3" . 513) ("myFunction4" . 583)))))) - ))) - - (setq - ast-current-namespace - nil) - (setq - ast-current-namespace-children - nil) - (setq - ast - nil) - - (phps-mode-test-parser--buffer-contents - "<?php\n\nnamespace MyNamespaceA\n{\n function aFunctionA() {\n /**\n * With some contents\n */\n }\n class MyClass\n {\n\n /**\n *\n */\n public function __construct()\n {\n if ($test) {\n }\n }\n\n /**\n *\n */\n public function myFunction1()\n {\n $this->addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" : \"\") . \" was [...] - "Imenu with double quoted string with variable inside it and concatenated string in two namespaces" - (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)))))) - (let ((_translation (phps-mode-parser-translate))) - ;; (message "translation: %S" translation) - - (when ast-current-namespace - (plist-put - ast-current-namespace - 'children - (reverse ast-current-namespace-children)) - (push - ast-current-namespace - ast)) - - (message "\nAST:\n%S\n" ast) - - (let ((imenu-index)) - (dolist (item ast) - (let ((children (plist-get item 'children)) - (item-type (plist-get item 'type)) - (parent)) - (if (and - (or - (equal item-type 'namespace) - (equal item-type 'class)) - children) - (progn - (dolist (child children) - (let ((grandchildren (plist-get child 'children)) - (child-type (plist-get child 'type)) - (subparent)) - (if (and - (equal child-type 'class) - grandchildren) - (progn - (dolist (grandchild grandchildren) - (push - `(,(plist-get grandchild 'name) . ,(plist-get grandchild '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)))) - (setq - imenu-index - (reverse imenu-index)) - - (message "imenu-index:\n%S\n" imenu-index) - - (should - (equal - imenu-index - '(("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))))) - )))) - - ) - - (message "\n-- Ran tests for parser translation. --")) - (defun phps-mode-test-parser () "Run test for lexer." (message "-- Running all tests for parser... --\n") - (phps-mode-test-parser-translate) (phps-mode-test-parser-parse) (message "\n-- Ran all tests for parser. --"))