branch: externals/phps-mode
commit 8947e6ea95e45025f71997176d055df0d2a48f84
Author: Christian Johansson <christ...@cvj.se>
Commit: Christian Johansson <christ...@cvj.se>

    Conceptual work on indentation-calculation for multi-line assignment
---
 docs/indentation-algorithm.md | 11 ++++++-
 phps-mode-test-functions.el   | 69 +++++++++++++++++++++++--------------------
 2 files changed, 47 insertions(+), 33 deletions(-)

diff --git a/docs/indentation-algorithm.md b/docs/indentation-algorithm.md
index fd8a877..e8e79ea 100644
--- a/docs/indentation-algorithm.md
+++ b/docs/indentation-algorithm.md
@@ -88,7 +88,16 @@ endif;                                       // #decrease 
pop (0 1) indent: 0, #save indent: 0
 
 ```php
 <?php                          // #save indent: 0
+$var = array(          // #save indent: 0, #increase push (0 2) indent: 1
+    'def'                      // #save indent: 1
+);                                     // #decrease pop (0 2) indent: 0, #save 
indent: 0
+```
+
+## Multi-line assignments 2
+
+```php
+<?php                          // #save indent: 0
 $var = 'abc'           // #save indent: 0, #increase push (0 1) indent: 1
     . 'def'            // #save indent: 1
-    . 'ghj';           // #decrease pop (0 1) indent: 0, #save indent: 0 <!-- 
ERROR -->
+    . 'ghj';           // #decrease pop (0 1) indent: 0, #save indent: 0 /* 
ERROR */
 ```
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index da5bd7e..077598b 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -58,36 +58,12 @@
    (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\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)
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (1 
0)) (7 (1 0)) (8 (1 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$variable = true;\n"
-   "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)
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (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 
heredoc syntax.\nEOD;\n"
-   "Multi-line HEREDOC string in assignment"
-   ;; (message "Tokens: %s" phps-mode-lexer-tokens)
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (0 
0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
-
-  (phps-mode-test-with-buffer
    "<?php\n$var = \"A line\nmore text here\nlast line here\";"
    "Multi-line double-quoted string"
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
@@ -99,8 +75,6 @@
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
-  ;; NOTE Maybe concatenated strings spanning multiple lines outside 
assignments should have indentation?
-  
   (phps-mode-test-with-buffer
    "<?php\necho \"A line\" .\n    \"more text here\" .\n    \"last line 
here\";"
    "Concatenated double-quoted-string spanning multiple-lines"
@@ -114,12 +88,6 @@
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   (phps-mode-test-with-buffer
-   "<?php\n$var = 'A line' .\n    'more text here' .\n    'last line here';"
-   "Concatenated single-quoted-string multiple-lines in assignment"
-   ;; (message "Tokens: %s" phps-mode-lexer-tokens)
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
-
-  (phps-mode-test-with-buffer
    "<?php\necho <<<EOD\nExample of string\nspanning multiple lines\nusing 
heredoc syntax.\nEOD;\n"
    "Multi-line HEREDOC string outside assignment"
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
@@ -144,6 +112,42 @@
 
   )
 
+(defun phps-mode-test-functions-get-lines-indent-multi-line-assignments ()
+  "Test for multi-line assignments."
+
+  (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$variable = array(\n    'random4');\n$variable = true;\n"
+   "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$var = 'A line' .\n    'more text here' .\n    'last line here';"
+   "Concatenated single-quoted-string multiple-lines in assignment"
+   ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 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 
heredoc syntax.\nEOD;\n"
+   "Multi-line HEREDOC string in assignment"
+   ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (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)
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (1 
0)) (7 (1 0)) (8 (1 0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+
+  )
+
 (defun phps-mode-test-functions-get-lines-indent-inline-if ()
   "Test for inline if indentations."
 
@@ -531,6 +535,7 @@
   (phps-mode-test-function-get-lines-indent-classes)
   (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-multi-line-assignments)
   (phps-mode-test-functions-get-lines-indent)
   (phps-mode-test-functions-get-lines-indent-switch-case)
   (phps-mode-test-functions-indent-line))

Reply via email to