emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sweeprolog 7dd575c686: * (sweeprolog-beginning-of-next-top


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 7dd575c686: * (sweeprolog-beginning-of-next-top-term): revise and add tests
Date: Wed, 23 Nov 2022 10:59:41 -0500 (EST)

branch: elpa/sweeprolog
commit 7dd575c68686e714f86c9f50f5260073ce796b13
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    * (sweeprolog-beginning-of-next-top-term): revise and add tests
---
 sweeprolog-tests.el | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sweeprolog.el       |  32 +++++++---------
 2 files changed, 120 insertions(+), 18 deletions(-)

diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el
index fc2b0dd377..9953d09a61 100644
--- a/sweeprolog-tests.el
+++ b/sweeprolog-tests.el
@@ -55,6 +55,75 @@
   (should (equal (sweeprolog-next-solution) nil))
   (should (equal (sweeprolog-cut-query) t)))
 
+(ert-deftest beginning-of-next-top-term ()
+  "Test finding the beginning of the next top term."
+  (let ((temp (make-temp-file "sweeprolog-test"
+                              nil
+                              "pl"
+                              "
+foo(Bar) :- bar.
+foo(Baz) :- baz.
+")))
+    (find-file-literally temp)
+    (sweeprolog-mode)
+    (goto-char (point-min))
+    (should (sweeprolog-beginning-of-next-top-term))
+    (should (= (point) 2))
+    (should (sweeprolog-beginning-of-next-top-term))
+    (should (= (point) 19))
+    (should (not (sweeprolog-beginning-of-next-top-term)))
+    (should (= (point) 19))))
+
+(ert-deftest beginning-of-next-top-term-header ()
+  "Test finding the beginning of the first top term."
+  (let ((temp (make-temp-file "sweeprolog-test"
+                              nil
+                              "pl"
+                              "/*
+    Author:        Eshel Yaron
+    E-mail:        eshel@swi-prolog.org
+    Copyright (c)  2022, SWI-Prolog Solutions b.v.
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions
+    are met:
+
+    1. Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in
+       the documentation and/or other materials provided with the
+       distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+    \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+    POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+foobar :- baz.
+*/
+
+:- module(mod")))
+    (find-file-literally temp)
+    (sweeprolog-mode)
+    (goto-char (point-min))
+    (should (sweeprolog-beginning-of-next-top-term))
+    (should (= (point) 1509))
+    (should (not (sweeprolog-beginning-of-next-top-term)))
+    (should (= (point) 1509))))
+
 (ert-deftest font-lock ()
   "Test semantic highlighting of Prolog code."
   (let ((temp (make-temp-file "sweeprolog-test"
@@ -212,6 +281,43 @@ bar(Bar) :- baz(Bar).
     (should (= (point) 24))
     (should (= (mark) 104))))
 
+(ert-deftest export-predicate-with-comment-header ()
+  "Test exporting a predicate after a comment header."
+  (let ((temp (make-temp-file "sweeprolog-test"
+                              nil
+                              ".pl"
+                              "/*
+Sed id ligula quis est convallis tempor.  Nam vestibulum accumsan
+nisl.  Sed diam.  Pellentesque tristique imperdiet tortor.  Fusce
+sagittis, libero non molestie mollis, magna orci ultrices dolor,
+at vulputate neque nulla lacinia eros.
+*/
+:- module(sweeprolog_test_export_predicate, []).
+
+%!  foo(+Bar) is det.
+
+foo(Bar) :- bar(Bar).
+")))
+    (find-file-literally temp)
+    (sweeprolog-mode)
+    (goto-char (point-max))
+    (backward-word)
+    (call-interactively #'sweeprolog-export-predicate)
+    (should (equal (buffer-string)
+                              "/*
+Sed id ligula quis est convallis tempor.  Nam vestibulum accumsan
+nisl.  Sed diam.  Pellentesque tristique imperdiet tortor.  Fusce
+sagittis, libero non molestie mollis, magna orci ultrices dolor,
+at vulputate neque nulla lacinia eros.
+*/
+:- module(sweeprolog_test_export_predicate, [foo/1  % +Bar
+                                            ]).
+
+%!  foo(+Bar) is det.
+
+foo(Bar) :- bar(Bar).
+"))))
+
 (ert-deftest export-predicate ()
   "Test exporting a predicate."
   (let ((temp (make-temp-file "sweeprolog-test"
diff --git a/sweeprolog.el b/sweeprolog.el
index 8bc6144c70..490012d631 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -2496,24 +2496,20 @@ Interactively, POINT is set to the current point."
 
 (defun sweeprolog-beginning-of-next-top-term (&optional times)
   (setq times (or times 1))
-  (let ((p (point)))
-    (when (sweeprolog-at-beginning-of-top-term-p)
-      (forward-char)
-      (re-search-forward (rx bol graph) nil t)
-      (while (and (or (nth 8 (syntax-ppss))
-                      (looking-at-p (rx bol (or "%" "/*"))))
-                  (not (eobp)))
-        (re-search-forward (rx bol graph) nil t))
-      (setq times (1- times)))
-    (while (and (< 0 times) (not (eobp)))
-      (setq times (1- times))
-      (re-search-forward (rx bol graph) nil t)
-      (while (and (or (nth 8 (syntax-ppss))
-                      (looking-at-p (rx bol (or "%" "/*"))))
-                  (not (eobp))
-                  (re-search-forward (rx bol graph) nil t))))
-    (unless (= p (point)) (beginning-of-line))
-    (not (= p (point)))))
+  (let ((target (save-mark-and-excursion
+                  (while (< 0 times)
+                    (setq times (1- times))
+                    (when (sweeprolog-at-beginning-of-top-term-p)
+                      (forward-char))
+                    (while (and (re-search-forward (rx bol graph) nil t)
+                                (or (nth 8 (syntax-ppss))
+                                    (and (= (char-before) ?/)
+                                         (= (char-after) ?*))
+                                    (eobp)))))
+                  (beginning-of-line)
+                  (point))))
+    (unless (= target (point))
+      (goto-char target))))
 
 (defun sweeprolog-end-of-top-term ()
   (unless (eobp)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]