Skip to content

Commit 25a923f

Browse files
committed
Merge pull request #224 from ejmr/improve-test
Improve test
2 parents eef97db + a292394 commit 25a923f

File tree

2 files changed

+52
-23
lines changed

2 files changed

+52
-23
lines changed

php-mode-test.el

+38-23
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)))
@@ -440,16 +442,16 @@ style from Drupal."
440442
(ert-deftest php-mode-test-language-constructs()
441443
"Test highlighting of language constructs and reserved keywords"
442444
(with-php-mode-test ("language-constructs.php")
443-
(while (search-forward "ClassName" nil t)
444-
(backward-char)
445-
(should (eq 'font-lock-type-face
446-
(get-text-property (point) 'face)))))
445+
(while (search-forward "ClassName" nil t)
446+
(backward-char)
447+
(should (eq 'font-lock-type-face
448+
(get-text-property (point) 'face)))))
447449
(with-php-mode-test ("language-constructs.php")
448-
(search-forward "Start:")
449-
(while (not (= (line-number-at-pos) (count-lines (point-min) (point-max))))
450-
(forward-line 1)
451-
(should (eq 'font-lock-keyword-face
452-
(get-text-property (point) 'face))))))
450+
(search-forward "Start:")
451+
(while (not (= (line-number-at-pos) (count-lines (point-min) (point-max))))
452+
(forward-line 1)
453+
(should (eq 'font-lock-keyword-face
454+
(get-text-property (point) 'face))))))
453455

454456
(ert-deftest php-mode-test-issue-178 ()
455457
"Highligth as keyword and following symbol"
@@ -474,21 +476,19 @@ 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")
481-
(while
482-
(search-forward "$test->" nil t)
483-
(should-not (eq 'font-lock-type-face
484-
(get-text-property (point) 'face))))))
482+
(while (search-forward "$test->" nil t)
483+
(should-not (eq 'font-lock-type-face
484+
(get-text-property (point) 'face))))))
485485

486486
(ert-deftest php-mode-test-issue-200 ()
487487
"Test highlighting and elimination of extraneous whitespace in PSR-2 mode"
488488
(with-php-mode-test ("issue-200.php")
489-
(php-mode-custom-coding-style-set 'php-mode-coding-style 'psr2)
490-
(should show-trailing-whitespace)
491-
(should (and (listp before-save-hook) (member 'delete-trailing-whitespace before-save-hook)))))
489+
(php-mode-custom-coding-style-set 'php-mode-coding-style 'psr2)
490+
(should show-trailing-whitespace)
491+
(should (and (listp before-save-hook) (member 'delete-trailing-whitespace before-save-hook)))))
492492

493493
(ert-deftest php-mode-test-issue-201 ()
494494
"Test highlighting of special variables"
@@ -529,11 +529,26 @@ style from Drupal."
529529
(ert-deftest php-mode-test-issue-184()
530530
"Test indent-line for statements and heredoc end at beginning of lines"
531531
(with-php-mode-test ("issue-184.php")
532-
(search-forward "html;")
533-
(php-cautious-indent-line)
534-
(should (eq (current-indentation) 0))
535-
(search-forward "return;")
536-
(php-cautious-indent-line)
537-
(should (eq (current-indentation) c-basic-offset))))
532+
(search-forward "html;")
533+
(php-cautious-indent-line)
534+
(should (= (current-indentation) 0))
535+
(search-forward "return;")
536+
(php-cautious-indent-line)
537+
(should (= (current-indentation) c-basic-offset))))
538+
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)))))
538553

539554
;;; 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)