Skip to content

Commit 2ad220f

Browse files
authored
Merge pull request #431 from zonuexe/refactor/test-faces
Fix tests that using `faces` file instead of search text-property
2 parents 6709720 + 0c2b3aa commit 2ad220f

14 files changed

+1036
-175
lines changed

php-mode-test.el

Lines changed: 12 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,7 @@ file name and check that the faces of the fonts in the buffer match."
167167

168168
(ert-deftest php-mode-test-issue-8 ()
169169
"Annotation highlighting."
170-
(with-php-mode-test ("issue-8.php")
171-
(search-forward "@ORM")
172-
(should (equal
173-
(get-text-property (match-beginning 0) 'face)
174-
'(php-doc-annotation-tag font-lock-doc-face)))))
170+
(with-php-mode-test ("issue-8.php" :faces t)))
175171

176172
(ert-deftest php-mode-test-issue-9 ()
177173
"Single quote in text in HTML misinterpreted.
@@ -352,24 +348,7 @@ style from Drupal."
352348

353349
(ert-deftest php-mode-test-issue-136 ()
354350
"Proper highlighting for variable interpolation."
355-
(with-php-mode-test ("issue-136.php")
356-
(let ((variables '("$name"
357-
"${name}"
358-
"{$name}"
359-
"{$user->name}"
360-
"{$user->getName()}"
361-
"{$users[0]->name}"
362-
"{$users[$index]->name}"
363-
"{$users[$user->id]->name}"
364-
"{$users[$user->getID()]->name}")))
365-
;; All of the strings we want to test come after the call to
366-
;; ob_start(), so we jump to there first.
367-
(search-forward "ob_start()")
368-
(dolist (variable variables)
369-
(search-forward variable)
370-
(goto-char (match-beginning 0))
371-
(should (eq 'php-variable-name
372-
(get-text-property (point) 'face)))))))
351+
(with-php-mode-test ("issue-136.php") :faces t))
373352

374353
(ert-deftest php-mode-test-issue-144 ()
375354
"Indentation test '#' comment line has single quote."
@@ -720,51 +699,14 @@ style from Drupal."
720699
(goto-char (match-beginning 0))
721700
(should (eq 'php-constant
722701
(get-text-property (point) 'face))))))
702+
703+
;; Set default
723704
(custom-set-variables '(php-extra-constants (quote ())))
724-
(with-php-mode-test ("constants.php")
725-
(let ((variables '("no_constant"
726-
"no_CONSTANT"
727-
"extraconstant"
728-
"classIdentifier()"
729-
"2FOO")))
730-
(dolist (variable variables)
731-
(search-forward variable)
732-
(goto-char (match-beginning 0))
733-
(should (not (eq 'php-constant
734-
(get-text-property (point) 'face))))))))
705+
(with-php-mode-test ("constants.php" :faces t)))
735706

736707
(ert-deftest php-mode-test-identifiers()
737708
"Proper highlighting for identifiers including their namespace."
738-
(with-php-mode-test ("identifiers.php")
739-
(let ((variables '("UnqualifiedClassName"
740-
"FullyQualifiedClassName"
741-
"SpaceName")))
742-
(dolist (variable variables)
743-
(search-forward variable)
744-
(goto-char (match-beginning 0))
745-
(should (eq 'font-lock-type-face
746-
(get-text-property (point) 'face)))))
747-
(search-forward "var")
748-
(goto-char (match-beginning 0))
749-
(should (eq 'php-variable-name
750-
(get-text-property (point) 'face)))
751-
(search-forward "syntaxerror")
752-
(goto-char (match-beginning 0))
753-
(should (not (eq 'php-variable-name
754-
(get-text-property (point) 'face))))
755-
(search-forward "ClassName")
756-
(goto-char (match-beginning 0))
757-
(should (eq 'php-constant
758-
(get-text-property (point) 'face)))
759-
(search-forward "SpaceName")
760-
(goto-char (match-beginning 0))
761-
(should (eq 'php-constant
762-
(get-text-property (point) 'face)))
763-
(search-forward-regexp "\\\\My_\\(Class\\)")
764-
(should (eq 'php-constant
765-
(get-text-property (match-beginning 0) 'face)))
766-
(should (eq 'php-constant
767-
(get-text-property (match-beginning 1) 'face)))))
709+
(with-php-mode-test ("identifiers.php" :faces t)))
768710

769711
(ert-deftest php-mode-test-variables ()
770712
"Proper highlighting for variables."
@@ -789,25 +731,7 @@ style from Drupal."
789731

790732
(ert-deftest php-mode-test-arrays()
791733
"Proper highlighting for array keyword."
792-
(with-php-mode-test ("arrays.php")
793-
;; Keyword situations
794-
(let ((variables '("array();"
795-
"array()")))
796-
(dolist (variable variables)
797-
(search-forward variable)
798-
(goto-char (match-beginning 0))
799-
(should (eq 'php-keyword
800-
(get-text-property (point) 'face)))))
801-
;; Type situations
802-
(let ((variables '("(array)"
803-
"array $byValue"
804-
"array &$byReference"
805-
": array")))
806-
(dolist (variable variables)
807-
(search-forward variable)
808-
(search-backward "array")
809-
(should (eq 'font-lock-type-face
810-
(get-text-property (point) 'face)))))))
734+
(with-php-mode-test ("arrays.php" :faces t)))
811735

812736
(ert-deftest php-mode-test-issue-174 ()
813737
"Test escaped quotes in string literals"
@@ -863,10 +787,7 @@ style from Drupal."
863787

864788
(ert-deftest php-mode-test-issue-197 ()
865789
"Test highlighting of member and function names (should not have type face)"
866-
(with-php-mode-test ("issue-197.php")
867-
(while (search-forward "$test->" nil t)
868-
(should-not (eq 'font-lock-type-face
869-
(get-text-property (point) 'face))))))
790+
(with-php-mode-test ("issue-197.php" :faces t)))
870791

871792
(ert-deftest php-mode-test-issue-200 ()
872793
"Test highlighting and elimination of extraneous whitespace in PSR-2 mode"
@@ -877,18 +798,7 @@ style from Drupal."
877798

878799
(ert-deftest php-mode-test-issue-201 ()
879800
"Test highlighting of special variables"
880-
(with-php-mode-test ("issue-201.php")
881-
(search-forward "Start:")
882-
(search-forward "$this")
883-
(should (eq 'php-$this (get-text-property (- (point) 1) 'face)))
884-
(search-forward "$that")
885-
(should (eq 'php-$this (get-text-property (- (point) 1) 'face)))
886-
(search-forward "self")
887-
(should (eq 'php-keyword (get-text-property (- (point) 1) 'face)))
888-
(search-forward "static")
889-
(should (eq 'php-keyword (get-text-property (- (point) 1) 'face)))
890-
(search-forward "parent")
891-
(should (eq 'php-keyword (get-text-property (- (point) 1) 'face)))))
801+
(with-php-mode-test ("issue-201.php" :faces t)))
892802

893803
(ert-deftest php-mode-test-issue-211 ()
894804
"Test indentation of string concatination"
@@ -960,30 +870,11 @@ style from Drupal."
960870

961871
(ert-deftest psr-5-style-tag-annotation ()
962872
"PSR-5 style tag annotation."
963-
(with-php-mode-test ("annotation.php")
964-
(re-search-forward "@\\([^\\]+\\)\\\\\\([^\\]+\\)\\\\\\([^\r\n]+\\)")
965-
(cl-loop for i from 1 to 3
966-
do
967-
(progn
968-
(should (equal (get-text-property (match-beginning i) 'face)
969-
'(php-doc-annotation-tag font-lock-doc-face)))
970-
(should (equal (get-text-property (1- (match-end i)) 'face)
971-
'(php-doc-annotation-tag font-lock-doc-face)))))
972-
973-
(search-forward "@property-read")
974-
(should (equal (get-text-property (match-beginning 0) 'face)
975-
'(php-doc-annotation-tag font-lock-doc-face)))
976-
(should (equal (get-text-property (1- (match-end 0)) 'face)
977-
'(php-doc-annotation-tag font-lock-doc-face)))))
873+
(with-php-mode-test ("annotation.php" :faces t)))
978874

979875
(ert-deftest php-mode-test-issue-305 ()
980876
"Test highlighting variables which contains 'this' or 'that'."
981-
(with-php-mode-test ("issue-305.php")
982-
(search-forward "Start:")
983-
(search-forward "$this")
984-
(should-not (eq 'php-constant (get-text-property (- (point) 1) 'face)))
985-
(search-forward "$that")
986-
(should-not (eq 'php-constant (get-text-property (- (point) 1) 'face)))))
877+
(with-php-mode-test ("issue-305.php" :faces t)))
987878

988879
(ert-deftest php-mode-test-issue-307 ()
989880
"Activating php-mode should not mark the buffer as modified."
@@ -1025,56 +916,7 @@ style from Drupal."
1025916

1026917
(ert-deftest php-mode-test-type-hints ()
1027918
"Test highlighting of type hints and return types."
1028-
(with-php-mode-test ("type-hints.php")
1029-
(search-forward "void")
1030-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face)))
1031-
(dotimes (num 4)
1032-
(search-forward "string")
1033-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1034-
(dotimes (num 4)
1035-
(search-forward "int")
1036-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1037-
(dotimes (num 4)
1038-
(search-forward "float")
1039-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1040-
(dotimes (num 4)
1041-
(search-forward "bool")
1042-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1043-
(dotimes (num 4)
1044-
(search-forward "array")
1045-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1046-
(dotimes (num 4)
1047-
(search-forward "stdClass")
1048-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1049-
(dotimes (num 4)
1050-
(search-forward "\\path\\to\\my\\Object")
1051-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))
1052-
;; Parameters on different lines
1053-
(let ((variables '("string"
1054-
"int"
1055-
"bool"
1056-
"array"
1057-
"stdClass"
1058-
"\\path\\to\\my\\Object"
1059-
"void")))
1060-
(dolist (variable variables)
1061-
(search-forward variable)
1062-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face)))))
1063-
;; Return types on different lines
1064-
(search-forward "void")
1065-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face)))
1066-
(let ((variables '("string"
1067-
"int"
1068-
"float"
1069-
"bool"
1070-
"array"
1071-
"stdClass"
1072-
"\\path\\to\\my\\Object"
1073-
)))
1074-
(dolist (variable variables)
1075-
(dotimes (num 2)
1076-
(search-forward variable)
1077-
(should (eq 'font-lock-type-face (get-text-property (- (point) 1) 'face))))))))
919+
(with-php-mode-test ("type-hints.php" :faces t)))
1078920

1079921
(ert-deftest php-project-root ()
1080922
(should (string= (abbreviate-file-name default-directory)

tests/annotation.php.faces

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . font-lock-preprocessor-face)
3+
("\n\n")
4+
("/**\n * PSR-5 style tag annotation\n */" . font-lock-doc-face)
5+
("\n\n")
6+
("/**\n * " . font-lock-doc-face)
7+
("@MyProject\\Annotations\\Foobarable" php-doc-annotation-tag font-lock-doc-face)
8+
("\n */" . font-lock-doc-face)
9+
("\n")
10+
("class" . php-keyword)
11+
(" ")
12+
("User" . font-lock-type-face)
13+
("\n{\n}\n\n")
14+
("/**\n * " . font-lock-doc-face)
15+
("@property-read" php-doc-annotation-tag font-lock-doc-face)
16+
(" " . font-lock-doc-face)
17+
("string" font-lock-type-face php-string font-lock-doc-face)
18+
(" " . font-lock-doc-face)
19+
("$" php-doc-variable-sigil font-lock-doc-face)
20+
("myProperty" php-variable-name font-lock-doc-face)
21+
("\n */" . font-lock-doc-face)
22+
("\n")
23+
("class" . php-keyword)
24+
(" ")
25+
("Child" . font-lock-type-face)
26+
(" ")
27+
("extends" . php-keyword)
28+
(" ")
29+
("Parent_" . font-lock-type-face)
30+
("\n{\n}\n"))

tests/arrays.php.faces

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . font-lock-preprocessor-face)
3+
("\n\n")
4+
("// " . font-lock-comment-delimiter-face)
5+
("Array should be treated like a normal keyword\n" . font-lock-comment-face)
6+
("$" . php-variable-sigil)
7+
("test" . php-variable-name)
8+
(" = ")
9+
("array" . php-keyword)
10+
("();\n\n")
11+
("$" . php-variable-sigil)
12+
("test" . php-variable-name)
13+
(" = ")
14+
("function" . php-keyword)
15+
("(")
16+
("$" . php-variable-sigil)
17+
("test" . php-variable-name)
18+
(" = ")
19+
("array" . php-keyword)
20+
("()) {\n};\n\n")
21+
("// " . font-lock-comment-delimiter-face)
22+
("Array should be treated as a type instead of a keyword in the following situations:\n" . font-lock-comment-face)
23+
("// " . font-lock-comment-delimiter-face)
24+
("- cast, should look like `(int)`\n" . font-lock-comment-face)
25+
("// " . font-lock-comment-delimiter-face)
26+
("- type hint, should look like `int $var`\n" . font-lock-comment-face)
27+
("// " . font-lock-comment-delimiter-face)
28+
("- return type, should look like `: int`\n" . font-lock-comment-face)
29+
("$" . php-variable-sigil)
30+
("test" . php-variable-name)
31+
(" = (")
32+
("array" . font-lock-type-face)
33+
(")")
34+
("$" . php-variable-sigil)
35+
("test" . php-variable-name)
36+
(";\n\n")
37+
("$" . php-variable-sigil)
38+
("test" . php-variable-name)
39+
(" = ")
40+
("function" . php-keyword)
41+
("(")
42+
("array" . font-lock-type-face)
43+
(" ")
44+
("$" . php-variable-sigil)
45+
("byValue" . php-variable-name)
46+
(", ")
47+
("array" . font-lock-type-face)
48+
(" &")
49+
("$" . php-variable-sigil)
50+
("byReference" . php-variable-name)
51+
("): ")
52+
("array" . font-lock-type-face)
53+
(" {\n};\n"))

0 commit comments

Comments
 (0)