branch: externals/phps-mode
commit 60c74316e8909116eca4023eaf01627310d8e113
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Unit tests for gather data about inline and alternative control structure
syntax passes
---
phps-mode-functions.el | 26 +++++++++++++++++---------
phps-mode-test-functions.el | 14 +++++++-------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index d23d06d..f6175d5 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -313,12 +313,25 @@
(")" (setq end-round-bracket-level (-
end-round-bracket-level 1)))
(_))
+ ;; Do we encounter first token on line?
+ (when (and (not first-token-on-line)
+ (>= token-start line-beginning)
+ (<= token-start line-end))
+ (setq first-token-on-line end-token-number))
+
+
;; Did we encounter end of alternative control structure?
(when (or (equal token 'T_ENDIF)
(equal token 'T_ENDWHILE)
(equal token 'T_ENDFOR)
(equal token 'T_ENDFOREACH)
(equal token 'T_ENDSWITCH))
+
+ ;; If this was the first token on line decrement start
+ (when (and first-token-on-line
+ (= first-token-on-line end-token-number))
+ (setq start-alternative-control-structure-level (-
start-alternative-control-structure-level 1)))
+
(setq end-alternative-control-structure-level (-
end-alternative-control-structure-level 1)))
;; Reduce inline control structure level when we encounter a
semi-colon after it's opening
@@ -329,12 +342,6 @@
)
- ;; Do we encounter first token on line?
- (when (and (not first-token-on-line)
- (>= token-start line-beginning)
- (<= token-start line-end))
- (setq first-token-on-line end-token-number))
-
;; Keep track of general round brace level
(when (string= token "(")
(setq round-brace-level (+ round-brace-level 1)))
@@ -351,10 +358,10 @@
;; Is token not a curly bracket - because that is a ordinary
control structure syntax
(when (not (string= token "{"))
- (message "After special control structure %s in buffer: %s
tokens: %s token-start: %s" token (buffer-substring-no-properties (point-min)
(point-max)) phps-mode-lexer-tokens token-start)
+ ;; (message "After special control structure %s in buffer:
%s tokens: %s token-start: %s" token (buffer-substring-no-properties
(point-min) (point-max)) phps-mode-lexer-tokens token-start)
(if (string= token ":")
(progn
- (message "Was colon")
+ ;; (message "Was colon")
;; Is token at or before line beginning?
(when (<= token-end line-beginning)
@@ -375,7 +382,8 @@
(setq end-inline-control-structure-level (+
end-inline-control-structure-level 1))
(setq end-expecting-semi-colon t))
- (message "Was not colon")))
+ ;; (message "Was not colon")
+ ))
(setq after-special-control-structure nil))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 3902c5e..98101be 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -360,22 +360,22 @@
(phps-mode-test-with-buffer
"<?php\nif ($myCondition):\n echo 'was here';\nendif;\necho 'was here
2';\n"
(goto-char 41)
- (should (equal (list (list t 0 0 0 0 1 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
+ (should (equal (list (list t 0 0 0 0 1 5 nil) (list t 0 0 0 0 1 8 nil))
(phps-mode-functions-get-point-data))))
(phps-mode-test-with-buffer
- "<?php\nif ($myCondition):\n echo 'was here';\nendif;\necho 'was here
2';\n"
+ "<?php\nif ($myCondition):\n echo 'was here';\nendif;\necho 'was here
3';\n"
(goto-char 52)
- (should (equal (list (list t 0 0 0 0 0 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
+ (should (equal (list (list t 0 0 0 0 0 8 nil) (list t 0 0 0 0 0 10 nil))
(phps-mode-functions-get-point-data))))
(phps-mode-test-with-buffer
- "<?php\nif ($myCondition): echo 'was here';\nendif;\necho 'was here
2';\n"
+ "<?php\nif ($myCondition): echo 'was here';\nendif;\necho 'was here
4';\n"
(goto-char 32)
- (should (equal (list (list t 0 0 0 1 0 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
+ (should (equal (list (list t 0 0 0 0 0 0 nil) (list t 0 0 0 0 1 8 nil))
(phps-mode-functions-get-point-data))))
(phps-mode-test-with-buffer
- "<?php\nif ($myCondition): echo 'was here'; endif; echo 'was here 2';\n"
+ "<?php\nif ($myCondition): echo 'was here'; endif; echo 'was here 5';\n"
(goto-char 35)
- (should (equal (list (list t 0 0 0 0 1 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
+ (should (equal (list (list t 0 0 0 0 0 0 nil) (list t 0 0 0 0 0 13 nil))
(phps-mode-functions-get-point-data))))
)