aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/ert-font-lock.el27
-rw-r--r--test/lisp/emacs-lisp/ert-font-lock-tests.el47
2 files changed, 60 insertions, 14 deletions
diff --git a/lisp/emacs-lisp/ert-font-lock.el b/lisp/emacs-lisp/ert-font-lock.el
index e77c8945dc3..c6fd65e1507 100644
--- a/lisp/emacs-lisp/ert-font-lock.el
+++ b/lisp/emacs-lisp/ert-font-lock.el
@@ -40,31 +40,34 @@
40(require 'pcase) 40(require 'pcase)
41 41
42(defconst ert-font-lock--face-symbol-re 42(defconst ert-font-lock--face-symbol-re
43 (rx (one-or-more (or alphanumeric "-" "_" "."))) 43 (rx (+ (or alphanumeric "-" "_" "." "/")))
44 "A face symbol matching regex.") 44 "A face symbol matching regex.
45The regexp cannot use character classes as these can be redefined by the
46major mode of the host language.")
45 47
46(defconst ert-font-lock--face-symbol-list-re 48(defconst ert-font-lock--face-symbol-list-re
47 (rx "(" 49 (rx "("
48 (* whitespace) 50 (* whitespace)
49 (one-or-more 51 (? (regexp ert-font-lock--face-symbol-re))
50 (seq (regexp ert-font-lock--face-symbol-re) 52 (* (+ whitespace)
51 (* whitespace))) 53 (regexp ert-font-lock--face-symbol-re))
54 (* whitespace)
52 ")") 55 ")")
53 "A face symbol list matching regex.") 56 "A face symbol list matching regex.")
54 57
55(defconst ert-font-lock--assertion-line-re 58(defconst ert-font-lock--assertion-line-re
56 (rx 59 (rx
57 ;; leading column assertion (arrow/caret) 60 ;; leading column assertion (arrow/caret)
58 (group (or "^" "<-")) 61 (group-n 1 (or "^" "<-"))
59 (zero-or-more whitespace) 62 (* whitespace)
60 ;; possible to have many carets on an assertion line 63 ;; possible to have many carets on an assertion line
61 (group (zero-or-more (seq "^" (zero-or-more whitespace)))) 64 (group-n 2 (* "^" (* whitespace)))
62 ;; optional negation of the face specification 65 ;; optional negation of the face specification
63 (group (optional "!")) 66 (group-n 3 (optional "!"))
64 (zero-or-more whitespace) 67 (* whitespace)
65 ;; face symbol name or a list of symbols 68 ;; face symbol name or a list of symbols
66 (group (or (regexp ert-font-lock--face-symbol-re) 69 (group-n 4 (or (regexp ert-font-lock--face-symbol-re)
67 (regexp ert-font-lock--face-symbol-list-re)))) 70 (regexp ert-font-lock--face-symbol-list-re))))
68 "An ert-font-lock assertion line regex.") 71 "An ert-font-lock assertion line regex.")
69 72
70(defun ert-font-lock--validate-major-mode (mode) 73(defun ert-font-lock--validate-major-mode (mode)
diff --git a/test/lisp/emacs-lisp/ert-font-lock-tests.el b/test/lisp/emacs-lisp/ert-font-lock-tests.el
index fa2e5dc4db7..33ef2c52288 100644
--- a/test/lisp/emacs-lisp/ert-font-lock-tests.el
+++ b/test/lisp/emacs-lisp/ert-font-lock-tests.el
@@ -44,13 +44,56 @@
44 (goto-char (point-min)) 44 (goto-char (point-min))
45 ,@body)) 45 ,@body))
46 46
47(defun ert-font-lock--wrap-begin-end (re)
48 (concat "^" re "$"))
49
50;;; Regexp tests
51;;;
52
53(ert-deftest test-regexp--face-symbol-re ()
54 (let ((re (ert-font-lock--wrap-begin-end
55 ert-font-lock--face-symbol-re)))
56 (should (string-match-p re "font-lock-keyword-face"))
57 (should (string-match-p re "-face"))
58 (should (string-match-p re "weird-package/-face"))
59 (should (string-match-p re "-"))
60 (should (string-match-p re "font-lock.face"))
61 (should-not (string-match-p re "face suffix-with"))
62 (should-not (string-match-p re "("))))
63
64(ert-deftest test-regexp--face-symbol-list-re ()
65 (let ((re (ert-font-lock--wrap-begin-end
66 ert-font-lock--face-symbol-list-re)))
67 (should (string-match-p re "(face1 face2)"))
68 (should (string-match-p re "(face1)"))
69 (should (string-match-p re "()"))
70 (should-not (string-match-p re ")"))
71 (should-not (string-match-p re "("))))
72
73(ert-deftest test-regexp--assertion-line-re ()
74 (let ((re (ert-font-lock--wrap-begin-end
75 ert-font-lock--assertion-line-re)))
76 (should (string-match-p re "^ something-face"))
77 (should (string-match-p re "^ !something-face"))
78 (should (string-match-p re "^ (face1 face2)"))
79 (should (string-match-p re "^ !(face1 face2)"))
80 (should (string-match-p re "^ ()"))
81 (should (string-match-p re "^ !()"))
82 (should (string-match-p re "^ nil"))
83 (should (string-match-p re "^ !nil"))
84 (should (string-match-p re "<- something-face"))
85 (should (string-match-p re "<- ^ something-face"))
86 (should (string-match-p re "^^ ^ something-face"))
87 (should (string-match-p re "^ ^something-face"))
88 (should-not (string-match-p re "^ <- ^something-face"))))
89
47;;; Comment parsing tests 90;;; Comment parsing tests
48;; 91;;
49 92
50(ert-deftest test-line-comment-p--fundamental () 93(ert-deftest test-line-comment-p--fundamental ()
51 (with-temp-buffer-str-mode fundamental-mode 94 (with-temp-buffer-str-mode fundamental-mode
52 "// comment\n" 95 "// comment\n"
53 (should-not (ert-font-lock--line-comment-p)))) 96 (should-not (ert-font-lock--line-comment-p))))
54 97
55(ert-deftest test-line-comment-p--emacs-lisp () 98(ert-deftest test-line-comment-p--emacs-lisp ()
56 (with-temp-buffer-str-mode emacs-lisp-mode 99 (with-temp-buffer-str-mode emacs-lisp-mode