summaryrefslogtreecommitdiff
path: root/test/lisp/progmodes/pascal-tests.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2020-06-21 21:04:30 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2020-06-22 09:51:11 +0200
commit73daab99914b4972a7cd167b03102be4c68e83e5 (patch)
tree454a7f5d3c33b72c1ba0b7f3cffb453473386c30 /test/lisp/progmodes/pascal-tests.el
parentce4ec1793041ae0f013234ef7189ed855b5227a3 (diff)
downloademacs-73daab99914b4972a7cd167b03102be4c68e83e5.tar.gz
emacs-73daab99914b4972a7cd167b03102be4c68e83e5.tar.bz2
emacs-73daab99914b4972a7cd167b03102be4c68e83e5.zip
Preserve point in pascal-mode completion (bug#41740)
Failure to do so caused errors in several cases. Reported by Shinichi Sakata. * lisp/progmodes/pascal.el (pascal-type-completion) (pascal-completion): Wrap code that may move point in save-excursion. * test/lisp/progmodes/pascal-tests.el: New file.
Diffstat (limited to 'test/lisp/progmodes/pascal-tests.el')
-rw-r--r--test/lisp/progmodes/pascal-tests.el55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/lisp/progmodes/pascal-tests.el b/test/lisp/progmodes/pascal-tests.el
new file mode 100644
index 00000000000..10d6e0433d0
--- /dev/null
+++ b/test/lisp/progmodes/pascal-tests.el
@@ -0,0 +1,55 @@
+;;; pascal-tests.el --- tests for pascal.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+(require 'ert)
+(require 'pascal)
+
+(ert-deftest pascal-completion ()
+ ;; Bug#41740: completion functions must preserve point.
+ (let ((pascal-completion-cache nil))
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; var")
+ (let* ((point-before (point))
+ (completions (pascal-completion "var" nil 'metadata))
+ (point-after (point)))
+ (should (equal completions nil))
+ (should (equal point-before point-after)))))
+
+ (let ((pascal-completion-cache nil))
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; function f(x : i")
+ (let* ((point-before (point))
+ (completions (pascal-completion "i" nil 'metadata))
+ (point-after (point)))
+ (should (equal completions nil))
+ (should (equal point-before point-after)))))
+
+ (let ((pascal-completion-cache nil))
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; function f(x : integer) : real")
+ (let* ((point-before (point))
+ (completions (pascal-completion "real" nil 'metadata))
+ (point-after (point)))
+ (should (equal completions nil))
+ (should (equal point-before point-after))))))
+
+(provide 'pascal-tests)