@@ -78,7 +78,35 @@ be processed."
7878 answers))))
7979 answers)))
8080
81- (cl-defmacro with-php-mode-test ((file &key style indent magic custom) &rest body )
81+ (defun php-mode-test--buffer-face-list (buffer )
82+ " Return list of (STRING . FACE) from `BUFFER' ."
83+ (with-current-buffer buffer
84+ (save-excursion
85+ (goto-char (point-min ))
86+ (let (retval begin-pos last-face current-face str)
87+ (setq last-face (get-text-property (point ) 'face ))
88+ (setq begin-pos (point ))
89+ (forward-char 1 )
90+
91+ (while (< (point ) (point-max ))
92+ (setq current-face (get-text-property (point ) 'face ))
93+ (unless (equal current-face last-face)
94+ (setq str (buffer-substring-no-properties begin-pos (point )))
95+ (setq retval (nconc retval (list (cons str last-face))))
96+ (setq begin-pos (point ))
97+ (setq last-face current-face))
98+ (forward-char 1 ))
99+ (setq str (buffer-substring-no-properties begin-pos (point )))
100+ (nconc retval (list (cons str last-face)))))))
101+
102+ (defun php-mode-test--parse-list-file (file-path )
103+ " Return list from `FILE-PATH' ."
104+ (with-temp-buffer
105+ (insert-file-contents file-path)
106+ (let ((read-circle t ))
107+ (read (current-buffer )))))
108+
109+ (cl-defmacro with-php-mode-test ((file &key style indent magic custom faces) &rest body )
82110 " Set up environment for testing `php-mode' .
83111Execute BODY in a temporary buffer containing the contents of
84112FILE, in `php-mode' . Optional keyword `:style' can be used to set
@@ -95,7 +123,10 @@ The test will use the PHP style by default.
95123
96124If the `:custom' keyword is set, customized variables are not reset to
97125their default state prior to starting the test. Use this if the test should
98- run with specific customizations set."
126+ run with specific customizations set.
127+
128+ If the `:faces' keyword is set, read the file with `.faces' added to that
129+ file name and check that the faces of the fonts in the buffer match."
99130 (declare (indent 1 ))
100131 `(with-temp-buffer
101132 (insert-file-contents (expand-file-name , file php-mode-test-dir))
@@ -119,6 +150,11 @@ run with specific customizations set."
119150 ,(if magic
120151 '(should (cl-reduce (lambda (l r ) (and l r))
121152 (php-mode-test-process-magics))))
153+ ,(if faces
154+ `(should (equal
155+ (php-mode-test--parse-list-file
156+ (concat (expand-file-name , file php-mode-test-dir) " .faces" ))
157+ (php-mode-test--buffer-face-list (current-buffer )))))
122158 (goto-char (point-min ))
123159 (let ((case-fold-search nil ))
124160 ,@body )))
@@ -728,9 +764,9 @@ style from Drupal."
728764 (should (eq 'php-constant
729765 (get-text-property (match-beginning 1 ) 'face )))))
730766
731- (ert-deftest php-mode-test-variables()
767+ (ert-deftest php-mode-test-variables ()
732768 " Proper highlighting for variables."
733- (with-php-mode-test (" variables.php" )
769+ (with-php-mode-test (" variables.php" :faces t )
734770 (let ((variables '(" regularVariable"
735771 " variableVariable"
736772 " staticVariable" )))
0 commit comments