From d57587b88a38115e5364ddc781ceba5165acead1 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 12 May 2019 13:50:44 +0900 Subject: [PATCH 1/3] Fix indentation --- php-mode-test.el | 102 +++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/php-mode-test.el b/php-mode-test.el index b0f0114b..78d9fcd3 100644 --- a/php-mode-test.el +++ b/php-mode-test.el @@ -43,9 +43,9 @@ (c-after-font-lock-init) (defvar php-mode-test-dir (expand-file-name "tests" - (if load-file-name - (file-name-directory load-file-name) - default-directory)) + (if load-file-name + (file-name-directory load-file-name) + default-directory)) "Directory containing the `php-mode' test files.") (defvar php-mode-test-valid-magics '(indent) @@ -178,8 +178,8 @@ The next character after \">We\" is a single quote. It should not have a string face." :expected-result :failed (with-php-mode-test ("issue-9.php") - (search-forward ">We") - (forward-char) ;; Jump to after the opening apostrophe + (search-forward ">We") + (forward-char) ;; Jump to after the opening apostrophe (should-not (eq (get-text-property (point) 'face) 'php-string)))) @@ -234,10 +234,10 @@ Gets the face of the text after the comma." This applies for both single and double quotes." (with-php-mode-test ("issue-21.php") (while (search-forward "#" nil t) - (while (not (looking-at "\n")) - (should (eq (get-text-property (point) 'face) - 'font-lock-comment-face)) - (forward-char))))) + (while (not (looking-at "\n")) + (should (eq (get-text-property (point) 'face) + 'font-lock-comment-face)) + (forward-char))))) (ert-deftest php-mode-test-issue-27 () "Indentation in a file with a shebang." @@ -268,22 +268,22 @@ an error." (ert-deftest php-mode-test-issue-53 () "Check if whitespace effects are undone when changing coding style from Drupal." - (with-php-mode-test - ("issue-53.php") - (search-forward "return $this->bar;") - ;; the file written to has no significance, only the buffer - (let ((tmp-filename (concat (make-temp-name temporary-file-directory) ".php"))) - (dolist (mode '(pear wordpress symfony2)) - (php-set-style "drupal") - (php-set-style (symbol-name mode)) - (should-not show-trailing-whitespace) - (php-set-style "psr2") - (php-set-style (symbol-name mode)) - (should-not show-trailing-whitespace) - - (php-set-style "drupal") - (write-file tmp-filename) - (should (looking-at-p "$")))))) + (with-php-mode-test ("issue-53.php") + (search-forward "return $this->bar;") + ;; the file written to has no significance, only the buffer + (let ((tmp-filename (concat (make-temp-name temporary-file-directory) ".php"))) + (dolist (mode '(pear wordpress symfony2)) + (php-set-style "drupal") + (php-set-style (symbol-name mode)) + (should (eq nil show-trailing-whitespace)) + (php-set-style "psr2") + (php-set-style (symbol-name mode)) + (should (eq nil show-trailing-whitespace)) + + (php-set-style "drupal") + (write-file tmp-filename) + (should (eq t show-trailing-whitespace)) + (should (looking-at-p "$")))))) (ert-deftest php-mode-test-issue-73 () "The `delete-indentation' function should work properly for PHP. @@ -309,15 +309,14 @@ style from Drupal." (ert-deftest php-mode-test-issue-83 () "All static method should appear on imenu whether 'static' keyword is placed before or after visibility" - (with-php-mode-test - ("issue-83.php") - (let* ((index-alist (imenu--make-index-alist)) - (public-methods (mapcar 'car (cdr (assoc "Public Methods" index-alist)))) - (all-methods (mapcar 'car (cdr (assoc "All Methods" index-alist))))) - (should (member "staticBeforeVisibility" public-methods)) - (should (member "staticBeforeVisibility" all-methods)) - (should (member "staticAfterVisibility" public-methods)) - (should (member "staticAfterVisibility" all-methods))))) + (with-php-mode-test ("issue-83.php") + (let* ((index-alist (imenu--make-index-alist)) + (public-methods (mapcar 'car (cdr (assoc "Public Methods" index-alist)))) + (all-methods (mapcar 'car (cdr (assoc "All Methods" index-alist))))) + (should (member "staticBeforeVisibility" public-methods)) + (should (member "staticBeforeVisibility" all-methods)) + (should (member "staticAfterVisibility" public-methods)) + (should (member "staticAfterVisibility" all-methods))))) (ert-deftest php-mode-test-issue-99 () "Proper indentation for 'foreach' statements without braces." @@ -340,14 +339,14 @@ style from Drupal." (ert-deftest php-mode-test-issue-124 () "Proper syntax propertizing when a quote appears in a heredoc." (with-php-mode-test ("issue-124.php" :indent t) - (search-forward "Start of heredoc") - ;; The heredoc should be recognized as a string. - (dolist (syntax (c-guess-basic-syntax)) - (should (eq (car syntax) 'string))) - (search-forward "function bar") - ;; After the heredoc should *not* be recognized as a string. - (dolist (syntax (c-guess-basic-syntax)) - (should (not (eq (car syntax) 'string)))))) + (search-forward "Start of heredoc") + ;; The heredoc should be recognized as a string. + (dolist (syntax (c-guess-basic-syntax)) + (should (eq (car syntax) 'string))) + (search-forward "function bar") + ;; After the heredoc should *not* be recognized as a string. + (dolist (syntax (c-guess-basic-syntax)) + (should (not (eq (car syntax) 'string)))))) (ert-deftest php-mode-test-issue-136 () "Proper highlighting for variable interpolation." @@ -964,16 +963,15 @@ Meant for `php-mode-test-issue-503'." (ert-deftest php-mode-test-issue-503 () "Function `php-beginning-of-defun' should return non-nil on success." - (with-php-mode-test - ("issue-503.php") - (php-mode) - (goto-char (point-max)) - (should (eq (php-mode-test-in-function-p) nil)) - (should (eq (php-mode-test-in-function-p (1- (point))) t)) - (should (eq (php-mode-test-in-function-p 1) nil)) - (should (eq (php-mode-test-in-function-p 24) t)) - (goto-char (point-min)) - (should (eq (php-mode-test-in-function-p nil) nil)))) + (with-php-mode-test ("issue-503.php") + (php-mode) + (goto-char (point-max)) + (should (eq (php-mode-test-in-function-p) nil)) + (should (eq (php-mode-test-in-function-p (1- (point))) t)) + (should (eq (php-mode-test-in-function-p 1) nil)) + (should (eq (php-mode-test-in-function-p 24) t)) + (goto-char (point-min)) + (should (eq (php-mode-test-in-function-p nil) nil)))) (ert-deftest php-mode-test-php74-arrow-fn () "Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4." From 9ab0dcf58a4e8eb1a7ef771803f5d58166d6633b Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 12 May 2019 13:53:16 +0900 Subject: [PATCH 2/3] Add .editorconfig for test directory --- tests/.editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/.editorconfig diff --git a/tests/.editorconfig b/tests/.editorconfig new file mode 100644 index 00000000..14a1b3b1 --- /dev/null +++ b/tests/.editorconfig @@ -0,0 +1,11 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = false + +# Unix-style newlines with a newline ending every file +[*.php] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false From 983fb5a79f4c2ebbb860a1847b37444ea2840771 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 12 May 2019 14:01:46 +0900 Subject: [PATCH 3/3] Clarification of the condition under test --- php-mode-test.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/php-mode-test.el b/php-mode-test.el index 78d9fcd3..1dba70cf 100644 --- a/php-mode-test.el +++ b/php-mode-test.el @@ -275,14 +275,17 @@ style from Drupal." (dolist (mode '(pear wordpress symfony2)) (php-set-style "drupal") (php-set-style (symbol-name mode)) - (should (eq nil show-trailing-whitespace)) + (should (equal (list "drupal" mode nil) + (list "drupal" mode show-trailing-whitespace))) (php-set-style "psr2") (php-set-style (symbol-name mode)) - (should (eq nil show-trailing-whitespace)) + (should (equal (list "psr2" mode nil) + (list "psr2" mode show-trailing-whitespace))) (php-set-style "drupal") (write-file tmp-filename) - (should (eq t show-trailing-whitespace)) + (should (equal (list "drupal-after-write" mode t) + (list "drupal-after-write" mode show-trailing-whitespace))) (should (looking-at-p "$")))))) (ert-deftest php-mode-test-issue-73 ()