[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
- [elpa] externals/phps-mode 3776841 138/405: Added new support for tracking doc-comment, HEREDOC and NOWDOC indentation, (continued)
- [elpa] externals/phps-mode 3776841 138/405: Added new support for tracking doc-comment, HEREDOC and NOWDOC indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 780d065 125/405: Code styling updates, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 314dba1 135/405: Improved articulation of what information get-current-line-data should return, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f0523b7 137/405: More work on new function to calculate indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 16d8056 144/405: Foundation for new indentation tests completed, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d380cd4 129/405: Updated readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3f08b86 128/405: Updated tracking of alternative control structures, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 52c502c 139/405: Improved logic for doc-comment tracking, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1472273 136/405: Begun working on new approach to indentation calculation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9792f70 133/405: Cleaning up code gather point meta information, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode cc947a9 140/405: Added more tests for new indentation function,
Stefan Monnier <=
- [elpa] externals/phps-mode d3e00f2 141/405: Starting on new function for indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c68c7a0 131/405: Fixed issue were first-token-on-line was nil, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c4ee0c3 132/405: Added more failing tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0b3ced4 145/405: First test for new indentation function passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 96588b5 142/405: More work on new indentation calculation functions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9d6af11 157/405: More work on indentations, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e249124 152/405: Prevent negative indent, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 4a27c44 147/405: Added support for naming unit tests to better find failures, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b852f5f 160/405: All tests for indentation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dfb0427 151/405: Added unit test for round and square bracket expressions, Stefan Monnier, 2019/07/13