Skip to content

Commit 817ac84

Browse files
authored
Merge pull request #707 from emacs-php/refactor/test-magic-comparison
Refactor :magic test
2 parents 6f9a471 + 9aecbf0 commit 817ac84

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tests/php-mode-test.el

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,24 @@ These are the ###php-mode-test### comments. Valid magics are
6363
listed in `php-mode-test-valid-magics'; no other directives will
6464
be processed."
6565
(cl-letf (((symbol-function 'indent)
66-
(lambda (offset) (equal (current-indentation) offset))))
66+
(lambda (offset)
67+
(let ((current-offset (current-indentation)))
68+
(unless (eq current-offset offset)
69+
(list :line (line-number-at-pos)
70+
:expected offset
71+
:actual current-offset))))))
6772
(let (directives answers)
6873
(save-excursion
6974
(goto-char (point-min))
70-
(while (re-search-forward php-mode-test-magic-regexp nil t)
71-
(setq directives (read (buffer-substring (match-beginning 1)
72-
(match-end 1))))
73-
(setq answers
74-
(append (mapcar (lambda (curr)
75-
(let ((fn (car curr))
76-
(args (mapcar 'eval (cdr-safe curr))))
77-
(if (memq fn php-mode-test-valid-magics)
78-
(apply fn args))))
79-
directives)
80-
answers))))
81-
answers)))
75+
(cl-loop while (re-search-forward php-mode-test-magic-regexp nil t)
76+
for directives = (read (buffer-substring (match-beginning 1) (match-end 1)))
77+
for result = (mapcar (lambda (expr)
78+
(let ((fn (car expr))
79+
(args (mapcar 'eval (cdr-safe expr))))
80+
(if (memq fn php-mode-test-valid-magics)
81+
(apply fn args))))
82+
directives)
83+
append (cl-remove-if #'null result))))))
8284

8385
(defun php-mode-test--buffer-face-list (buffer)
8486
"Return list of (STRING . FACE) from `BUFFER'."
@@ -154,8 +156,9 @@ file name and check that the faces of the fonts in the buffer match."
154156
,(if indent
155157
'(let ((inhibit-message t)) (indent-region (point-min) (point-max))))
156158
,(if magic
157-
'(should (cl-reduce (lambda (l r) (and l r))
158-
(php-mode-test-process-magics))))
159+
`(should (equal
160+
(cons ,file nil)
161+
(cons ,file (php-mode-test-process-magics)))))
159162
,(if faces
160163
`(should (equal
161164
(cons ,file

0 commit comments

Comments
 (0)