emacs-diffs
[Top][All Lists]
Advanced

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

master 6a64660: Enhance syntax-tests.el to test comments in scan-lists


From: Alan Mackenzie
Subject: master 6a64660: Enhance syntax-tests.el to test comments in scan-lists
Date: Fri, 2 Oct 2020 13:26:19 -0400 (EDT)

branch: master
commit 6a6466031839d5fb4efadbfe2cdbd5ba469dd9c6
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    Enhance syntax-tests.el to test comments in scan-lists
    
    This now tests the interface between scan_lists and the comment functions.
    
    * test/src/syntax-tests.el (syntax-br-comments): New macro.
    ({-in, ;-in, /*-in): Set parse-sexp-ignore-comments to t.
    (top level): Add 15 tests for comments inside brace lists.
    
    * test/data/syntax-comments.txt (top level): Amend some test fragments.
---
 test/data/syntax-comments.txt | 29 ++++++++-------
 test/src/syntax-tests.el      | 85 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 95 insertions(+), 19 deletions(-)

diff --git a/test/data/syntax-comments.txt b/test/data/syntax-comments.txt
index 74e08b1..e10c145 100644
--- a/test/data/syntax-comments.txt
+++ b/test/data/syntax-comments.txt
@@ -23,6 +23,21 @@
 13
 15/* /*/15
 
+/* C Comments within lists */
+59}59
+50{ /* comment */ }50
+51{ /**/ }51
+52{ // comment
+}52
+53{ //
+}53
+54{ // \
+}54
+55{/* */}55
+56{ /* \*/ }56
+57*/57
+58}58
+
 
 /* Straight Pascal comments (not nested) */
 20}20
@@ -46,20 +61,6 @@
 33;        \
 33
 
-/* Comments within lists */
-50{ /* comment */ }50
-51{ /**/ }51
-52{ // comment
-}52
-53{ //
-}53
-54{ //
-}54
-55{/* */}55
-56{ /* \*/ }56
-57*/57
-58}58
-
 Local Variables:
 mode: fundamental
 eval: (set-syntax-table (make-syntax-table))
diff --git a/test/src/syntax-tests.el b/test/src/syntax-tests.el
index 4bd8a85..3b3521e 100644
--- a/test/src/syntax-tests.el
+++ b/test/src/syntax-tests.el
@@ -85,11 +85,11 @@ also has open paren syntax (see Bug#24870)."
 
 ;;; Commentary:
 ;; The next bit tests the handling of comments in syntax.c, in
-;; particular the function `forward-comment'.
+;; particular the functions `forward-comment' and `scan-lists' (in so
+;; far as it relates to comments).
 
 ;; It is intended to enhance this bit to test nested comments and also
-;; the interaction of `parse-partial-sexp' and `scan-lists' with
-;; comments (2020-10-01).
+;; the interaction of `parse-partial-sexp' with comments (2020-10-01).
 
 ;; This bit uses the data file test/data/syntax-comments.txt.
 
@@ -158,8 +158,7 @@ missing or nil, the value of START is assumed for it."
          ((eq -dir- 'backward) nil)
          (t (error "Invalid -dir- argument \"%s\" to `syntax-comments'" 
-dir-))))
        (start-str (format "%d" (abs start)))
-       (type -type-)
-       )
+       (type -type-))
     `(ert-deftest ,(intern (concat "syntax-comments-"
                                   syntax-comments-section
                                   (if forw "-f" "-b") start-str))
@@ -175,11 +174,66 @@ missing or nil, the value of START is assumed for it."
           (should (eq (point) stop)))
         (,(intern (concat (symbol-name type) "-out")))))))
 
+(defmacro syntax-br-comments (-type- -dir- res -start- &optional stop)
+  "Create an ERT test to test (scan-lists <position> 1/-1 0).
+This is to test the interface between scan-lists and the internal
+comment routines in syntax.c.
+
+The test uses a fixed name data file, which it visits.  It calls
+entry and exit functions to set up and tear down syntax entries
+for comment and paren characters.  The test is given a name based
+on the global variable `syntax-comments-section', the direction
+of movement and the value of -START-.
+
+-TYPE- (unquoted) is a symbol from whose name the entry and exit
+function names are derived by appending \"-in\" and \"-out\".
+
+-DIR- (unquoted) is `forward' or `backward', the direction
+`scan-lists' is attempted.
+
+RES is t if `scan-lists' is expected to return, nil if it is
+expected to raise a `scan-error' exception.
+
+-START- and STOP are decimal numbers corresponding to labels in the
+data file marking the start and expected stop positions.  See
+`syntax-comments-point' for a precise specification.  If STOP is
+missing or nil, the value of -START- is assumed for it."
+  (declare (debug t))
+  (let* ((forw
+         (cond
+          ((eq -dir- 'forward) t)
+          ((eq -dir- 'backward) nil)
+          (t (error "Invalid -dir- argument \"%s\" to `syntax-comments'" 
-dir-))))
+         (start -start-)
+        (start-str (format "%d" (abs start)))
+        (type -type-))
+    `(ert-deftest ,(intern (concat "syntax-br-comments-"
+                                  syntax-comments-section
+                                  (if forw "-f" "-b") start-str))
+        ()
+       (with-current-buffer
+          (find-file
+           ,(expand-file-name "data/syntax-comments.txt"
+                              (getenv "EMACS_TEST_DIRECTORY")))
+        (,(intern (concat (symbol-name type) "-in")))
+         (let ((start-pos (syntax-comments-point ,start ,forw))
+               ,@(if res
+                     `((stop-pos (syntax-comments-point
+                                  ,(or stop start) ,(not forw))))))
+           ,(if res
+                `(should
+                  (eq (scan-lists start-pos ,(if forw 1 -1) 0)
+                      stop-pos))
+              `(should-error (scan-lists start-pos ,(if forw 1 -1) 0)
+                             :type 'scan-error)))
+        (,(intern (concat (symbol-name type) "-out")))))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; "Pascal" style comments - single character delimiters, the closing
 ;; delimiter not being newline.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun {-in ()
+  (setq parse-sexp-ignore-comments t)
   (setq comment-end-can-be-escaped nil)
   (modify-syntax-entry ?{ "<")
   (modify-syntax-entry ?} ">"))
@@ -208,6 +262,7 @@ missing or nil, the value of START is assumed for it."
 ;; comments.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun \;-in ()
+  (setq parse-sexp-ignore-comments t)
   (setq comment-end-can-be-escaped nil)
   (modify-syntax-entry ?\n ">")
   (modify-syntax-entry ?\; "<"))
@@ -229,6 +284,7 @@ missing or nil, the value of START is assumed for it."
 ;; Emacs 27 "C" style comments - `comment-end-can-be-escaped' is non-nil.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun /*-in ()
+  (setq parse-sexp-ignore-comments t)
   (setq comment-end-can-be-escaped t)
   (modify-syntax-entry ?/ ". 124b")
   (modify-syntax-entry ?* ". 23")
@@ -272,4 +328,23 @@ missing or nil, the value of START is assumed for it."
 (syntax-comments /* forward t 15)
 (syntax-comments /* backward t 15)
 
+;; Emacs 27 "C" style comments inside brace lists.
+(syntax-br-comments /* forward t 50)
+(syntax-br-comments /* backward t 50)
+(syntax-br-comments /* forward t 51)
+(syntax-br-comments /* backward t 51)
+(syntax-br-comments /* forward t 52)
+(syntax-br-comments /* backward t 52)
+
+(syntax-br-comments /* forward t 53)
+(syntax-br-comments /* backward t 53)
+(syntax-br-comments /* forward t 54 20)
+(syntax-br-comments /* backward t 54)
+(syntax-br-comments /* forward t 55)
+(syntax-br-comments /* backward t 55)
+
+(syntax-br-comments /* forward t 56 58)
+(syntax-br-comments /* backward t 58 56)
+(syntax-br-comments /* backward nil 59)
+
 ;;; syntax-tests.el ends here



reply via email to

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