]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/perl-mode.el (perl--syntax-exp-intro-regexp): Bug#42168
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 14 Aug 2020 14:58:00 +0000 (10:58 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 14 Aug 2020 14:58:00 +0000 (10:58 -0400)
* test/lisp/progmodes/cperl-mode-tests.el: Adjust for `perl-mode`.
(cperl-test-ppss): Rename from `cperl-test-face` and change return value.
(cperl-mode-test-bug-42168): Test the `syntax-ppss` state rather than
the font-lock faces, so it works for both `perl-mode` and `cperl-mode`.

lisp/progmodes/perl-mode.el
test/lisp/progmodes/cperl-mode-tests.el

index ff0b6a331bc6ad335b638d37f804f5d852f6b1ec..127b24cb8908e8504ef282d7c4db3446903e6965 100644 (file)
   (defconst perl--syntax-exp-intro-regexp
     (concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)"
             (regexp-opt perl--syntax-exp-intro-keywords)
-            "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*")))
+            "\\|[?:.,;|&*=!~({[]"
+            "\\|[^-+][-+]"    ;Bug#42168: `+' is intro but `++' isn't!
+            "\\|\\(^\\)\\)[ \t\n]*")))
 
 (defun perl-syntax-propertize-function (start end)
   (let ((case-fold-search nil))
index f39f1ba6580b18d44dc799c3bfce516c4a271b70..be8b42d99a826b9dd236723506f57d1ef92cfd8e 100644 (file)
 
 ;;; Code:
 
-(defun cperl-test-face (text regexp)
-  "Returns the face of the first character matched by REGEXP in TEXT."
+(defvar cperl-test-mode #'cperl-mode)
+
+(defun cperl-test-ppss (text regexp)
+  "Return the `syntax-ppss' of the first character matched by REGEXP in TEXT."
   (interactive)
   (with-temp-buffer
-      (insert text)
-      (cperl-mode)
-      (font-lock-ensure (point-min) (point-max))
-      (goto-char (point-min))
-      (re-search-forward regexp)
-      (get-text-property (match-beginning 0) 'face)))
+    (insert text)
+    (funcall cperl-test-mode)
+    (goto-char (point-min))
+    (re-search-forward regexp)
+    (syntax-ppss)))
 
 (ert-deftest cperl-mode-test-bug-42168 ()
   "Verify that '/' is a division after ++ or --, not a regexp.
@@ -37,14 +38,14 @@ have a face property."
   ;; The next two Perl expressions have divisions.  Perl "punctuation"
   ;; operators don't get a face.
   (let ((code "{ $a++ / $b }"))
-    (should (equal (cperl-test-face code "/" ) nil)))
+    (should (equal (nth 8 (cperl-test-ppss code "/")) nil)))
   (let ((code "{ $a-- / $b }"))
-    (should (equal (cperl-test-face code "/" ) nil)))
+    (should (equal (nth 8 (cperl-test-ppss code "/")) nil)))
   ;; The next two Perl expressions have regular expressions.  The
   ;; delimiter of a RE is fontified with font-lock-constant-face.
   (let ((code "{ $a+ / $b } # /"))
-    (should (equal (cperl-test-face code "/" ) font-lock-constant-face)))
+    (should (equal (nth 8 (cperl-test-ppss code "/")) 7)))
   (let ((code "{ $a- / $b } # /"))
-    (should (equal (cperl-test-face code "/" ) font-lock-constant-face))))
+    (should (equal (nth 8 (cperl-test-ppss code "/")) 7))))
 
 ;;; cperl-mode-tests.el ends here