From 4b69ca57f51d9de8a29fd3880a76d8eff1fb42dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kruczyk?= Date: Wed, 18 Oct 2017 00:14:29 +0200 Subject: [PATCH 1/2] Simplify regexp literal --- typescript-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript-mode.el b/typescript-mode.el index 9d16f69..2591810 100644 --- a/typescript-mode.el +++ b/typescript-mode.el @@ -1871,7 +1871,7 @@ This performs fontification according to `typescript--class-styles'." ;; as the newline is escaped with \. Account for that in the regexp ;; below. (defconst typescript--regexp-literal - "[=(,:]\\(?:\\s-\\|\n\\)*\\(/\\)\\(?:\\\\/\\|[^/*]\\)\\(?:\\\\/\\|[^/]\\)*\\(/\\)" + "[=(,:]\\(?:\\s-\\|\n\\)*\\(/\\)[^/]*\\(/\\)" "Regexp matching a typescript regular expression literal. Match groups 1 and 2 are the characters forming the beginning and end of the literal.") From 393ac6db0fdd399bb12beb9e66ee0e3823d50675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kruczyk?= Date: Sun, 22 Oct 2017 13:53:37 +0200 Subject: [PATCH 2/2] add tests for regexp font locking --- typescript-mode-tests.el | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el index 6933d4f..4a9e4f0 100644 --- a/typescript-mode-tests.el +++ b/typescript-mode-tests.el @@ -277,6 +277,29 @@ declare function declareFunctionDefn(x3: xty3, y3: yty3): ret3;" (("y0" "y1" "y2" "y3") . font-lock-variable-name-face) (("ret0" "ret1" "ret2" "ret3") . nil)))) +(ert-deftest font-lock/regexp () + "Regular expresssions should be fontified as string constant." + (let ((content "=/foo/ (/bar/ ,/baz/ :/buzz/")) + (font-lock-test content + '(("=" . nil) ("/foo/" . font-lock-string-face) + ("(" . nil) ("/bar/" . font-lock-string-face) + ("," . nil) ("/baz/" . font-lock-string-face) + (":" . nil) ("/buzz/" . font-lock-string-face))))) + +(ert-deftest font-lock/text-after-trailing-regexp-delim-should-not-be-fontified () + "Text after trailing regular expression delimiter should not be fontified." + (test-with-temp-buffer + "=/foo/g something // comment" + (should (eq (get-face-at "g something") nil))) + (test-with-temp-buffer + "=/foo\\bar/g something // comment" + (should (eq (get-face-at "g something") nil))) + (test-with-temp-buffer + "=/foo\\\\bar/g something // comment" + (should (eq (get-face-at "g something") nil))) + (test-with-temp-buffer + "=/foo\\\\/g something // comment" + (should (eq (get-face-at "g something") nil)))) (defun flyspell-predicate-test (search-for) "This function runs a test on