Skip to content

Commit a292394

Browse files
jorissteynsyohex
authored andcommitted
[PATCH] Add test case for case label/break/return indent
The new case tests indent offsets for case labels and break/return statements and takes into account the different indentation of case labels in the PEAR standard.
1 parent a1d9533 commit a292394

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

php-mode-test.el

+17-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ the coding style to one of the following:
8080
2. `drupal'
8181
3. `wordpress'
8282
4. `symfony2'
83+
5. `psr2'
8384
8485
Using any other symbol for STYLE results in undefined behavior.
8586
The test will use the PHP style by default.
@@ -97,6 +98,7 @@ run with specific customizations set."
9798
(drupal '(php-enable-drupal-coding-style))
9899
(wordpress '(php-enable-wordpress-coding-style))
99100
(symfony2 '(php-enable-symfony2-coding-style))
101+
(psr2 '(php-enable-psr2-coding-style))
100102
(t '(php-enable-default-coding-style)))
101103

102104
,(unless custom '(custom-set-variables '(php-lineup-cascaded-calls nil)))
@@ -474,7 +476,6 @@ style from Drupal."
474476
"Indentation of switch case body preceeded by multiple case statements"
475477
(with-php-mode-test ("issue-186.php" :indent t :magic t)))
476478

477-
478479
(ert-deftest php-mode-test-issue-197 ()
479480
"Test highlighting of member and function names (should not have type face)"
480481
(with-php-mode-test ("issue-197.php")
@@ -535,4 +536,19 @@ style from Drupal."
535536
(php-cautious-indent-line)
536537
(should (= (current-indentation) c-basic-offset))))
537538

539+
(ert-deftest php-mode-test-switch-statements()
540+
"Test indentation inside switch statements"
541+
(with-php-mode-test ("switch-statements.php" :indent t :style pear)
542+
(search-forward "case true:")
543+
(should (eq (current-indentation) 0))
544+
(search-forward "break")
545+
(should (eq (current-indentation) c-basic-offset)))
546+
(with-php-mode-test ("switch-statements.php" :indent t :style psr2)
547+
(search-forward "case true:")
548+
(should (eq (current-indentation) c-basic-offset))
549+
(search-forward "break")
550+
(should (eq (current-indentation) (* 2 c-basic-offset)))
551+
(search-forward "return")
552+
(should (eq (current-indentation) (* 2 c-basic-offset)))))
553+
538554
;;; php-mode-test.el ends here

tests/switch-statements.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* Test indentation of switch statement and case labels
5+
*/
6+
7+
switch (true) {
8+
case true:
9+
echo 'hello';
10+
break;
11+
12+
case true:
13+
return;
14+
}

0 commit comments

Comments
 (0)