emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode f791cee 234/405: Started on unit tests for im


From: Stefan Monnier
Subject: [elpa] externals/phps-mode f791cee 234/405: Started on unit tests for imenu-index generation
Date: Sat, 13 Jul 2019 10:00:20 -0400 (EDT)

branch: externals/phps-mode
commit f791ceef1637061fb8c03eab7ca11f0059fc8a19
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Started on unit tests for imenu-index generation
---
 README.md                   |  6 +++---
 phps-mode-functions.el      | 14 +++++++++++++-
 phps-mode-test-functions.el | 12 +++++++++++-
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 591df05..31efe01 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ If you have emacs at a customized location prefix the 
commands with your path, i
 
 ### Lexer
 
-Token generation
+Semantic token generation.
 
 ``` bash
 make test-lexer
@@ -38,7 +38,7 @@ make test-lexer
 
 ### Parser
 
-Not ready yet.
+Semantic grammar. Not ready yet.
 
 ``` bash
 make test-parser
@@ -46,7 +46,7 @@ make test-parser
 
 ### Functions
 
-Indentations, imenu, semantic subsystem
+Indentations, imenu.
 
 ``` bash
 make test-functions
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 8e14b43..eba4714 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -618,12 +618,24 @@
     ;; (message "phps-mode-functions-after-change %s %s %s" start stop length)
     ))
 
+;; TODO Implement this
+(defun phps-mode-functions-imenu-create-index-function ()
+  "Create index for imenu."
+  (let ((index '()))
+
+    ;; TODO Iterate namespaces, classes and functions and add to index
+
+    index))
+
 (defun phps-mode-functions-init ()
   "PHP specific init-cleanup routines."
 
-  ;; indent-region will call this on each line of region
+  ;; NOTE Indent-region will call this on each line of region
   (set (make-local-variable 'indent-line-function) 
#'phps-mode-functions-indent-line)
 
+  ;; Support Imenu
+  (set (make-local-variable 'imenu-create-index-function) 
#'phps-mode-functions-imenu-create-index-function)
+
   (when (and (boundp 'phps-mode-use-psr-2)
              phps-mode-use-psr-2)
 
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 47da2bc..1de7fdf 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -583,6 +583,15 @@
 
   )
 
+(defun phps-mode-test-functions-imenu ()
+  "Test for imenu"
+  (phps-mode-test-with-buffer
+   "<?php\nfunction myFunctionA() {}\nfunction myFunctionB() {}\n"
+   "Imenu function-oriented file"
+   (should (equal (phps-mode-functions-imenu-create-index-function) 
'(("myFunctionA" . 16) ("myFunction B" . 42))))
+   )
+  )
+
 ;; TODO Add tests for all examples here: https://www.php-fig.org/psr/psr-2/
 
 (defun phps-mode-test-functions ()
@@ -596,7 +605,8 @@
   (phps-mode-test-functions-get-lines-indent-multi-line-assignments)
   (phps-mode-test-functions-get-lines-indent-switch-case)
   (phps-mode-test-functions-get-lines-indent)
-  (phps-mode-test-functions-indent-line))
+  (phps-mode-test-functions-indent-line)
+  (phps-mode-test-functions-imenu))
 
 (phps-mode-test-functions)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]