Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
325 changes: 5 additions & 320 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -370,326 +370,6 @@ style from Drupal."
"Closure indentation."
(with-php-mode-test ("issue-145.php" :indent t)))

(ert-deftest php-mode-test-comments ()
"Proper highlighting for comments and doc-blocks."
(with-php-mode-test ("comments.php")
(search-forward "/**")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-doc-face))

(search-forward "@copyright")
(should (equal (get-text-property (match-beginning 0) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))
(search-forward-regexp "@link +\\(https://github.com/emacs-php/php-mode\\)")
(should (equal (get-text-property (match-beginning 1) 'face)
'(link font-lock-doc-face)))
(search-forward-regexp "@package +\\(Emacs\\\\PHPMode\\)")
(should (equal (get-text-property (match-beginning 0) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face)
'(php-string font-lock-doc-face)))


(search-forward-regexp "// \\(@annotation This is NOT annotation. 1\\)")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-delimiter-face))
(should (eq (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))

(search-forward-regexp "\\* \\(@annotation This is NOT annotation. 2\\)")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-face))
(should (eq (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))

;; Comment outed doc-block
(search-forward "/**")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-face))

(search-forward-regexp "\\* \\(@annotation This is NOT annotation. 3\\)")
(should (equal (get-text-property (match-beginning 0) 'face)
'font-lock-comment-face))

(should (equal (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))

(search-forward "class CommentOuted")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-face))

;; Class level doc-comment
(search-forward-regexp "{@internal \\(Description\\)}")
(should (equal (get-text-property (match-beginning 0) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face)
'(php-string php-doc-annotation-tag font-lock-doc-face)))

(should (equal (get-text-property (1- (match-end 0)) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-end 0) 'face)
'font-lock-doc-face))

(search-forward-regexp "@property\\(-read\\)")
(should (equal (get-text-property (match-beginning 0) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))

(should (equal (get-text-property (match-beginning 1) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))

(search-forward-regexp "@ORM\\(\\\\Table\\)")
(should (equal (get-text-property (match-beginning 0) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))

(search-forward-regexp "@var \\(string\\) \\(sample property doc-comment\\)")
(should (equal (get-text-property (match-beginning 0) 'face)
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face)
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face)
'font-lock-doc-face))

(search-forward-regexp "// \\(comment in after code\\)")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-delimiter-face))
(should (eq (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))

(search-forward-regexp "@var \\(string\\)|\\(bool\\)|\\(array\\)\\([[]]\\)|\\(ArrayObject\\) \\*/$")
(should (equal (get-text-property (match-beginning 0) 'face) ;; matches `@'
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `s'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-end 1) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `b'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-end 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `a'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 4) 'face) ;; matches `['
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-end 4) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 5) 'face) ;; matches `A'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-end 5) 'face) ;; matches ` '
' font-lock-doc-face))

(search-forward-regexp "// \\(one-line comment\\)")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-delimiter-face))
(should (eq (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))

(search-forward-regexp "// \\(@annotation This is NOT annotation. 4\\)")
(should (eq (get-text-property (match-beginning 0) 'face)
'font-lock-comment-delimiter-face))
(should (eq (get-text-property (match-beginning 1) 'face)
'font-lock-comment-face))

(search-forward-regexp "@var \\(int\\) \\(internal linter variable\\) \\*/$")
(should (equal (get-text-property (match-beginning 0) 'face) ;; matches `@'
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-end 1) 'face) ;; matches ` '
'font-lock-doc-face))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `i'
'font-lock-doc-face))
(should (equal (get-text-property (match-end 2) 'face) ;; matches ` '
'font-lock-doc-face))

(search-forward-regexp "@throws \\(\\\\RuntimeException\\)$")
(should (equal (get-text-property (match-beginning 0) 'face) ;; matches `@'
'(php-doc-annotation-tag font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `\'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `R'
'(php-string font-lock-doc-face)))))

(ert-deftest php-mode-test-comment-return-type ()
"Proper highlighting for type annotation in doc-block."
(with-php-mode-test ("doc-comment-return-type.php")
;; Test for premitive type (int)
(search-forward-regexp "@return \\(int\\) +\\(A integer value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\?int\\) +\\(A nullable integer value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `?'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\int\\[\\]\\) +\\(A list of integer values\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (1- (match-end 1)) 'face) ;; matches `]'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

;; Test for class type (DateTime)
(search-forward-regexp "@return \\(DateTime\\) +\\(A DateTime object value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `D'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\?DateTime\\) +\\(A nullable DateTime object value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `?'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `D'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\DateTime\\[]\\) +\\(A list of DateTime object values\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `D'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1- (match-end 1)) 'face) ;; matches `]'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

;; Test for class type (stdClass)
(search-forward-regexp "@return \\(stdClass\\) +\\(A stdClass object value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `s'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\?stdClass\\) +\\(A nullable stdClass object value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `?'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `s'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(stdClass\\[]\\) +\\(A list of stdClass object values\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `s'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1- (match-end 1)) 'face) ;; matches `]'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

;; Test for class type (\App\User)
(search-forward-regexp "@return \\(\\\\App\\\\User\\) +\\(A \\\\App\\\\User object value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `\'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `A'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\?\\\\App\\\\User\\) +\\(A nullable \\\\App\\\\User object value\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `?'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `\\'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\\\App\\\\User\\[]\\) +\\(A list of \\\\App\\\\User object values\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `\'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1- (match-end 1)) 'face) ;; matches `]'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `A'
'font-lock-doc-face))

;; Test for multiple types
(search-forward-regexp "@return \\(int\\)\\(|\\)\\(string\\) +\\(Multiple types by int and string\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `s'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 4) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(int\\[]\\)\\(|\\)\\(string\\) +\\(Multiple types by list of int and string\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (1- (match-end 1)) 'face) ;; matches `]'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `s'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 4) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(int\\)\\(|\\)\\(stdClass\\) +\\(Multiple types by int and stdClass\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `s'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 4) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(int\\)\\(|\\)\\(\\\\App\\\\User\\) +\\(Multiple types by int and \\\\App\\\\User\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `\'
'(php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 4) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(DateTime\\)\\(|\\)\\(int\\) +\\(Multiple types by DateTime and int\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `D'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 4) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\\\App\\\\User\\)\\(|\\)\\(int\\) +\\(Multiple types by \\\\App\\\\User and int\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `\'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `A'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 2) 'face) ;; matches `|'
'(php-string font-lock-doc-face)))
(should (equal (get-text-property (match-beginning 3) 'face) ;; matches `i'
'(font-lock-type-face php-string font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 4) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\$this\\) +\\(this is special variable\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `$'
'(php-doc-$this-sigil php-doc-variable-sigil font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `t'
'(php-doc-$this php-variable-name font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `M'
'font-lock-doc-face))

(search-forward-regexp "@return \\(\\$that\\) +\\(that is NOT special variable\\)")
(should (equal (get-text-property (match-beginning 1) 'face) ;; matches `$'
'(php-doc-variable-sigil font-lock-doc-face)))
(should (equal (get-text-property (1+ (match-beginning 1)) 'face) ;; matches `t'
'(php-variable-name font-lock-doc-face)))
(should (eq (get-text-property (match-beginning 2) 'face) ;; matches `M'
'font-lock-doc-face))
))

(ert-deftest php-mode-test-constants ()
"Proper highlighting for constants."
(custom-set-variables '(php-extra-constants (quote ("extraconstant"))))
Expand Down Expand Up @@ -987,6 +667,11 @@ Meant for `php-mode-test-issue-503'."

(ert-deftest php-mode-test-lang ()
"Test highlighting for language constructs."
(with-php-mode-test ("comments.php"
:faces (if (eq emacs-major-version 24)
".24.faces"
t)))
(with-php-mode-test ("doc-comment-return-type.php" :faces t))
(with-php-mode-test ("lang/types/cast.php" :faces t))
(with-php-mode-test ("lang/types/function.php" :faces t))
(with-php-mode-test ("lang/types/keywords.php" :faces t))
Expand Down
Loading