Skip to content

Commit

Permalink
[PATCH] Add test case for case label/break/return indent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jorissteyn authored and syohex committed Feb 8, 2015
1 parent a1d9533 commit a292394
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ the coding style to one of the following:
2. `drupal'
3. `wordpress'
4. `symfony2'
5. `psr2'
Using any other symbol for STYLE results in undefined behavior.
The test will use the PHP style by default.
Expand All @@ -97,6 +98,7 @@ run with specific customizations set."
(drupal '(php-enable-drupal-coding-style))
(wordpress '(php-enable-wordpress-coding-style))
(symfony2 '(php-enable-symfony2-coding-style))
(psr2 '(php-enable-psr2-coding-style))
(t '(php-enable-default-coding-style)))

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


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

(ert-deftest php-mode-test-switch-statements()
"Test indentation inside switch statements"
(with-php-mode-test ("switch-statements.php" :indent t :style pear)
(search-forward "case true:")
(should (eq (current-indentation) 0))
(search-forward "break")
(should (eq (current-indentation) c-basic-offset)))
(with-php-mode-test ("switch-statements.php" :indent t :style psr2)
(search-forward "case true:")
(should (eq (current-indentation) c-basic-offset))
(search-forward "break")
(should (eq (current-indentation) (* 2 c-basic-offset)))
(search-forward "return")
(should (eq (current-indentation) (* 2 c-basic-offset)))))

;;; php-mode-test.el ends here
14 changes: 14 additions & 0 deletions tests/switch-statements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Test indentation of switch statement and case labels
*/

switch (true) {
case true:
echo 'hello';
break;

case true:
return;
}

0 comments on commit a292394

Please sign in to comment.