branch: externals/hyperbole
commit 5b6855e2257bbccc5b898fac9dad5d85ac3ee79e
Author: Mats Lidell <mats.lid...@lidells.se>
Commit: GitHub <nore...@github.com>

    Add basic test of quote handling of hypb:in-string-p (#732)
---
 ChangeLog          |  6 ++++++
 test/hypb-tests.el | 43 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 624b898e65..5c6f35ae4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-05-24  Mats Lidell  <ma...@gnu.org>
+
+* test/hypb-tests.el (hypb--in-string-p--max-lines): Add test of max-lines.
+
+* test/hypb-tests.el (hypb--in-string-p): Add basic test of quote handling.
+
 2025-05-23  Bob Weiner  <r...@gnu.org>
 
 * hywiki.el (hywiki-word-with-optional-suffix-regexp): Change #section
diff --git a/test/hypb-tests.el b/test/hypb-tests.el
index deec828e01..722c6f7f80 100644
--- a/test/hypb-tests.el
+++ b/test/hypb-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:     5-Apr-21 at 18:53:10
-;; Last-Mod:     30-Dec-24 at 23:37:03 by Mats Lidell
+;; Last-Mod:     24-May-25 at 00:14:16 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -84,6 +84,47 @@ See Emacs bug#74042 related to usage of texi2any."
         (should (set:equal '("Key Index" "Function Index" "Concept Index") 
(Info-index-nodes))))
     (hy-test-helpers:kill-buffer "*info*")))
 
+(ert-deftest hypb--in-string-p ()
+  "Verify basic quote handing by `hypb:in-string-p'."
+  :expected-result :failed
+  (let ((s '(("\"str\"" . text-mode)            ;; double-quotes:
+             ("'str'" . python-mode)            ;; Python single-quotes:
+             ("'''str'''" . python-mode)        ;; Python triple single-quotes:
+             ("\"\"\"str\"\"\"" . python-mode)  ;; Python triple double-quotes:
+             ("``str''" . texinfo-mode))))      ;; Texinfo open and close 
quotes:
+    (dolist (v s)
+      (let ((str (car v))
+            (mode (cdr v)))
+        (with-temp-buffer
+          (funcall mode)
+          (insert str)
+          (goto-char (/ (length str) 2))
+          (should (hypb:in-string-p))
+          (let ((seq (hypb:in-string-p nil t)))
+            (should (sequencep seq))
+            (cl-destructuring-bind (val beg end) seq
+              (should val)
+              (should (and beg end (= (- end beg) 3))))))))))
+
+(ert-deftest hypb--in-string-p--max-lines ()
+  "Verify max lines handing by `hypb:in-string-p'."
+  (with-temp-buffer
+    (insert "\
+\"1
+2
+\"")
+    (goto-line 1) (move-to-column 1)
+    ;; First line. Line starts with quote.
+    (should-not (hypb:in-string-p 1))
+    (should-not (hypb:in-string-p 2))
+    (should (hypb:in-string-p 3))
+    (should (hypb:in-string-p 99))
+
+    ;; Second line. No quote on the line.
+    (goto-line 2)
+    (dotimes (l 5)
+      (should-not (hypb:in-string-p l)))))
+
 ;; This file can't be byte-compiled without the `el-mock' package (because of
 ;; the use of the `with-mock' macro), which is not a dependency of Hyperbole.
 ;;  Local Variables:

Reply via email to