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

    Added all examples from PSR-2 as tests for indentation
---
 phps-mode-test-functions.el | 76 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 63 insertions(+), 13 deletions(-)

diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 62513e6..0d9ada1 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -230,20 +230,70 @@
    (message "Indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (1 
0)) (7 (2 0)) (8 (2 0)) (9 (2 0)) (10 (1 0)) (11 (2 0)) (12 (1 0)) (13 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
 
-  ;; TODO 4.5. abstract, final, and static
-  ;; TODO 4.6. Method and Function Calls : Example 1
-  ;; TODO 4.6. Method and Function Calls : Example 2
-  ;; TODO 5.1. if, elseif, else
-  ;; TODO 5.2. switch, case
-  ;; TODO 5.3. while, do while : Example 1
-  ;; TODO 5.3. while, do while : Example 2
-  ;; TODO 5.4. for
-  ;; TODO 5.5. foreach
-  ;; TODO 5.6. try, catch
-  ;; TODO 6. Closures : Example 1
-  ;; TODO 6. Closures : Example 2
-  ;; TODO 6. Closures : Example 3
+  (phps-mode-test-with-buffer
+   "<?php\nnamespace Vendor\Package;\n\nabstract class ClassName\n{\n    
protected static $foo;\n\n    abstract protected function zim();\n\n    final 
public static function bar()\n    {\n        // method body\n    }\n}"
+   "PSR-2 ; 4.5. abstract, final, and static"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (1 
0)) (7 (1 0)) (8 (1 0)) (9 (1 0)) (10 (1 0)) (11 (1 0)) (12 (2 0)) (13 (1 0)) 
(14 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nbar();\n$foo->bar($arg1);\nFoo::bar($arg2, $arg3);"
+   "PSR-2 : 4.6. Method and Function Calls : Example 1"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\n$foo->bar(\n    $longArgument,\n    $longerArgument,\n    
$muchLongerArgument\n);"
+   "PSR-2 : 4.6. Method and Function Calls : Example 2"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif ($expr1) {\n    // if body\n} elseif ($expr2) {\n    // elseif 
body\n} else {\n    // else body;\n}"
+   "PSR-2 : 5.1. if, elseif, else"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nswitch ($expr) {\n    case 0:\n        echo 'First case, with a 
break';\n        break;\n    case 1:\n        echo 'Second case, which falls 
through';\n        // no break\n    case 2:\n    case 3:\n    case 4:\n        
echo 'Third case, return instead of break';\n        return;\n    default:\n    
    echo 'Default case';\n        break;\n}"
+   "PSR-2 : 5.2. switch, case"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1 
0)) (7 (2 0)) (8 (2 0)) (9 (1 0)) (10 (1 0)) (11 (1 0)) (12 (2 0)) (13 (2 0)) 
(14 (1 0)) (15 (2 0)) (16 (2 0)) (17 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nwhile ($expr) {\n    // structure body\n}"
+   "PSR-2 : 5.3. while, do while : Example 1"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\ndo {\n    // structure body;\n} while ($expr);"
+   "PSR-2 : 5.3. while, do while : Example 2"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nfor ($i = 0; $i < 10; $i++) {\n    // for body\n}"
+   "PSR-2 : 5.4. for"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
   
+  (phps-mode-test-with-buffer
+   "<?php\nforeach ($iterable as $key => $value) {\n    // foreach body\n}"
+   "PSR-2 : 5.5. foreach"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\ntry {\n    // try body\n} catch (FirstExceptionType $e) {\n    // 
catch body\n} catch (OtherExceptionType $e) {\n    // catch body\n}"
+   "PSR-2 : 5.6. try, catch"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\n$closureWithArgs = function ($arg1, $arg2) {\n    // 
body\n};\n\n$closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, 
$var2) {\n    // body\n};"
+   "PSR-2 : 6. Closures : Example 1"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (0 0)) (6 (0 
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\n$longArgs_noVars = function (\n    $longArgument,\n    
$longerArgument,\n    $muchLongerArgument\n) {\n    // 
body\n};\n\n$noArgs_longVars = function () use (\n    $longVar1,\n    
$longerVar2,\n    $muchLongerVar3\n) {\n    // body\n};\n\n$longArgs_longVars = 
function (\n    $longArgument,\n    $longerArgument,\n    
$muchLongerArgument\n) use (\n    $longVar1,\n    $longerVar2,\n    
$muchLongerVar3\n) {\n    // body\n};\n\n$longArgs_shortVars = function (\n    
$longArgument,\n [...]
+   "PSR-2 : 6. Closures : Example 2"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (0 
0)) (7 (1 0)) (8 (0 0)) (9 (0 0)) (10 (0 0)) (11 (1 0)) (12 (1 0)) (13 (1 0)) 
(14 (0 0)) (15 (1 0)) (16 (0 0)) (17 (0 0)) (18 (0 0)) (19 (1 0)) (20 (1 0)) 
(21 (1 0)) (22 (0 0)) (23 (1 0)) (24 (1 0)) (25 (1 0)) (26 (0 0)) (27 (1 0)) 
(28 (0 0)) (29 (0 0)) (30 (0 0)) (31 (1 0)) (32 (1 0)) (33 (1 0)) (34 (0 0)) 
(35 (1 0)) (36 (0 0)) (37 (0 0)) (38 (0 0)) (39 (1 0)) (40 (1 0)) (41 (1 0)) 
(42 (0 0)) (43 (1 0)) (44 (0 0 [...]
+
+  (phps-mode-test-with-buffer
+   "<?php\n$foo->bar(\n    $arg1,\n    function ($arg2) use ($var1) {\n        
// body\n    },\n    $arg3\n);"
+   "PSR-2 : 6. Closures : Example 3"
+   (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-hash-to-list 
(phps-mode-functions-get-lines-indent)))))  
 
   )
 

Reply via email to