[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 3f3a8bb0fa 081/212: Major refactor of indent
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 3f3a8bb0fa 081/212: Major refactor of indent tests |
Date: |
Wed, 26 Jan 2022 01:50:57 -0500 (EST) |
branch: externals/phps-mode
commit 3f3a8bb0fae0f127bd28c1543e64b7ad27907423
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Major refactor of indent tests
---
test/phps-mode-test-lex-analyzer.el | 824 ++++++++++++------------------------
1 file changed, 275 insertions(+), 549 deletions(-)
diff --git a/test/phps-mode-test-lex-analyzer.el
b/test/phps-mode-test-lex-analyzer.el
index c1dfd13b2f..7b916975f0 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -289,561 +289,426 @@
)
+(defun phps-mode-test-lex-analyzer--indent-should-equal (string name)
+ "Test indent of whole buffer containing STRING with NAME."
+ (phps-mode-test--with-buffer
+ string
+ name
+ (phps-mode-test-lex-analyzer--alternative-indentation-whole-buffer)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal
+ buffer-contents
+ string)))))
+
(defun phps-mode-test-lex-analyzer--get-lines-indent ()
- "Test `phps-mode-lex-analyzer--get-lines-indent' function."
+ "Test indent function."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n/**\n * Bla\n */"
- "DOC-COMMENT"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 1)) (4 (0 1)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "DOC-COMMENT")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nmyFunction(array(\n 23,\n [\n 25\n ]\n )\n);"
- "Round and square bracket expressions"
- (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-lex-analyzer--get-lines-indent)))))
+ "Round and square bracket expressions")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nvar_dump(array(<<<EOD\nfoobar!\nEOD\n));\n?>"
- "HEREDOC in arguments example"
- ;; (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--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "HEREDOC in arguments example")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line NOWDOC string")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var = \"A line\nmore text here\nlast line here\";"
- "Multi-line double-quoted string"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line double-quoted string")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var = 'A line\nmore text here\nlast line here';"
- "Multi-line single-quoted string"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line single-quoted string")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\necho \"A line\" .\n \"more text here\" .\n \"last line
here\";"
- "Concatenated double-quoted-string spanning multiple-lines"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated double-quoted-string spanning multiple-lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated double-quoted-string spanning multiple-lines inside function")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\necho \"A line\"\n . \"more text here\"\n . \"last line
here\";"
- "Concatenated double-quoted-string spanning multiple-lines 2"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated double-quoted-string spanning multiple-lines 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated double-quoted-string spanning multiple-lines inside function
2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\necho 'A line' .\n 'more text here' .\n 'last line here';"
- "Concatenated single-quoted-string spanning multiple-lines"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated single-quoted-string spanning multiple-lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated single-quoted-string spanning multiple-lines inside function")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\necho 'A line'\n . 'more text here'\n . 'last line here';"
- "Concatenated single-quoted-string spanning multiple-lines 2"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated single-quoted-string spanning multiple-lines 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated single-quoted-string spanning multiple-lines inside function
2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line HEREDOC string outside assignment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n/**\n * @var string\n */\necho 'was here';\n"
- "Statement after doc-comment"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 1)) (4 (0 1)) (5 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Statement after doc-comment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Statement after a define() with a doc-comment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nfunction myFunction($parameters = null)\n{\n echo
'statement';\n}\n"
- "Statement after one-lined function declaration with optional argument"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Statement after one-lined function declaration with optional argument")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php if (true) { ?>\n <?php echo 'here'; ?>\n<?php } ?>"
- "Regular if-expression but inside scripting tags"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (1 0)) (3 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Regular if-expression but inside scripting tags")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\ndo {\n echo 'true';\n} while ($number > 0\n && $letter >
0\n);"
- "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-lex-analyzer--get-lines-indent)))))
+ "Do while loop with multi-line condition")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\ndo {\n echo 'true';\n} while ($number > 0\n && $letter >
0\n);"
- "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-lex-analyzer--get-lines-indent)))))
+ "Do while loop with multi-line condition")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$myVar = 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n ) .
'okeoke';\n?>"
- "Concatenated assignment string with function call"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated assignment string with function call")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$myVar = 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n )\n
. 'okeoke';\n?>"
- "Concatenated assignment 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-lex-analyzer--get-lines-indent)))))
+ "Concatenated assignment string with function call")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\necho 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n ) .
'okeoke';\n?>"
- "Concatenated echo string with function call"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated echo string with function call")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\necho 'blaha'\n . 'ijeije' . __(\n 'okeoke'\n )\n .
'okeoke';\n?>"
- "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-lex-analyzer--get-lines-indent)))))
+ "Concatenated echo string with function call")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$options = [\n 0 => [\n 'label' => __('No'),\n
'value' => 0,\n ],\n];"
- "Assignment with square bracketed array"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (1
0)) (7 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Assignment with square bracketed array")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$options = array(\n 'blaha' .\n 'blaha',\n 123,\n
'blaha'\n);"
- "Assignment with square bracketed array"
- (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-lex-analyzer--get-lines-indent)))))
+ "Assignment with square bracketed array")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nreturn $variable\n && $variable;"
- "Multi-line return statement"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line return statement")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Assignment with double-dimensional array with double arrow assignment
inside function call")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (3 0)) (6 (2
0)) (7 (3 0)) (8 (4 0)) (9 (2 0)) (10 (2 0)) (11 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Switch case with conditional modulo expression")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$options = array(\n 'options' => array(array(\n
'errorTo'\n ))\n);"
- "Assignment with three-dimensional array with double arrow assignment"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Assignment with three-dimensional array with double arrow assignment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Object-oriented file with bracket-less namespace with multiple levels,
class that extends and implements and functions with optional arguments")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$myObj->myFunction()\n ->mySecondaryFunction();"
- "Indentation of chained class method calls outside of assignments and
conditionals"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Indentation of chained class method calls outside of assignments and
conditionals")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (1
0)) (7 (2 0)) (8 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Indentation for chained object operators in assignment with method call
with arguments")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n\n$myResult = !empty($myVar->myMethod3)\n && $myVar->myMethod\n
&& $myVar->myMethod2;\n"
- "Indentation for chained object operators in assignment"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Indentation for chained object operators in assignment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0
0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (2 0)) (11 (1 0)) (12 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent))))
+ "Indent multi-dimensional arrays without trailing commas")
- (phps-mode-test--with-buffer
- "<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."
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (1 0)) (5 (1 0)) (6 (0
0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (0 0)) (11 (0 0)) (12 (0 0)) (13 (1 0))
(14 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
- )
+ (phps-mode-test-lex-analyzer--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--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n\n if ($fullInfo) $fullInfo = unserialize ($fullInfo);\n else
array();\n\n"
- "Indentation for single-line inline control structures."
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Indentation for single-line inline control structures.")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php
\n\nif (true) {\n // Was here\n}"
- "If condition after a mixed newline encoded file"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "If condition after a mixed newline encoded file")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-psr-2 ()
"Test PSR-2 examples from: https://www.php-fig.org/psr/psr-2/.";
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 1.1. Example")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 3. Namespace and Use Declarations")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.1. Extends and Implements : Example 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.1. Extends and Implements : Example 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nnamespace Vendor\\Package;\n\nclass ClassName\n{\n public $foo =
null;\n}"
- "PSR-2 : 4.2. Properties"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (1
0)) (7 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.2. Properties")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (1
0)) (7 (1 0)) (8 (2 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.3. Methods")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0)) (5 (0 0)) (6 (1
0)) (7 (1 0)) (8 (2 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.4. Method Arguments : Example 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.4. Method Arguments : Example 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 ; 4.5. abstract, final, and static")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.6. Method and Function Calls : Example 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 4.6. Method and Function Calls : Example 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.1. if, elseif, else")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.2. switch, case")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.3. while, do while : Example 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.3. while, do while : Example 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.4. for")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.5. foreach")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 5.6. try, catch")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 6. Closures : Example 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (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 [...]
+ "PSR-2 : 6. Closures : Example 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "PSR-2 : 6. Closures : Example 3")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-multi-line-assignments ()
"Test for multi-line assignments."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Array assignment on three lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$variable = array(\n 'random4' =>\n 'hello'\n);"
- "Array assignment with double arrow elements on four lines"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Array assignment with double arrow elements on four lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Array assignment on two lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated single-quoted-string multiple-lines in assignment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var .=\n 'A line';"
- "Concatenated equal single-quoted-string on multiple-lines in assignment"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Concatenated equal single-quoted-string on multiple-lines in assignment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var *=\n 25;"
- "Multiplication equal assignment on multiple-lines"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multiplication equal assignment on multiple-lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line HEREDOC string in assignment")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?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 (2 0)) (5 (2 0)) (6 (2
0)) (7 (2 0)) (8 (3 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Multi-line assignments")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-inline-if ()
"Test for inline if indentations."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (true)\n echo 'Something';\nelse\n echo 'Something
else';\necho true;\n"
- "Inline control structures if else"
- (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-lex-analyzer--get-lines-indent)))))
+ "Inline control structures if else")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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-lex-analyzer--get-lines-indent)))))
+ "Inline control structures if else if")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nwhile (true)\n echo 'Something';"
- "Inline control structures while"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Inline control structures while")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-alternative-if ()
"Test for alternative if indentations."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0
0)) (7 (1 0)) (8 (1 0)) (9 (0 0)) (10 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Alternative control structures")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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)) (9 (1 0)) (10 (1 0)) (11 (0 0)) (12 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Alternative control structures with multi-line elseif 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Alternative control structures with multi-line elseif 2")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-classes ()
"Test for class indent."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (2
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (1 0)) (11 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Regular PHP with namespaces, classes and functions")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (2 0)) (6 (2
0)) (7 (3 0)) (8 (2 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Regular PHP with namespaces, classes and functions")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nclass MyClass extends MyAbstract implements\n myInterface,\n
myInterface2\n{\n}\n"
- "Class multi-line implements"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Class multi-line implements")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nclass MyClass\n extends MyAbstract\n implements myInterface,
myInterface2\n{\n}\n"
- "Class multi-line extends and implements"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0)) (6 (0
0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Class multi-line extends and implements")
-
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 1)) (4 (0 1)) (5 (0 0)) (6 (0
0)) (7 (1 0)) (8 (1 1)) (9 (1 1)) (10 (1 0)) (11 (1 0)) (12 (1 0)) (13 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Namespace and class with doc-comments")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-if ()
"Test for multi-line if expressions."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (\n true\n && true\n) {\n echo 'was here';\n}\n"
- "If expression spanning multiple lines 1"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (0 0)) (6 (1
0)) (7 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "If expression spanning multiple lines 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (1
0)) (7 (1 0)) (8 (0 0)) (9 (1 0)) (10 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "If expression spanning multiple lines 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (2
0)) (7 (2 0)) (8 (1 0)) (9 (2 0)) (10 (1 0)) (11 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "If expression spanning multiple lines 3")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myFunction(true)\n) {\n echo 'was here';\n}\n"
- "If expression spanning multiple lines 4"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "If expression spanning multiple lines 4")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myFunction(\n true)\n) {\n echo 'was here';\n}\n"
- "If expression spanning multiple lines 5"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (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-lex-analyzer--get-lines-indent)))))
+ "If expression spanning multiple lines 5")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Nested if expression spanning multiple lines 6")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))
- (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (2 0)) (5 (1 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Mixed HTML/PHP with if expression and token-less lines")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2
0)) (7 (1 0)) (8 (2 0)) (9 (2 0)) (10 (1 0)) (11 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Mixed HTML/PHP with if expression 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myFirstCondition()) {\n $this->var = 'abc123';\n} else {\n
$this->var = 'def456';\n}\n"
- "Regular else expression indent calculation"
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (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-lex-analyzer--get-lines-indent)))))
+ "Regular else expression indent calculation")
)
(defun phps-mode-test-lex-analyzer--get-lines-indent-switch-case ()
"Test for switch-case indentation."
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Switch, case, default")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (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--hash-to-list
(phps-mode-lex-analyzer--get-lines-indent)))))
+ "Switch, case, default with alternative control structure")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "Alternative switch, case, default with exception after it")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Indent: %s" (phps-mode-test--hash-to-list
(phps-mode-lex-analyzer--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-lex-analyzer--get-lines-indent)))))
+ "Curly switch, case, default with exception after it")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$product_path = \"${filename[0]}/${filename[1]}/\";\necho 'here';\n"
- "Double-quoted string with multiple indexed variables in it"
- (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)))
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+ "Double-quoted string with multiple indexed variables in it")
)
@@ -851,276 +716,137 @@
"Test for indentation."
;; Curly bracket tests
- (phps-mode-test--with-buffer
- "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
- "Curly bracket test"
- (goto-char 69)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\n if ($mySeconCondition) {\necho $title;\n\n}
?></title><body>Bla bla</body></html>"))))
+ (phps-mode-test-lex-analyzer--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--with-buffer
- "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition)
{\necho $title1;\n} ?></title><body>Bla bla</body></html>"
- "Curly bracket test 2"
- (goto-char 75)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<html><head><title><?php if
($myCondition) {\nif ($mySeconCondition) {\n echo $title1;\n}
?></title><body>Bla bla</body></html>"))))
+ (phps-mode-test-lex-analyzer--indent-should-equal
+ "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) {\n
echo $title1;\n} ?></title><body>Bla bla</body></html>")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (goto-char 98)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<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--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (goto-char 110)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<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--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$variable = array(\n'random3'\n);\n$variable = true;\n"
- "Assignment test 1"
- (goto-char 28)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random3'\n);\n$variable = true;\n"))))
+ "Assignment test 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$variable = array(\n 'random2'\n );\n$variable = true;\n"
- "Assignment test 2"
- (goto-char 43)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random2'\n);\n$variable = true;\n"))))
+ "Assignment test 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n/**\n* My first line\n* My second line\n**/\n"
- "Doc-comment test 1"
- (goto-char 20)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n/**\n * My first line\n* My
second line\n**/\n"))))
+ "Doc-comment test 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n/**\n* My first line\n* My second line\n**/\n"
- "Doc-comment test 2"
- (goto-char 9)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n/**\n* My first line\n* My second
line\n**/\n"))))
+ "Doc-comment test 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n/**\n* My first line\n* My second line\n**/\n"
- "Doc-comment test 3"
- (goto-char 46)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n/**\n* My first line\n* My second
line\n **/\n"))))
+ "Doc-comment test 3")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
- "Round bracket test 1"
- (goto-char 30)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random4');\n$variable = true;\n"))))
+ "Round bracket test 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nadd_filter(\n\"views_{$screen->id}\",'__return_empty_array'\n);"
- "Round bracket test 2"
- (goto-char 25)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nadd_filter(\n
\"views_{$screen->id}\",'__return_empty_array'\n);"))))
+ "Round bracket test 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (random_expression(\ntrue\n)) {\nsome_logic_here();\n}"
- "Round bracket test 3"
- (goto-char 36)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (random_expression(\ntrue\n))
{\nsome_logic_here();\n}"))))
+ "Round bracket test 3")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (empty(\n$this->var\n) && !empty($this->var)\n) {\n$this->var =
'abc123';\n}\n"
- "Nested if-expression"
- (goto-char 54)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (empty(\n$this->var\n) &&
!empty($this->var)\n) {\n$this->var = 'abc123';\n}\n"))))
+ "Nested if-expression")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myFirstCondition()) {\n $this->var = 'abc123';\n } else
{\n $this->var = 'def456';\n}\n"
- "Regular else expression"
- (goto-char 68)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (myFirstCondition()) {\n
$this->var = 'abc123';\n} else {\n $this->var = 'def456';\n}\n"))))
+ "Regular else expression")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myFirstCondition()) {\n $this->var = 'abc123';\n } else
if (mySeconCondition()) {\n $this->var = 'def456';\n}\n"
- "Regular else if test"
- (goto-char 68)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?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--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var = [\n 'random' => [\n 'hello',\n],\n];\n"
- "Square bracket test 1"
- (goto-char 51)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$var = [\n 'random' => [\n
'hello',\n ],\n];\n"))))
+ "Square bracket test 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myRandomCondition()):\necho 'Something here';\n else:\n
echo 'Something else here 8';\nendif;\n"
- "Alternative else test"
- (goto-char 62)
- (phps-mode-lex-analyzer--indent-line)
- ;; (message "Tokens %s" phps-mode-lexer-tokens)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (myRandomCondition()):\necho
'Something here';\nelse:\n echo 'Something else here 8';\nendif;\n"))))
+ "Alternative else test")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nswitch (myRandomCondition()) {\ncase 'Something here':\necho
'Something else here';\n}\n"
- "Switch case indentation test"
- (goto-char 45)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nswitch (myRandomCondition()) {\n
case 'Something here':\necho 'Something else here';\n}\n"))))
+ "Switch case indentation test")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nswitch (myRandomCondition()): \ncase 'Something here':\necho
'Something else here';\nendswitch;\n"
- "Alternative switch case indentation test 2"
- (goto-char 70)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nswitch (myRandomCondition()):
\ncase 'Something here':\n echo 'Something else here';\nendswitch;\n"))))
+ "Alternative switch case indentation test 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myRandomCondition())\necho 'Something here';\necho 'Something
else here';\n"
- "Inline control structure indentation"
- (goto-char 40)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (myRandomCondition())\n echo
'Something here';\necho 'Something else here';\n"))))
+ "Inline control structure indentation")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myRandomCondition())\n echo 'Something here';\n echo
'Something else here';\n"
- "Inline control structure indentation 2"
- (goto-char 60)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (myRandomCondition())\n echo
'Something here';\necho 'Something else here';\n"))))
+ "Inline control structure indentation 2")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (myRandomCondition()):\necho 'Something here';\n echo
'Something else here';\nendif;\n"
- "Alternative control structure indentation 1"
- (goto-char 40)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (myRandomCondition()):\n
echo 'Something here';\n echo 'Something else here';\nendif;\n"))))
+ "Alternative control structure indentation 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nmyFunction(\n array(\n 'random' => 'abc',\n ),\n
$var5\n);\n"
- "Function arguments with associate array indentation"
- (goto-char 65)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nmyFunction(\n array(\n
'random' => 'abc',\n ),\n $var5\n);\n"))))
+ "Function arguments with associate array indentation")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var = $var2->getHead()\n->getTail();\n"
- "Multi-line assignment indentation test 1"
- ;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (goto-char 35)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$var = $var2->getHead()\n
->getTail();\n"))))
+ "Multi-line assignment indentation test 1")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\n$var =\n'random string';\n"
- "Single-line assignment indentation test"
- (goto-char 20)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$var =\n 'random string';\n"))))
+ "Single-line assignment indentation test")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (empty($this->var)):\n$this->var = 'abc123';\n endif;"
- "Alternative control structure if expression"
- (goto-char 60)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif
(empty($this->var)):\n$this->var = 'abc123';\nendif;"))))
+ "Alternative control structure if expression")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--indent-should-equal
"<?php\nif (empty($this->var)):\n$this->var = 'abc123';\nendif;"
- "Alternative control structure test"
- (goto-char 35)
- (phps-mode-lex-analyzer--indent-line)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\nif (empty($this->var)):\n
$this->var = 'abc123';\nendif;"))))
+ "Alternative control structure test")
- (phps-mode-test--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (indent-region (point-min) (point-max))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<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--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (indent-region (point-min) (point-max))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<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--with-buffer
+ (phps-mode-test-lex-analyzer--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."
- (indent-region (point-min) (point-max))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<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--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (indent-region (point-min) (point-max))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal
- buffer-contents
- "<?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--with-buffer
+ (phps-mode-test-lex-analyzer--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"
- (indent-region (point-min) (point-max))
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?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 [...]
+ "Switch case with default case and trailing comments")
)
-(defun phps-mode-test-lex-analyzer--get-moved-imenu ()
+(defun phps-mode-test-lex-analyzer--get-moved-imenu ()
"Test for moving imenu index."
;; (message "Moved imenu %s" (phps-mode-lex-analyzer--get-moved-imenu
'(("myNamespace" ("myClass" ("myFunctionA" . 108) ("myFunctionB" . 161)))) 0 2))
@@ -1296,16 +1022,16 @@
;; (setq debug-on-error t)
(phps-mode-test-lex-analyzer--process-changes)
(phps-mode-test-lex-analyzer--alternative-indentation)
- ;; (phps-mode-test-lex-analyzer--get-inline-html-indentation)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-if)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-classes)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-inline-if)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-alternative-if)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-multi-line-assignments)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-switch-case)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent-psr-2)
- ;; (phps-mode-test-lex-analyzer--get-lines-indent)
- ;; (phps-mode-test-lex-analyzer--indent-line)
+ (phps-mode-test-lex-analyzer--get-inline-html-indentation)
+ (phps-mode-test-lex-analyzer--get-lines-indent-if)
+ (phps-mode-test-lex-analyzer--get-lines-indent-classes)
+ (phps-mode-test-lex-analyzer--get-lines-indent-inline-if)
+ (phps-mode-test-lex-analyzer--get-lines-indent-alternative-if)
+ (phps-mode-test-lex-analyzer--get-lines-indent-multi-line-assignments)
+ (phps-mode-test-lex-analyzer--get-lines-indent-switch-case)
+ (phps-mode-test-lex-analyzer--get-lines-indent-psr-2)
+ (phps-mode-test-lex-analyzer--get-lines-indent)
+ (phps-mode-test-lex-analyzer--indent-line)
(phps-mode-test-lex-analyzer--get-moved-imenu)
(phps-mode-test-lex-analyzer--comment-uncomment-region))
- [elpa] externals/phps-mode 2bc31a0f83 065/212: Added TODO items, (continued)
- [elpa] externals/phps-mode 2bc31a0f83 065/212: Added TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d802a669c0 061/212: Bookkeeping via AST working with isset() and !empty() scoped variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9115ec583 069/212: Cleaned up AST bookkeeping tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f4d2164f8b 067/212: Bookkeeping via parser SDT passing static variables in function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e66abd00e5 064/212: Bookkeeping via AST passing nested isset() !empty() expressions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8b5ce22d87 072/212: Fixed issue with SDT for return statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 491c82a2a1 071/212: Added TODO item for bookkeeping via AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5ec32f5f5a 076/212: Bookkeeping via AST passing all tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 228f212127 080/212: Starting on removing the old process tokens in string function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5b1f5b4774 079/212: Improved format of SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3f3a8bb0fa 081/212: Major refactor of indent tests,
Christian Johansson <=
- [elpa] externals/phps-mode b469f0ffbb 088/212: Passing indentation for multi-line class implements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f69df4fdf6 083/212: Moved indentation to separate file and test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 481deb6331 082/212: More work on indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fe9cb90c44 097/212: Passing indent test for some multi-line assignments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c9f715a1fd 093/212: Improved comments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f0ab7a2cdb 095/212: Passed tests for inline control structures, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 08f57c1d36 107/212: Added TODO item for indent, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenation test for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1ed09d42f5 111/212: Passing another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d205d8392f 113/212: Passed another indent test, Christian Johansson, 2022/01/26