diff options
author | Harald Jörg <haj@posteo.de> | 2020-09-03 22:11:47 +0200 |
---|---|---|
committer | Stefan Kangas <stefankangas@gmail.com> | 2020-09-03 22:58:07 +0200 |
commit | 7921b5db1049709a1d4ed143d1f44417d5087dc1 (patch) | |
tree | ca2b3c39c65062118e61f00669883cf1067d6205 /test/lisp/progmodes/cperl-mode-tests.el | |
parent | 4ea928e14f486ae8b89c0cdf1d19d3dc3d6498a2 (diff) | |
download | emacs-7921b5db1049709a1d4ed143d1f44417d5087dc1.tar.gz |
Fix freeze in cperl-mode when editing a regexp
* lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
sure that an error is reported back to the caller (Bug#16368).
* test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
Tests for balanced (no error) and unbalanced (caught exception)
cases of `cperl-forward-group-in-re'.
Diffstat (limited to 'test/lisp/progmodes/cperl-mode-tests.el')
-rw-r--r-- | test/lisp/progmodes/cperl-mode-tests.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index abb13f25557..1efcad50078 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -33,6 +33,8 @@ (defvar cperl-test-mode #'cperl-mode) +(require 'cperl-mode) + (defun cperl-test-ppss (text regexp) "Return the `syntax-ppss' of the first character matched by REGEXP in TEXT." (interactive) @@ -63,4 +65,25 @@ have a face property." (let ((code "{ $a- / $b } # /")) (should (equal (nth 8 (cperl-test-ppss code "/")) 7)))) +(ert-deftest cperl-mode-test-bug-16368 () + "Verify that `cperl-forward-group-in-re' doesn't hide errors." + (skip-unless (eq cperl-test-mode #'cperl-mode)) + (let ((code "/(\\d{4})(?{2}/;") ; the regex from the bug report + (result)) + (with-temp-buffer + (insert code) + (goto-char 9) + (setq result (cperl-forward-group-in-re)) + (should (equal (car result) 'scan-error)) + (should (equal (nth 1 result) "Unbalanced parentheses")) + (should (= (point) 9)))) ; point remains unchanged on error + (let ((code "/(\\d{4})(?{2})/;") ; here all parens are balanced + (result)) + (with-temp-buffer + (insert code) + (goto-char 9) + (setq result (cperl-forward-group-in-re)) + (should (equal result nil)) + (should (= (point) 15))))) ; point has skipped the group + ;;; cperl-mode-tests.el ends here |