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

[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)



reply via email to

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