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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 00d3568 290/405: Added indentation examples f


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 00d3568 290/405: Added indentation examples from official PSR-2
Date: Sat, 13 Jul 2019 10:00:34 -0400 (EDT)

branch: externals/phps-mode
commit 00d356816ba166e84f0d870585c6bb8c801e87cd
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Added indentation examples from official PSR-2
---
 phps-mode-test-functions.el | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index c0c63be..d176cf3 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -161,6 +161,10 @@
    "Do while loop with multi-line condition"
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
 
+
+  ;; TODO Fix below
+
+  
   (phps-mode-test-with-buffer
    "<?php\n$myVar = 'blaha'\n    . 'ijeije' . __(\n        'okeoke'\n    )\n   
 . 'okeoke';\n?>"
    "Concatenated assignment string with function call"
@@ -171,8 +175,34 @@
    "Concatenated echo string with function call"
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (1 
0)) (7 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
+  )
+
+(defun phps-mode-test-functions-get-lines-indent-psr-2 ()
+  "Test PSR-2 examples from: https://www.php-fig.org/psr/psr-2/";
+
+  (phps-mode-test-with-buffer
+   "<?php\nnamespace Vendor\\Package;\n\nuse FooInterface;\nuse BarClass as 
Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\nclass Foo extends Bar 
implements FooInterface\n{\n    public function sampleMethod($a, $b = null)\n   
 {\n        if ($a === $b) {\n            bar();\n        } elseif ($a > $b) 
{\n            $foo->bar($arg1);\n        } else {\n            
BazClass::bar($arg2, $arg3);\n        }\n    }\n\n    final public static 
function bar()\n    {\n        // method body\n   [...]
+   "PSR-2 : 1.1. Example"
+   ;; (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 (0 
0)) (7 (0 0)) (8 (0 0)) (9 (0 0)) (10 (1 0)) (11 (1 0)) (12 (2 0)) (13 (3 0)) 
(14 (2 0)) (15 (3 0)) (16 (2 0)) (17 (3 0)) (18 (2 0)) (19 (1 0)) (20 (1 0)) 
(21 (1 0)) (22 (1 0)) (23 (2 0)) (24 (1 0)) (25 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nnamespace Vendor\\Package;\n\nuse FooClass;\nuse BarClass as 
Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\n// ... additional PHP code 
..."
+   "PSR-2 : 3. Namespace and Use Declarations"
+   ;; (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 (0 
0)) (7 (0 0)) (8 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
-  ;; TODO Add tests for all examples here: https://www.php-fig.org/psr/psr-2/
+  (phps-mode-test-with-buffer
+   "<?php\nnamespace Vendor\\Package;\n\nuse FooClass;\nuse BarClass as 
Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\nclass ClassName extends 
ParentClass implements \\ArrayAccess, \\Countable\n{\n    // constants, 
properties, methods\n}"
+   "PSR-2 : 4.1. Extends and Implements : Example 1"
+   ;; (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 (0 
0)) (7 (0 0)) (8 (0 0)) (9 (0 0)) (10 (1 0)) (11 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nnamespace Vendor\\Package;\n\nuse FooClass;\nuse BarClass as 
Bar;\nuse OtherVendor\\OtherPackage\\BazClass;\n\nclass ClassName extends 
ParentClass implements\n    \\ArrayAccess,\n    \\Countable,\n    
\\Serializable\n{\n    // constants, properties, methods\n}"
+   "PSR-2 : 4.1. Extends and Implements : Example 2"
+   ;; (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 (0 
0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (1 0)) (11 (1 0)) (12 (0 0)) (13 (1 0)) 
(14 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   )
 
@@ -358,13 +388,13 @@
   (phps-mode-test-with-buffer
    "<?php\nif (true) {\n    switch ($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    endswitch;\n  
  sprintf(__(\n        'Error: %s',\n        $error\n    ));\n}\n"
    "Alternative switch, case, default with exception after it"
-   (message "Indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
+   ;; (message "Indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (3 0)) (6 (3 
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (3 0)) (11 (1 0)) (12 (1 0)) (13 (2 0)) 
(14 (2 0)) (15 (1 0)) (16 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   (phps-mode-test-with-buffer
    "<?php\nif (true) {\n    switch ($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    
sprintf(__(\n        'Error: %s',\n        $error\n    ));\n}\n"
    "Curly switch, case, default with exception after it"
-   (message "Indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
+   ;; (message "Indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (3 0)) (6 (3 
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (3 0)) (11 (1 0)) (12 (1 0)) (13 (2 0)) 
(14 (2 0)) (15 (1 0)) (16 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   )
@@ -648,13 +678,14 @@
 (defun phps-mode-test-functions ()
   "Run test for functions."
   ;; (setq debug-on-error t)
-  (setq phps-mode-functions-verbose t)
+  ;; (setq phps-mode-functions-verbose t)
   (phps-mode-test-functions-get-lines-lindent-if)
   (phps-mode-test-functions-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-switch-case)
+  (phps-mode-test-functions-get-lines-indent-psr-2)
   (phps-mode-test-functions-get-lines-indent)
   (phps-mode-test-functions-indent-line)
   (phps-mode-test-functions-imenu))



reply via email to

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