[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode ee211dac6a 084/212: Started on indentation te
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode ee211dac6a 084/212: Started on indentation tests |
Date: |
Wed, 26 Jan 2022 01:50:58 -0500 (EST) |
branch: externals/phps-mode
commit ee211dac6a36d2b18114a6023970fab325a90890
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Started on indentation tests
---
Makefile | 6 +-
phps-mode-indent.el | 198 ++++++++++
test/phps-mode-test-indent.el | 817 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 1020 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index f425653679..f5e8f3d390 100644
--- a/Makefile
+++ b/Makefile
@@ -20,12 +20,16 @@ compile:
find . -name "*.el" -exec $(EMACS_CMD) -f batch-byte-compile {} \;
.PHONY: tests
-tests: test-integration test-lexer test-lex-analyzer test-parser
test-syntax-table test-ast
+tests: test-integration test-lexer test-lex-analyzer test-parser
test-syntax-table test-ast test-indent
.PHONY: test-ast
test-ast:
$(EMACS_CMD) -l test/phps-mode-test-ast.el
+.PHONY: test-indent
+test-indent:
+ $(EMACS_CMD) -l test/phps-mode-test-indent.el
+
.PHONY: test-integration
test-integration:
$(EMACS_CMD) -l test/phps-mode-test-integration.el
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
new file mode 100644
index 0000000000..4e85d52a40
--- /dev/null
+++ b/phps-mode-indent.el
@@ -0,0 +1,198 @@
+;;; phps-mode-indent.el -- Indentation for phps-mode -*- lexical-binding: t -*-
+
+;; Copyright (C) 2018-2021 Free Software Foundation, Inc.
+
+
+
+;;; Commentary:
+
+
+;;; Code:
+
+
+(defun phps-mode-indent-line (&optional point)
+ "Apply alternative indentation at POINT here."
+ (unless point
+ (setq point (point)))
+ (let ((new-indentation 0)
+ (point-at-end-of-line (equal point (line-end-position))))
+ (save-excursion
+ (let ((line-number (line-number-at-pos point))
+ (move-length 0)
+ (line-is-empty t)
+ line-beginning-position
+ line-end-position
+ line-string
+ current-line-string)
+ (goto-char point)
+ (setq
+ current-line-string
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))
+ )
+ (if (> line-number 1)
+ (progn
+ (while (and
+ (> line-number 0)
+ line-is-empty)
+ (forward-line -1)
+ (setq line-number (1- line-number))
+ (beginning-of-line)
+ (setq line-beginning-position (line-beginning-position))
+ (setq line-end-position (line-end-position))
+ (setq
+ line-string
+ (buffer-substring-no-properties line-beginning-position
line-end-position))
+ (setq line-is-empty (string-match-p "^[ \t\f\r\n]*$"
line-string))
+ (setq move-length (1+ move-length)))
+
+ (unless line-is-empty
+ (let* ((old-indentation (current-indentation))
+ (current-line-starts-with-closing-bracket
(phps-mode-indent--string-starts-with-closing-bracket-p current-line-string))
+ (line-starts-with-closing-bracket
(phps-mode-indent--string-starts-with-closing-bracket-p line-string))
+ (line-starts-with-opening-doc-comment
(phps-mode-indent--string-starts-with-opening-doc-comment-p line-string))
+ (line-ends-with-assignment
(phps-mode-indent--string-ends-with-assignment-p line-string))
+ (line-ends-with-opening-bracket
(phps-mode-indent--string-ends-with-opening-bracket-p line-string))
+ (line-ends-with-terminus
(phps-mode-indent--string-ends-with-terminus-p line-string))
+ (bracket-level
(phps-mode-indent--get-string-brackets-count line-string)))
+ (setq new-indentation old-indentation)
+ (goto-char point)
+
+ (when (> bracket-level 0)
+ (if (< bracket-level tab-width)
+ (setq new-indentation (+ new-indentation 1))
+ (setq new-indentation (+ new-indentation tab-width))))
+
+ (when (= bracket-level -1)
+ (setq new-indentation (1- new-indentation)))
+
+ (when (and (= bracket-level 0)
+ line-starts-with-closing-bracket)
+ (setq new-indentation (+ new-indentation tab-width)))
+
+ (when current-line-starts-with-closing-bracket
+ (setq new-indentation (- new-indentation tab-width)))
+
+ (when line-starts-with-opening-doc-comment
+ (setq new-indentation (+ new-indentation 1)))
+
+ (when (and
+ line-ends-with-assignment
+ (<= bracket-level 0))
+ (setq new-indentation (+ new-indentation tab-width)))
+
+ (when (and
+ line-ends-with-opening-bracket
+ (< bracket-level 0))
+ (setq new-indentation (+ new-indentation tab-width)))
+
+ (when line-ends-with-terminus
+ ;; Back-trace buffer from previous line
+ ;; Determine if semi-colon ended an assignment or
bracket-less command or not
+ (forward-line (* -1 move-length))
+ (end-of-line)
+ (forward-char -1)
+ (let ((not-found t)
+ (is-assignment nil)
+ (parenthesis-level 0)
+ (is-bracket-less-command nil))
+ (while (and
+ not-found
+ (search-backward-regexp
"\\(;\\|{\\|(\\|)\\|=\\|echo[\t ]+\\|print[\t ]+\\)" nil t))
+ (let ((match (buffer-substring-no-properties
(match-beginning 0) (match-end 0))))
+ (when (string= match ")")
+ (setq parenthesis-level (1- parenthesis-level)))
+ (when (= parenthesis-level 0)
+ (setq is-assignment (string= match "="))
+ (setq is-bracket-less-command
+ (string-match-p
+ "\\(echo[\t ]+\\|print[\t ]+\\)"
+ match))
+ (setq not-found nil))
+
+ (when (string= match "(")
+ (setq parenthesis-level (1+ parenthesis-level)))))
+ ;; If it ended an assignment on a previous line,
decrease indentation
+ (when
+ (and
+ (or
+ (and
+ is-assignment
+ (> bracket-level -1))
+ is-bracket-less-command)
+ (not (= line-number (line-number-at-pos))))
+ ;; NOTE stuff like $var = array(\n 4\n);\n
+ ;; will end assignment but also decrease bracket-level
+ (setq new-indentation (- new-indentation tab-width))))
+
+ (goto-char point))
+
+ ;; Decrease indentation if current line decreases in bracket
level
+ (when (< new-indentation 0)
+ (setq new-indentation 0))
+
+ (indent-line-to new-indentation))))
+ (indent-line-to 0))))
+ ;; Only move to end of line if point is the current point and is at end of
line
+ (when (equal point (point))
+ (if point-at-end-of-line
+ (end-of-line)
+ (back-to-indentation)))
+ new-indentation))
+
+(defun phps-mode-indent--get-string-brackets-count (string)
+ "Get bracket count for STRING."
+ (let ((bracket-level 0)
+ (start 0)
+ (line-is-empty
+ (string-match-p "^[ \t\f\r\n]*$" string)))
+ (unless line-is-empty
+ (while (string-match
+ "\\([\]{}()[]\\|<[a-zA-Z]+\\|</[a-zA-Z]+\\|/>\\|^[\t
]/\\*\\*\\|^[\t\\* ]*\\*/\\)"
+ string
+ start)
+ (setq start (match-end 0))
+ (let ((bracket (substring string (match-beginning 0) (match-end 0))))
+ (cond
+ ((or
+ (string= bracket "{")
+ (string= bracket "[")
+ (string= bracket "(")
+ (string= bracket "<")
+ (string-match "<[a-zA-Z]+" bracket))
+ (setq bracket-level (+ bracket-level tab-width)))
+ ((string-match "^[\t\\* ]*\\*/" bracket )
+ (setq bracket-level (- bracket-level 1)))
+ ((or
+ (string-match "^/\\*\\*" bracket)
+ (string-match "^[\t ]*\\*" bracket))
+ (setq bracket-level (+ bracket-level 1)))
+ (t
+ (setq bracket-level (- bracket-level tab-width)))))))
+ bracket-level))
+
+(defun phps-mode-indent--string-starts-with-closing-bracket-p (string)
+ "Get bracket count for STRING."
+ (string-match-p "^[\t ]*\\([\]})[]\\|</[a-zA-Z]+\\|/>\\)" string))
+
+(defun phps-mode-indent--string-starts-with-opening-doc-comment-p (string)
+ "Does STRING start with opening doc comment?"
+ (string-match-p "^[\t ]*/\\*\\*" string))
+
+(defun phps-mode-indent--string-ends-with-opening-bracket-p (string)
+ "Get bracket count for STRING."
+ (string-match-p "\\([\[{(]\\|<[a-zA-Z]+\\)[\t ]*$" string))
+
+(defun phps-mode-indent--string-ends-with-assignment-p (string)
+ "Get bracket count for STRING."
+ (string-match-p "=>?[\t ]*$" string))
+
+(defun phps-mode-indent--string-ends-with-terminus-p (string)
+ "Get bracket count for STRING."
+ (string-match-p "\\(;\\|,\\)[\t ]*$" string))
+
+
+(provide 'phps-mode-indent)
+
+;;; phps-mode-indent.el ends here
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
new file mode 100644
index 0000000000..f5ee27e694
--- /dev/null
+++ b/test/phps-mode-test-indent.el
@@ -0,0 +1,817 @@
+;;; phps-mode-test-indent.el --- Tests for indentation -*- lexical-binding: t
-*-
+
+;; Copyright (C) 2018-2021 Free Software Foundation, Inc.
+
+
+;;; Commentary:
+
+
+;; Run from terminal make test-indent
+
+
+;;; Code:
+
+
+(require 'ert)
+(require 'phps-mode)
+(require 'phps-mode-indent)
+(require 'phps-mode-test)
+
+(defun phps-mode-test-indent--indent-whole-buffer ()
+ "Use alternative indentation of every line of buffer."
+ (goto-char (point-min))
+ (phps-mode-indent-line)
+ (while (search-forward "\n" nil t nil)
+ (phps-mode-indent-line)))
+
+(defun phps-mode-test-indent--should-equal (string name)
+ "Test indent of whole buffer containing STRING with NAME."
+ (phps-mode-test--with-buffer
+ string
+ name
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (message "Indented buffer:\n%S" buffer-contents)
+ (should (equal
+ buffer-contents
+ string)))))
+
+(defun phps-mode-test-indent--get-lines-indent ()
+ "Test indent function."
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/**\n * Bla\n */"
+ "DOC-COMMENT")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nmyFunction(array(\n 23,\n [\n 25\n ]\n )\n);"
+ "Round and square bracket expressions")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nvar_dump(array(<<<EOD\nfoobar!\nEOD\n));\n?>"
+ "HEREDOC in arguments example")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$str = <<<'EOD'\nExample of string\nspanning multiple lines\nusing
nowdoc syntax.\nEOD;\n"
+ "Multi-line NOWDOC string")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = \"A line\nmore text here\nlast line here\";"
+ "Multi-line double-quoted string")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = 'A line\nmore text here\nlast line here';"
+ "Multi-line single-quoted string")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho \"A line\" .\n \"more text here\" .\n \"last line
here\";"
+ "Concatenated double-quoted-string spanning multiple-lines")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho myFunction(\"A line\" .\n \"more text here\" .\n \"last
line here\");"
+ "Concatenated double-quoted-string spanning multiple-lines inside function")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho \"A line\"\n . \"more text here\"\n . \"last line
here\";"
+ "Concatenated double-quoted-string spanning multiple-lines 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho myFunction(\"A line\" .\n \"more text here\" .\n \"last
line here\");"
+ "Concatenated double-quoted-string spanning multiple-lines inside function
2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho 'A line' .\n 'more text here' .\n 'last line here';"
+ "Concatenated single-quoted-string spanning multiple-lines")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho myFunction('A line' .\n 'more text here' .\n 'last line
here');"
+ "Concatenated single-quoted-string spanning multiple-lines inside function")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho 'A line'\n . 'more text here'\n . 'last line here';"
+ "Concatenated single-quoted-string spanning multiple-lines 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho myFunction('A line'\n . 'more text here'\n . 'last line
here');"
+ "Concatenated single-quoted-string spanning multiple-lines inside function
2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho <<<EOD\nExample of string\nspanning multiple lines\nusing
heredoc syntax.\nEOD;\n"
+ "Multi-line HEREDOC string outside assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/**\n * @var string\n */\necho 'was here';\n"
+ "Statement after doc-comment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/** @define _SYSTEM_START_TIME_ Startup time for system
*/\ndefine('_SYSTEM_START_TIME_', microtime(true));\necho 'statement';\n"
+ "Statement after a define() with a doc-comment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nfunction myFunction($parameters = null)\n{\n echo
'statement';\n}\n"
+ "Statement after one-lined function declaration with optional argument")
+
+ (phps-mode-test-indent--should-equal
+ "<?php if (true) { ?>\n <?php echo 'here'; ?>\n<?php } ?>"
+ "Regular if-expression but inside scripting tags")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\ndo {\n echo 'true';\n} while ($number > 0\n && $letter >
0\n);"
+ "Do while loop with multi-line condition")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\ndo {\n echo 'true';\n} while ($number > 0\n && $letter >
0\n);"
+ "Do while loop with multi-line condition")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$myVar = 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n ) .
'okeoke';\n?>"
+ "Concatenated assignment string with function call")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$myVar = 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n )\n
. 'okeoke';\n?>"
+ "Concatenated assignment string with function call")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n ) .
'okeoke';\n?>"
+ "Concatenated echo string with function call")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\necho 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n )\n .
'okeoke';\n?>"
+ "Concatenated echo string with function call")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$options = [\n 0 => [\n 'label' => __('No'),\n
'value' => 0,\n ],\n];"
+ "Assignment with square bracketed array")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$options = array(\n 'blaha' .\n 'blaha',\n 123,\n
'blaha'\n);"
+ "Assignment with square bracketed array")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nreturn $variable\n && $variable;"
+ "Multi-line return statement")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$options = myFunction(\n array(array(\n 'options' =>
123\n ))\n);"
+ "Assignment with double-dimensional array with double arrow assignment
inside function call")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nswitch ($condition) {\n case 34:\n if ($item['Random'] %
10 == 0) {\n $attributes['item'] = ($item['IntegerValue'] / 10);\n
} else {\n $attributes['item'] =\n
number_format(($item['IntegerValue'] / 10), 1, '.', '');\n }\n
break;\n}\n"
+ "Switch case with conditional modulo expression")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$options = array(\n 'options' => array(array(\n
'errorTo'\n ))\n);"
+ "Assignment with three-dimensional array with double arrow assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif ($myCondition) {\n $myObject->myMethod(myClass::class)\n
->myMethod2($myArgument2);\n }"
+ "Object-oriented file with bracket-less namespace with multiple levels,
class that extends and implements and functions with optional arguments")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$myObj->myFunction()\n ->mySecondaryFunction();"
+ "Indentation of chained class method calls outside of assignments and
conditionals")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n\n$myVar = $myClass->meMethod()\n ->mySecondMethod()\n
->myThirdMethod()\n->myFourthFunction(\n $myVariable\n);"
+ "Indentation for chained object operators in assignment with method call
with arguments")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n\n$myResult = !empty($myVar->myMethod3)\n && $myVar->myMethod\n
&& $myVar->myMethod2;\n"
+ "Indentation for chained object operators in assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$array = [\n 'second' => [\n 'hello' => true\n
]\n];\n\n$array = array(\n 'second' => array(\n 'third' => true\n
)\n);"
+ "Indent multi-dimensional arrays without trailing commas")
+
+ (phps-mode-test-indent--should-equal
+ "<html>\n <head>\n <?php echo $title; ?>\n </head>\n
<body>\n <?php\n\n if ($myTest) {\n doSomething();\n }\n\n
?>\n </body>\n</html>"
+ "A mixed HTML and PHP file.")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n\n if ($fullInfo) $fullInfo = unserialize ($fullInfo);\n else
array();\n\n"
+ "Indentation for single-line inline control structures.")
+
+ (phps-mode-test-indent--should-equal
+ "<?php
\n\nif (true) {\n // Was here\n}"
+ "If condition after a mixed newline encoded file")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-psr-2 ()
+ "Test PSR-2 examples from: https://www.php-fig.org/psr/psr-2/.";
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nnamespace Vendor\\Package;\n\nclass ClassName\n{\n public $foo =
null;\n}"
+ "PSR-2 : 4.2. Properties")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nnamespace Vendor\\Package;\n\nclass ClassName\n{\n public
function fooBarBaz($arg1, &$arg2, $arg3 = [])\n {\n // method body\n
}\n}"
+ "PSR-2 : 4.3. Methods")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nnamespace Vendor\\Package;\n\nclass ClassName\n{\n public
function foo($arg1, &$arg2, $arg3 = [])\n {\n // method body\n
}\n}"
+ "PSR-2 : 4.4. Method Arguments : Example 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nnamespace Vendor\\Package;\n\nclass ClassName\n{\n public
function aVeryLongMethodName(\n ClassTypeHint $arg1,\n &$arg2,\n
array $arg3 = []\n ) {\n // method body\n }\n}"
+ "PSR-2 : 4.4. Method Arguments : Example 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nbar();\n$foo->bar($arg1);\nFoo::bar($arg2, $arg3);"
+ "PSR-2 : 4.6. Method and Function Calls : Example 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$foo->bar(\n $longArgument,\n $longerArgument,\n
$muchLongerArgument\n);"
+ "PSR-2 : 4.6. Method and Function Calls : Example 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nwhile ($expr) {\n // structure body\n}"
+ "PSR-2 : 5.3. while, do while : Example 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\ndo {\n // structure body;\n} while ($expr);"
+ "PSR-2 : 5.3. while, do while : Example 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nfor ($i = 0; $i < 10; $i++) {\n // for body\n}"
+ "PSR-2 : 5.4. for")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nforeach ($iterable as $key => $value) {\n // foreach body\n}"
+ "PSR-2 : 5.5. foreach")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$foo->bar(\n $arg1,\n function ($arg2) use ($var1) {\n
// body\n },\n $arg3\n);"
+ "PSR-2 : 6. Closures : Example 3")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-multi-line-assignments ()
+ "Test for multi-line assignments."
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random4'\n);\n$variable = true;\n"
+ "Array assignment on three lines")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random4' =>\n 'hello'\n);"
+ "Array assignment with double arrow elements on four lines")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
+ "Array assignment on two lines")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = 'A line' .\n 'more text here' .\n 'last line here';"
+ "Concatenated single-quoted-string multiple-lines in assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var .=\n 'A line';"
+ "Concatenated equal single-quoted-string on multiple-lines in assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var *=\n 25;"
+ "Multiplication equal assignment on multiple-lines")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$str = <<<EOD\nExample of string\nspanning multiple lines\nusing
heredoc syntax.\nEOD;\n"
+ "Multi-line HEREDOC string in assignment")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var =\n 500 .\n \"200\" .\n 100.0 .\n '200' .\n
$this->getTail()\n ->getBottom();"
+ "Multi-line assignments")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-inline-if ()
+ "Test for inline if indentations."
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true)\n echo 'Something';\nelse\n echo 'Something
else';\necho true;\n"
+ "Inline control structures if else")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true)\n echo 'Something';\nelse if (true)\n echo
'Something else';\necho true;\n"
+ "Inline control structures if else if")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nwhile (true)\n echo 'Something';"
+ "Inline control structures while")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-alternative-if ()
+ "Test for alternative if indentations."
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true):\n echo 'Something';\nelseif (true):\n echo
'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
+ "Alternative control structures")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true):\n echo 'Something';\nelseif (true\n && true\n):\n
echo 'Something';\nelse:\n echo 'Something else';\n echo 'Something
else again';\nendif;\necho true;\n"
+ "Alternative control structures with multi-line elseif 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-classes ()
+ "Test for class indent."
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nnamespace myNamespace\n{\n class myClass\n {\n public
function myFunction()\n {\n echo 'my statement';\n }\n
}\n}\n"
+ "Regular PHP with namespaces, classes and functions")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nnamespace myNamespace\n{\n class myClass {\n public
function myFunction()\n {\n echo 'my statement';\n }\n
}\n}\n"
+ "Regular PHP with namespaces, classes and functions")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nclass MyClass extends MyAbstract implements\n myInterface,\n
myInterface2\n{\n}\n"
+ "Class multi-line implements")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nclass MyClass\n extends MyAbstract\n implements myInterface,
myInterface2\n{\n}\n"
+ "Class multi-line extends and implements")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/**\n *\n */\nnamespace Aomebo\n{\n /**\n *\n */\n
class Base\n {\n }\n}\n"
+ "Namespace and class with doc-comments")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-if ()
+ "Test for multi-line if expressions."
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (\n true\n && true\n) {\n echo 'was here';\n}\n"
+ "If expression spanning multiple lines 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n// Can we load configuration?\nif ($configuration::load(\n
self::getParameter(self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME),\n
self::getParameter(self::PARAMETER_CONFIGURATION_EXTERNAL_FILENAME),\n
self::getParameter(self::PARAMETER_STRUCTURE_INTERNAL_FILENAME),\n
self::getParameter(self::PARAMETER_STRUCTURE_EXTERNAL_FILENAME)\n)) {\n echo
'was here';\n}\n"
+ "If expression spanning multiple lines 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true) {\n if ($configuration::load(\n
self::getParameter(self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME),\n
self::getParameter(self::PARAMETER_CONFIGURATION_EXTERNAL_FILENAME),\n
self::getParameter(self::PARAMETER_STRUCTURE_INTERNAL_FILENAME),\n
self::getParameter(self::PARAMETER_STRUCTURE_EXTERNAL_FILENAME))\n ) {\n
echo 'was here';\n }\n}\n"
+ "If expression spanning multiple lines 3")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myFunction(true)\n) {\n echo 'was here';\n}\n"
+ "If expression spanning multiple lines 4")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myFunction(\n true)\n) {\n echo 'was here';\n}\n"
+ "If expression spanning multiple lines 5")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (true) {\n if (myFunction(\n true)\n ) {\n
echo 'was here';\n }\n}\n"
+ "Nested if expression spanning multiple lines 6")
+
+ (phps-mode-test-indent--should-equal
+ "<html><head><title><?php if ($myCondition) {\n if ($mySeconCondition)
{\n echo $title2;\n \n } ?></title><body>Bla bla</body></html>"
+ "Mixed HTML/PHP with if expression and token-less lines")
+
+ (phps-mode-test-indent--should-equal
+ "<html><head><title><?php\nif ($myCondition) {\n if ($mySecondCondition)
{\n echo $title;\n } else if ($mySecondCondition) {\n echo
$title4;\n } else {\n echo $title2;\n echo $title3;\n }\n}
?></title><body>Bla bla</body></html>"
+ "Mixed HTML/PHP with if expression 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myFirstCondition()) {\n $this->var = 'abc123';\n} else {\n
$this->var = 'def456';\n}\n"
+ "Regular else expression indent calculation")
+
+ )
+
+(defun phps-mode-test-indent--get-lines-indent-switch-case ()
+ "Test for switch-case indentation."
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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';\nendswitch;\n"
+ "Switch, case, default with alternative control structure")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$product_path = \"${filename[0]}/${filename[1]}/\";\necho 'here';\n"
+ "Double-quoted string with multiple indexed variables in it")
+
+ )
+
+(defun phps-mode-test-indent--indent-line ()
+ "Test for indentation."
+
+ ;; Curly bracket tests
+ (phps-mode-test-indent--should-equal
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) {\n
echo $title;\n\n} ?></title><body>Bla bla</body></html>"
+ "Curly bracket test")
+
+ (phps-mode-test-indent--should-equal
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title2;\n\n} ?></title><body>Bla bla</body></html>"
+ "Curly bracket test 3")
+
+ (phps-mode-test-indent--should-equal
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title3;\n\n}\n?>\n</title><body>Bla bla</body></html>"
+ "Curly bracket test 4")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n'random3'\n);\n$variable = true;\n"
+ "Assignment test 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random2'\n );\n$variable = true;\n"
+ "Assignment test 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/**\n* My first line\n* My second line\n**/\n"
+ "Doc-comment test 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/**\n* My first line\n* My second line\n**/\n"
+ "Doc-comment test 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n/**\n* My first line\n* My second line\n**/\n"
+ "Doc-comment test 3")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
+ "Round bracket test 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nadd_filter(\n\"views_{$screen->id}\",'__return_empty_array'\n);"
+ "Round bracket test 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (random_expression(\ntrue\n)) {\nsome_logic_here();\n}"
+ "Round bracket test 3")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (empty(\n$this->var\n) && !empty($this->var)\n) {\n$this->var =
'abc123';\n}\n"
+ "Nested if-expression")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myFirstCondition()) {\n $this->var = 'abc123';\n } else
{\n $this->var = 'def456';\n}\n"
+ "Regular else expression")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myFirstCondition()) {\n $this->var = 'abc123';\n } else
if (mySeconCondition()) {\n $this->var = 'def456';\n}\n"
+ "Regular else if test")
+
+ ;; Square bracket
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = [\n 'random' => [\n 'hello',\n],\n];\n"
+ "Square bracket test 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myRandomCondition()):\necho 'Something here';\n else:\n
echo 'Something else here 8';\nendif;\n"
+ "Alternative else test")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nswitch (myRandomCondition()) {\ncase 'Something here':\necho
'Something else here';\n}\n"
+ "Switch case indentation test")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nswitch (myRandomCondition()): \ncase 'Something here':\necho
'Something else here';\nendswitch;\n"
+ "Alternative switch case indentation test 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myRandomCondition())\necho 'Something here';\necho 'Something
else here';\n"
+ "Inline control structure indentation")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myRandomCondition())\n echo 'Something here';\n echo
'Something else here';\n"
+ "Inline control structure indentation 2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (myRandomCondition()):\necho 'Something here';\n echo
'Something else here';\nendif;\n"
+ "Alternative control structure indentation 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nmyFunction(\n array(\n 'random' => 'abc',\n ),\n
$var5\n);\n"
+ "Function arguments with associate array indentation")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = $var2->getHead()\n->getTail();\n"
+ "Multi-line assignment indentation test 1")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var =\n'random string';\n"
+ "Single-line assignment indentation test")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (empty($this->var)):\n$this->var = 'abc123';\n endif;"
+ "Alternative control structure if expression")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif (empty($this->var)):\n$this->var = 'abc123';\nendif;"
+ "Alternative control structure test")
+
+ (phps-mode-test-indent--should-equal
+ "<html>\n<head>\n<title><?php echo $title;
?></title>\n</head>\n<body>\n<div class=\"contents\"><?php echo $body;
?></div>\n</body>\n</html>"
+ "A mixed HTML and PHP file, each PHP command is inside HTML markup")
+
+ (phps-mode-test-indent--should-equal
+ "<html>\n<head>\n<title><?php echo $title; ?></title>\n</head>\n<body
class=\"<?php echo $class; ?>\">\n<div class=\"contents\"><?php echo $body;
?></div>\n</body>\n</html>"
+ "A mixed HTML and PHP file, each PHP command is inside HTML markup, one PHP
inside markup tag")
+
+ (phps-mode-test-indent--should-equal
+ "<html>\n <head>\n <title><?php $myTitle; ?></title>\n
</head>\n <body>\n <?php echo 'test'; ?>\n <h1>My title</h1>\n
<?php if ($myTest): ?>\n <div>\n A lot of other
stuff.\n </div>\n <?php endif; ?>\n </body>\n</html>"
+ "Indent mixed HTML and one-line PHP lines.")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nif ($here) {\n $var = \"abc $b[abc] def\";\n// Was here\n}\n\n"
+ "Indentation after line with square brackets inside double quoted string")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n\n// Adjust days to delivery accorind to document\nswitch
($dayOfWeek)\n{\n case 1: // Monday\n case 2: // Tuesday\n case 3: //
Wednesday\n case 7: // Sunday\n $daysToDelivery = 3;\n
break;\n case 4: // Thursday\n case 5: // Friday\n $daysToDelivery
= 5;\n break;\n case 6: // Saturday\n $daysToDelivery = 4;\n
break;\n default:\n throw new \Exception(sprintf(\n
'day of week above interval (1-7): [...]
+ "Switch case with default case and trailing comments")
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($myCondition) {\necho 'I was here';\n}"
+ "Alternative indentation inside if block"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($myCondition) {\n echo 'I was here';\n}"))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($myCondition) {\necho 'I was here';\necho 'I was here
again';\n}"
+ "Alternative indentation on closing if block"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($myCondition) {\n echo 'I was here';\n echo 'I
was here again';\n}"))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($test) {\nif ($test2) {\n\n}\n}"
+ "Alternative indentation on nested if block with empty contents"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($test) {\n if ($test2) {\n \n }\n}"))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($test) {\nif ($test2) {\n\n}\n\n}"
+ "Alternative indentation on multiple closing brackets"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($test) {\n if ($test2) {\n \n }\n
\n}"))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($test) {\n\n} else if ($test) {\n\n}\n"
+ "Alternative indentation on elseif block"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($test) {\n \n} else if ($test) {\n \n}\n"))))
+
+ (phps-mode-test--with-buffer
+ "if ($true) {\nif ($true) {\n}\n}"
+ "Alternative indentation on closing bracket inside parent bracket"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "if ($true) {\n if ($true) {\n }\n}"))))
+
+ (phps-mode-test--with-buffer
+ "/**\n*\n*/"
+ "Alternative indentation on last line of doc comment block"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "/**\n *\n */"))))
+
+ (phps-mode-test--with-buffer
+ " $var = 'abc';\n // Comment"
+ "Alternative indentation on single-line assignment"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "$var = 'abc';\n// Comment"))))
+
+ (phps-mode-test--with-buffer
+ "$var =\n'abc';\n$var =\n'abc'\n. 'def';\n// Comment\n"
+ "Alternative indentation on multi-line assignment"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "$var =\n 'abc';\n$var =\n 'abc'\n . 'def';\n//
Comment\n"))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($here) {\nif ($wasHere)\n{\n\n}\n}\n\n"
+ "Alternative indentation on line after condition"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($here) {\n if ($wasHere)\n {\n \n
}\n}\n\n"))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($myCondition)\n{\n$var = array(\n'was here'\n);\n// Was
here\n}\n"
+ "Alternative indentation on line after array declaration"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($myCondition)\n{\n $var = array(\n 'was
here'\n );\n // Was here\n}\n"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($myCondition == 2) {\necho 'store_vars: <pre>' .
print_r($store_vars, true) . '</pre>';\necho 'search_ids: <pre>' .
print_r($search_ids, true) . '</pre>';\n}"
+ "Alternative indentation on line echo"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($myCondition == 2) {\n echo 'store_vars: <pre>' .
print_r($store_vars, true) . '</pre>';\n echo 'search_ids: <pre>' .
print_r($search_ids, true) . '</pre>';\n}"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif (is_array(\n$array\n)) {\necho 'was here';\n}"
+ "Alternative indentation after trailing opening bracket while closing two
earlier on line"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif (is_array(\n $array\n)) {\n echo 'was here';\n}"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\n\n$var = array(\n'123' =>\n'def',\n);"
+ "Alternative indentation on lines after lines ending with T_DOUBLE_ARROW"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\n\n$var = array(\n '123' =>\n 'def',\n);"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\n$var = array(\n'123' => true,\n\n);"
+ "Alternative indentation after comma ended double arrow assignment"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\n$var = array(\n '123' => true,\n \n);"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nfunction myFunction(\n$arg = true,\n$arg2 = false\n) {\n\n}"
+ "Line after function argument with default value"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nfunction myFunction(\n $arg = true,\n $arg2 =
false\n) {\n \n}"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "$random = get_post_meta(\n $postId,\n '_random',
// TODO Here\n true // TODO Here\n );"
+ "Line in multi-line function call"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "$random = get_post_meta(\n $postId,\n '_random', // TODO
Here\n true // TODO Here\n);"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "$cartPrice = round(\n $cartPrice,\n2 // TODO Here\n);"
+ "Assignment with multi-line function call"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "$cartPrice = round(\n $cartPrice,\n 2 // TODO Here\n);"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "$applications =\n $transaction->getResponseBodyDecoded();\n // TODO
Here\n"
+ "Line after multi-line assignment with object-operator"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "$applications =\n
$transaction->getResponseBodyDecoded();\n// TODO Here\n"
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\necho '<dl><dt>' . __('Data', 'something')\n . ':</dt><dd><pre>'
. print_r($decodedData, true) . '</pre></dd></dl>';\necho '<div class=\"meta
actions\">';\n"
+ "Two echo statements, one spans two lines"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\necho '<dl><dt>' . __('Data', 'something')\n .
':</dt><dd><pre>' . print_r($decodedData, true) . '</pre></dd></dl>';\necho
'<div class=\"meta actions\">';\n "
+ ))))
+
+ (phps-mode-test--with-buffer
+ "<?php\nif ($shippingMethod->id ===\n \\MyClass::METHOD_ID\n )
{\n"
+ "Multi-line if statement testing equality in two lines"
+ (phps-mode-test-indent--indent-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif ($shippingMethod->id ===\n \\MyClass::METHOD_ID\n)
{\n "
+ ))))
+
+ (phps-mode-test--with-buffer
+ ""
+ "Multi-line if block after opening parenthesis"
+ (execute-kbd-macro "<?php")
+ (execute-kbd-macro (kbd "<return>"))
+ (execute-kbd-macro "if (true) {")
+ (execute-kbd-macro (kbd "<return>"))
+ (execute-kbd-macro "if (")
+ (execute-kbd-macro (kbd "<return>"))
+ (let ((buffer-contents
+ (buffer-substring-no-properties
+ (point-min)
+ (point-max))))
+ (should (equal
+ buffer-contents
+ "<?php\nif (true) {\n if (\n \n )\n}"
+ ))))
+
+ )
+
+(defun phps-mode-test-indent ()
+ "Run test for functions."
+ ;; (setq debug-on-error t)
+ (phps-mode-test-indent--get-lines-indent-if)
+ (phps-mode-test-indent--get-lines-indent-classes)
+ (phps-mode-test-indent--get-lines-indent-inline-if)
+ (phps-mode-test-indent--get-lines-indent-alternative-if)
+ (phps-mode-test-indent--get-lines-indent-multi-line-assignments)
+ (phps-mode-test-indent--get-lines-indent-switch-case)
+ (phps-mode-test-indent--get-lines-indent-psr-2)
+ (phps-mode-test-indent--get-lines-indent)
+ (phps-mode-test-indent--indent-line))
+
+(phps-mode-test-indent)
+
+(provide 'phps-mode-test-indent)
+
+;;; phps-mode-test-indent.el ends here
- [elpa] externals/phps-mode c29e35fea2 021/212: More work on bookkeeping, (continued)
- [elpa] externals/phps-mode c29e35fea2 021/212: More work on bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0daaa97f8d 025/212: SDT for for() loop started, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fa3681141b 027/212: Passed test for bookkeeping of conditional assignment via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fc4c763d68 030/212: Added SDT for class properties, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f7c261cee1 032/212: Generate parser command now compatible with latest emacs-parser-generator, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f82c9a377d 033/212: Re-generated parser to verify automation functionality, improved automation documentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f858060096 034/212: More work on bookkeeping generated from parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c83b1c264e 060/212: Fixed SDT for isset_variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8fa61fa1f2 063/212: Passing bookkeeping of interface method arguments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7a636ccd28 078/212: Removed obsolete file parser-grammar-macro.el, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode ee211dac6a 084/212: Started on indentation tests,
Christian Johansson <=
- [elpa] externals/phps-mode f65ca852cd 092/212: Passed another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 9a2573939a 094/212: More wrestling, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7c0cb57312 098/212: Added more multi-line assignment indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3a594466d5 100/212: Passed indent test for multi-line assignments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7deebc5f79 101/212: Improved indent test descriptions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d5d80017bc 104/212: Passed indent tests for concatenated string, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e083e90ac0 108/212: Passing more indentation tests for PSR-2, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 84d447e4e6 119/212: Added TODO item, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1ab6ac7324 131/212: Added failing tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7135a30446 173/212: Updated TODO items, Christian Johansson, 2022/01/26