aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/syntax-comments.txt13
-rw-r--r--test/src/syntax-tests.el92
2 files changed, 95 insertions, 10 deletions
diff --git a/test/data/syntax-comments.txt b/test/data/syntax-comments.txt
index e10c1450e46..6f595e4d8dc 100644
--- a/test/data/syntax-comments.txt
+++ b/test/data/syntax-comments.txt
@@ -25,18 +25,19 @@
25 25
26/* C Comments within lists */ 26/* C Comments within lists */
2759}59 2759}59
2850{ /* comment */ }50 2850{ /*70 comment */71 }50
2951{ /**/ }51 2951{ /**/ }51
3052{ // comment 3052{ //72 comment
31}52 3173}52
3253{ // 3253{ //
33}53 33}53
3454{ // \ 3454{ //74 \
35}54 35}54
3655{/* */}55 3655{/* */}55
3756{ /* \*/ }56 3756{ /*76 \*/ }56
3857*/57 3857*/77
3958}58 3958}58
4060{ /*78 \\*/79}60
40 41
41 42
42/* Straight Pascal comments (not nested) */ 43/* Straight Pascal comments (not nested) */
diff --git a/test/src/syntax-tests.el b/test/src/syntax-tests.el
index 3b3521eaab0..56e03380579 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)."
85 85
86;;; Commentary: 86;;; Commentary:
87;; The next bit tests the handling of comments in syntax.c, in 87;; The next bit tests the handling of comments in syntax.c, in
88;; particular the functions `forward-comment' and `scan-lists' (in so 88;; particular the functions `forward-comment' and `scan-lists' and
89;; far as it relates to comments). 89;; `parse-partial-sexp' (in so far as they relate to comments).
90 90
91;; It is intended to enhance this bit to test nested comments and also 91;; It is intended to enhance this bit to test nested comments
92;; the interaction of `parse-partial-sexp' with comments (2020-10-01). 92;; (2020-10-01).
93 93
94;; This bit uses the data file test/data/syntax-comments.txt. 94;; This bit uses the data file test/data/syntax-comments.txt.
95 95
@@ -128,6 +128,23 @@ line that the -N label is on. When it is zero, we return POINT."
128 (progn (end-of-line) (point)) 128 (progn (end-of-line) (point))
129 (match-beginning 2))))))) 129 (match-beginning 2)))))))
130 130
131(defun syntax-comments-midpoint (n)
132 "Return the buffer offset corresponding to the \"label\" N.
133N is a positive decimal number which should appear in the buffer
134exactly once. The label need not be at the beginning or end of a
135line.
136
137The return value is the position just before the label.
138
139If the label N doesn't exist in the current buffer, an exception
140is thrown."
141 (let ((str (format "%d" n)))
142 (save-excursion
143 (goto-char (point-min))
144 (re-search-forward
145 (concat "\\(^\\|[^0-9]\\)\\(" str "\\)\\([^0-9\n]\\|$\\)"))
146 (match-beginning 2))))
147
131(eval-and-compile 148(eval-and-compile
132 (defvar syntax-comments-section)) 149 (defvar syntax-comments-section))
133 150
@@ -228,6 +245,64 @@ missing or nil, the value of -START- is assumed for it."
228 :type 'scan-error))) 245 :type 'scan-error)))
229 (,(intern (concat (symbol-name type) "-out"))))))) 246 (,(intern (concat (symbol-name type) "-out")))))))
230 247
248(defmacro syntax-pps-comments (-type- -start- open close &optional -stop-)
249 "Create an ERT test to test `parse-partial-sexp' with comments.
250This is to test the interface between `parse-partial-sexp' and
251the internal comment routines in syntax.c.
252
253The test uses a fixed name data file, which it visits. It calls
254entry and exit functions to set up and tear down syntax entries
255for comment and paren characters. The test is given a name based
256on the global variable `syntax-comments-section', and the value
257of -START-.
258
259The generated test calls `parse-partial-sexp' three times, the
260first two with COMMENTSTOP set to `syntax-table' so as to stop
261after the start and end of the comment. The third call is
262expected to stop at the brace/paren matching the one where the
263test started.
264
265-TYPE- (unquoted) is a symbol from whose name the entry and exit
266function names are derived by appending \"-in\" and \"-out\".
267
268-START- and -STOP- are decimal numbers corresponding to labels in
269the data file marking the start and expected stop positions. See
270`syntax-comments-point' for a precise specification. If -STOP-
271is missing or nil, the value of -START- is assumed for it.
272
273OPEN and CLOSE are decimal numbers corresponding to labels in the
274data file marking just after the comment opener and closer where
275the `parse-partial-sexp's are expected to stop. See
276`syntax-comments-midpoint' for a precise specification."
277 (declare (debug t))
278 (let* ((type -type-)
279 (start -start-)
280 (start-str (format "%d" start))
281 (stop (or -stop- start)))
282 `(ert-deftest ,(intern (concat "syntax-pps-comments-"
283 syntax-comments-section
284 "-" start-str))
285 ()
286 (with-current-buffer
287 (find-file
288 ,(expand-file-name "data/syntax-comments.txt"
289 (getenv "EMACS_TEST_DIRECTORY")))
290 (,(intern (concat (symbol-name type) "-in")))
291 (let ((start-pos (syntax-comments-point ,start t))
292 (open-pos (syntax-comments-midpoint ,open))
293 (close-pos (syntax-comments-midpoint ,close))
294 (stop-pos (syntax-comments-point ,stop nil))
295 s)
296 (setq s (parse-partial-sexp
297 start-pos (point-max) 0 nil nil 'syntax-table))
298 (should (eq (point) open-pos))
299 (setq s (parse-partial-sexp
300 (point) (point-max) 0 nil s 'syntax-table))
301 (should (eq (point) close-pos))
302 (setq s (parse-partial-sexp (point) (point-max) 0 nil s))
303 (should (eq (point) stop-pos)))
304 (,(intern (concat (symbol-name type) "-out")))))))
305
231;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 306;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
232;; "Pascal" style comments - single character delimiters, the closing 307;; "Pascal" style comments - single character delimiters, the closing
233;; delimiter not being newline. 308;; delimiter not being newline.
@@ -346,5 +421,14 @@ missing or nil, the value of -START- is assumed for it."
346(syntax-br-comments /* forward t 56 58) 421(syntax-br-comments /* forward t 56 58)
347(syntax-br-comments /* backward t 58 56) 422(syntax-br-comments /* backward t 58 56)
348(syntax-br-comments /* backward nil 59) 423(syntax-br-comments /* backward nil 59)
424(syntax-br-comments /* forward t 60)
425(syntax-br-comments /* backward t 60)
426
427;; Emacs 27 "C" style comments parsed by `parse-partial-sexp'.
428(syntax-pps-comments /* 50 70 71)
429(syntax-pps-comments /* 52 72 73)
430(syntax-pps-comments /* 54 74 55 20)
431(syntax-pps-comments /* 56 76 77 58)
432(syntax-pps-comments /* 60 78 79)
349 433
350;;; syntax-tests.el ends here 434;;; syntax-tests.el ends here