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

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

[elpa] externals/phps-mode cc947a9 140/405: Added more tests for new ind


From: Stefan Monnier
Subject: [elpa] externals/phps-mode cc947a9 140/405: Added more tests for new indentation function
Date: Sat, 13 Jul 2019 10:00:00 -0400 (EDT)

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

    Added more tests for new indentation function
---
 phps-mode-functions.el      | 27 ++++++++++++++++++++---
 phps-mode-test-functions.el | 54 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index f5a6985..55501cd 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -114,7 +114,8 @@
                 (when (string= token "}")
                   (setq curly-bracket-level (1- curly-bracket-level)))
 
-                ;; TODO Keep track of inline control structures
+                ;; TODO Keep track of case and default special tokens
+
                 ;; Keep track of alternative control structure level
                 (when (or (equal token 'T_ENDIF)
                           (equal token 'T_ENDWHILE)
@@ -123,11 +124,31 @@
                           (equal token 'T_ENDSWITCH))
                   (setq alternative-control-structure-level (1- 
alternative-control-structure-level)))
 
+                (when (and after-special-control-structure
+                           (= after-special-control-structure 
round-bracket-level)
+                           (not (string= token ")"))
+                           (not (string= token "(")))
+
+                  ;; Is token not a curly bracket - because that is a ordinary 
control structure syntax
+                  (unless (string= token "{")
+
+                    ;; Is it the start of an alternative control structure?
+                    (if (string= token ":")
+                        (setq alternative-control-structure-level (1+ 
alternative-control-structure-level))
+                      (setq inline-control-structure-level (1+ 
inline-control-structure-level))
+                      (setq in-inline-control-structure t)))
+
+                  (setq after-special-control-structure nil))
+
+                ;; Did we reach a semicolon inside a inline block? Close the 
inline block
+                (when (and in-inline-control-structure
+                           (string= token ";"))
+                  (setq inline-control-structure-level (1- 
inline-control-structure-level))
+                  (setq in-inline-control-structure nil))
+
                 ;; Did we encounter a token that supports alternative and 
inline control structures?
                 (when (or (equal token 'T_IF)
                           (equal token 'T_WHILE)
-                          (equal token 'T_CASE)
-                             (equal token 'T_DEFAULT)
                           (equal token 'T_FOR)
                           (equal token 'T_FOREACH)
                           (equal token 'T_SWITCH)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 7a91214..b8a6f8c 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -76,6 +76,60 @@
    (goto-char 17)
    (should (equal '(0 1) (phps-mode-functions-get-current-line-indent))))
 
+  ;; Alternative control structures
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\n"
+   (goto-char 11)
+   (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\n"
+   (goto-char 22)
+   (should (equal '(1 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\n"
+   (goto-char 42)
+   (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\n"
+   (goto-char 55)
+   (should (equal '(1 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\n"
+   (goto-char 75)
+   (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
+
+  ;; Inline control structures
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true)\n    echo 'Something';\nelse:\n    echo 'Something 
else';\n"
+   (goto-char 23)
+   (should (equal '(1 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true)\n    echo 'Something';\nelse\n    echo 'Something 
else';\n"
+   (goto-char 42)
+   (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true)\n    echo 'Something';\nelse\n    echo 'Something 
else';\n"
+   (goto-char 55)
+   (should (equal '(1 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\n"
+   (goto-char 72)
+   (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
+
+  ;; TODO CASE, DEFAULT
+
+  ;; TODO NOWDOC, HEREDOC
+
+
   )
 
 ;; TODO Add unit tests for HEREDOC and NOWDOC regions as well



reply via email to

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