[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 7a538ac 200/405: Tests for alternative contro
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 7a538ac 200/405: Tests for alternative control structures passes |
Date: |
Sat, 13 Jul 2019 10:00:12 -0400 (EDT) |
branch: externals/phps-mode
commit 7a538ac8ee4310e5dbd6871ebb97b4e77356389b
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Tests for alternative control structures passes
---
docs/indentation-algorithm.md | 12 ++++++------
phps-mode-functions.el | 6 +++---
phps-mode-test-functions.el | 26 +++++++++++++++++++-------
3 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/docs/indentation-algorithm.md b/docs/indentation-algorithm.md
index e967e27..df58b26 100644
--- a/docs/indentation-algorithm.md
+++ b/docs/indentation-algorithm.md
@@ -70,12 +70,12 @@ else // #save indent: 0
## Alternative control structure for if-else 2
```php
-if (true &&
- true
-):
- echo true;
-elseif (true
- || false):
+if (true && #save indent: 0, #increase push (0 1) indent: 1
+ true #save indent: 1
+): #decrease pop (0 1) indent: 0,
#save indent: 0, #increase push (0 1) indent: 1
+ echo true; #save indent 1
+elseif (true #decrease pop (0 1) indent: 0, #save indent: 0,
#increase push (0 1) indent: 1
+ || false): #decrease pop (0 1) indent: 0, #save indent: 0,
#increase push (0 1) indent: 1
echo 'another';
else:
echo false;
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 61b795b..cfcea9e 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -238,7 +238,7 @@
(progn
(setq line-contained-nesting-increase t)
(when
after-special-control-structure-first-on-line
- (setq first-token-is-nesting-decrease t)))
+ (setq alternative-control-structure-level
(1+ alternative-control-structure-level))))
(when (equal
after-special-control-structure-token 'T_SWITCH)
(setq alternative-control-structure-level (1+
alternative-control-structure-level))
@@ -291,8 +291,8 @@
(equal token 'T_DEFAULT))
nesting-stack
(string= (car (cdr (cdr (car nesting-stack))))
":"))
- (setq column-level (1- column-level))
- (pop nesting-stack))
+
+ (setq alternative-control-structure-level (1-
alternative-control-structure-level)))
)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 62f8146..da5bd7e 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -58,11 +58,6 @@
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (2 0)) (6 (1
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
- "<?php\nswitch ($condition) {\n case true:\n echo 'here';\n
echo 'here 2';\n case false:\n echo 'here 4';\n default:\n
echo 'here 3';\n}\n"
- "Switch, case, default"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1
0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
-
- (phps-mode-test-with-buffer
"<?php\n$var =\n 500 .\n \"200\" .\n 100.0 .\n '200' .\n
$this->getTail()\n ->getBottom();"
"Multi-line assignments"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
@@ -70,11 +65,17 @@
(phps-mode-test-with-buffer
"<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
- "Array assignment on only two lines"
+ "Array assignment on two lines"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) )
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
+ "<?php\n$variable = array(\n 'random4'\n);\n$variable = true;\n"
+ "Array assignment on three lines"
+ ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+ (phps-mode-test-with-buffer
"<?php\n$str = <<<'EOD'\nExample of string\nspanning multiple lines\nusing
nowdoc syntax.\nEOD;\n"
"Multi-line NOWDOC string"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
@@ -179,7 +180,7 @@
(phps-mode-test-with-buffer
"<?php\nif (true):\n echo 'Something';\nelseif (true\n && true):\n
echo 'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
"Alternative control structures with multi-line elseif 2"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (1
0)) (7 (0 0)) (8 (1 0)) (9 (1 0)) (10 (0 0)) (11 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (0 0)) (6 (1
0)) (7 (0 0)) (8 (1 0)) (9 (1 0)) (10 (0 0)) (11 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
)
@@ -274,6 +275,16 @@
)
+(defun phps-mode-test-functions-get-lines-indent-switch-case ()
+ "Test for switch-case indentation."
+
+ (phps-mode-test-with-buffer
+ "<?php\nswitch ($condition) {\n case true:\n echo 'here';\n
echo 'here 2';\n case false:\n echo 'here 4';\n default:\n
echo 'here 3';\n}\n"
+ "Switch, case, default"
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1
0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (0 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+)
+
(defun phps-mode-test-functions-indent-line ()
"Test for indentation."
@@ -521,6 +532,7 @@
(phps-mode-test-functions-get-lines-indent-inline-if)
(phps-mode-test-functions-get-lines-indent-alternative-if)
(phps-mode-test-functions-get-lines-indent)
+ (phps-mode-test-functions-get-lines-indent-switch-case)
(phps-mode-test-functions-indent-line))
(phps-mode-test-functions)
- [elpa] externals/phps-mode ce2d4bd 148/405: New indentation calculation function passes alternative, (continued)
- [elpa] externals/phps-mode ce2d4bd 148/405: New indentation calculation function passes alternative, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3718931 156/405: Basic tests for indentation calculation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 13e9148 159/405: Indentation unit test for assignment is passing, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b5c64c1 162/405: Added failing tests for HEREDOC and NOWDOC assignments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f283e4b 173/405: Added new failing unit tests for multiple-lines IF and single line class declaration, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 59474ea 180/405: Improved debugging messages, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9659ab4 174/405: Added failing test for doc-comments are namespace and class, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c5d8ec6 168/405: Indentation calculation for class implement working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f93765d 184/405: Improved code structure of indentation were nesting start and end equals, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2af8abd 206/405: Made TODO notes in algorithm, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a538ac 200/405: Tests for alternative control structures passes,
Stefan Monnier <=
- [elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assignment lines on only one line, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d18fddc 175/405: Fixed bug with indentation for indented doc-comments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 00c0ab9 194/405: Nesting-stack algorithm handles class declaration indents, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8a76039 189/405: Started implementing nesting-stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode cf7dc07 210/405: Preparations for multi-line quoted indentation tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 208a788 208/405: Re-organized indent tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c678fc1 209/405: New algorithm handles HEREDOC indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b6cf3a4 191/405: Started on new algorithm for indentation calculation based on stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b2338cd 223/405: All tests for indentation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a4b98e 215/405: More work on algorithm description, Stefan Monnier, 2019/07/13