Skip to content

Commit a43be72

Browse files
authored
Merge pull request #516 from emacs-php/refactor/test-files
Refactor test files
2 parents d80a657 + 983fb5a commit a43be72

File tree

2 files changed

+64
-52
lines changed

2 files changed

+64
-52
lines changed

php-mode-test.el

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
(c-after-font-lock-init)
4444

4545
(defvar php-mode-test-dir (expand-file-name "tests"
46-
(if load-file-name
47-
(file-name-directory load-file-name)
48-
default-directory))
46+
(if load-file-name
47+
(file-name-directory load-file-name)
48+
default-directory))
4949
"Directory containing the `php-mode' test files.")
5050

5151
(defvar php-mode-test-valid-magics '(indent)
@@ -178,8 +178,8 @@ The next character after \">We\" is a single quote. It should not
178178
have a string face."
179179
:expected-result :failed
180180
(with-php-mode-test ("issue-9.php")
181-
(search-forward ">We")
182-
(forward-char) ;; Jump to after the opening apostrophe
181+
(search-forward ">We")
182+
(forward-char) ;; Jump to after the opening apostrophe
183183
(should-not (eq
184184
(get-text-property (point) 'face)
185185
'php-string))))
@@ -234,10 +234,10 @@ Gets the face of the text after the comma."
234234
This applies for both single and double quotes."
235235
(with-php-mode-test ("issue-21.php")
236236
(while (search-forward "#" nil t)
237-
(while (not (looking-at "\n"))
238-
(should (eq (get-text-property (point) 'face)
239-
'font-lock-comment-face))
240-
(forward-char)))))
237+
(while (not (looking-at "\n"))
238+
(should (eq (get-text-property (point) 'face)
239+
'font-lock-comment-face))
240+
(forward-char)))))
241241

242242
(ert-deftest php-mode-test-issue-27 ()
243243
"Indentation in a file with a shebang."
@@ -268,22 +268,25 @@ an error."
268268
(ert-deftest php-mode-test-issue-53 ()
269269
"Check if whitespace effects are undone when changing coding
270270
style from Drupal."
271-
(with-php-mode-test
272-
("issue-53.php")
273-
(search-forward "return $this->bar;")
274-
;; the file written to has no significance, only the buffer
275-
(let ((tmp-filename (concat (make-temp-name temporary-file-directory) ".php")))
276-
(dolist (mode '(pear wordpress symfony2))
277-
(php-set-style "drupal")
278-
(php-set-style (symbol-name mode))
279-
(should-not show-trailing-whitespace)
280-
(php-set-style "psr2")
281-
(php-set-style (symbol-name mode))
282-
(should-not show-trailing-whitespace)
283-
284-
(php-set-style "drupal")
285-
(write-file tmp-filename)
286-
(should (looking-at-p "$"))))))
271+
(with-php-mode-test ("issue-53.php")
272+
(search-forward "return $this->bar;")
273+
;; the file written to has no significance, only the buffer
274+
(let ((tmp-filename (concat (make-temp-name temporary-file-directory) ".php")))
275+
(dolist (mode '(pear wordpress symfony2))
276+
(php-set-style "drupal")
277+
(php-set-style (symbol-name mode))
278+
(should (equal (list "drupal" mode nil)
279+
(list "drupal" mode show-trailing-whitespace)))
280+
(php-set-style "psr2")
281+
(php-set-style (symbol-name mode))
282+
(should (equal (list "psr2" mode nil)
283+
(list "psr2" mode show-trailing-whitespace)))
284+
285+
(php-set-style "drupal")
286+
(write-file tmp-filename)
287+
(should (equal (list "drupal-after-write" mode t)
288+
(list "drupal-after-write" mode show-trailing-whitespace)))
289+
(should (looking-at-p "$"))))))
287290

288291
(ert-deftest php-mode-test-issue-73 ()
289292
"The `delete-indentation' function should work properly for PHP.
@@ -309,15 +312,14 @@ style from Drupal."
309312

310313
(ert-deftest php-mode-test-issue-83 ()
311314
"All static method should appear on imenu whether 'static' keyword is placed before or after visibility"
312-
(with-php-mode-test
313-
("issue-83.php")
314-
(let* ((index-alist (imenu--make-index-alist))
315-
(public-methods (mapcar 'car (cdr (assoc "Public Methods" index-alist))))
316-
(all-methods (mapcar 'car (cdr (assoc "All Methods" index-alist)))))
317-
(should (member "staticBeforeVisibility" public-methods))
318-
(should (member "staticBeforeVisibility" all-methods))
319-
(should (member "staticAfterVisibility" public-methods))
320-
(should (member "staticAfterVisibility" all-methods)))))
315+
(with-php-mode-test ("issue-83.php")
316+
(let* ((index-alist (imenu--make-index-alist))
317+
(public-methods (mapcar 'car (cdr (assoc "Public Methods" index-alist))))
318+
(all-methods (mapcar 'car (cdr (assoc "All Methods" index-alist)))))
319+
(should (member "staticBeforeVisibility" public-methods))
320+
(should (member "staticBeforeVisibility" all-methods))
321+
(should (member "staticAfterVisibility" public-methods))
322+
(should (member "staticAfterVisibility" all-methods)))))
321323

322324
(ert-deftest php-mode-test-issue-99 ()
323325
"Proper indentation for 'foreach' statements without braces."
@@ -340,14 +342,14 @@ style from Drupal."
340342
(ert-deftest php-mode-test-issue-124 ()
341343
"Proper syntax propertizing when a quote appears in a heredoc."
342344
(with-php-mode-test ("issue-124.php" :indent t)
343-
(search-forward "Start of heredoc")
344-
;; The heredoc should be recognized as a string.
345-
(dolist (syntax (c-guess-basic-syntax))
346-
(should (eq (car syntax) 'string)))
347-
(search-forward "function bar")
348-
;; After the heredoc should *not* be recognized as a string.
349-
(dolist (syntax (c-guess-basic-syntax))
350-
(should (not (eq (car syntax) 'string))))))
345+
(search-forward "Start of heredoc")
346+
;; The heredoc should be recognized as a string.
347+
(dolist (syntax (c-guess-basic-syntax))
348+
(should (eq (car syntax) 'string)))
349+
(search-forward "function bar")
350+
;; After the heredoc should *not* be recognized as a string.
351+
(dolist (syntax (c-guess-basic-syntax))
352+
(should (not (eq (car syntax) 'string))))))
351353

352354
(ert-deftest php-mode-test-issue-136 ()
353355
"Proper highlighting for variable interpolation."
@@ -964,16 +966,15 @@ Meant for `php-mode-test-issue-503'."
964966

965967
(ert-deftest php-mode-test-issue-503 ()
966968
"Function `php-beginning-of-defun' should return non-nil on success."
967-
(with-php-mode-test
968-
("issue-503.php")
969-
(php-mode)
970-
(goto-char (point-max))
971-
(should (eq (php-mode-test-in-function-p) nil))
972-
(should (eq (php-mode-test-in-function-p (1- (point))) t))
973-
(should (eq (php-mode-test-in-function-p 1) nil))
974-
(should (eq (php-mode-test-in-function-p 24) t))
975-
(goto-char (point-min))
976-
(should (eq (php-mode-test-in-function-p nil) nil))))
969+
(with-php-mode-test ("issue-503.php")
970+
(php-mode)
971+
(goto-char (point-max))
972+
(should (eq (php-mode-test-in-function-p) nil))
973+
(should (eq (php-mode-test-in-function-p (1- (point))) t))
974+
(should (eq (php-mode-test-in-function-p 1) nil))
975+
(should (eq (php-mode-test-in-function-p 24) t))
976+
(goto-char (point-min))
977+
(should (eq (php-mode-test-in-function-p nil) nil))))
977978

978979
(ert-deftest php-mode-test-php74-arrow-fn ()
979980
"Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4."

tests/.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = false
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*.php]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = false
11+
insert_final_newline = false

0 commit comments

Comments
 (0)