aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-rw-r--r--test/src/coding-tests.el2
-rw-r--r--test/src/indent-tests.el59
-rw-r--r--test/src/regex-resources/BOOST.tests4
-rw-r--r--test/src/syntax-tests.el349
4 files changed, 411 insertions, 3 deletions
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el
index c438ae22ce3..82883a045c8 100644
--- a/test/src/coding-tests.el
+++ b/test/src/coding-tests.el
@@ -143,7 +143,7 @@
143;; Optional 5th arg TRANSLATOR is a function to translate the original 143;; Optional 5th arg TRANSLATOR is a function to translate the original
144;; file contents to match with the expected result of decoding. For 144;; file contents to match with the expected result of decoding. For
145;; instance, when a file of dos eol-type is read by unix eol-type, 145;; instance, when a file of dos eol-type is read by unix eol-type,
146;; `decode-test-lf-to-crlf' must be specified. 146;; `coding-tests-lf-to-crlf' must be specified.
147 147
148(defun coding-tests (content-type write-coding read-coding detected-coding 148(defun coding-tests (content-type write-coding read-coding detected-coding
149 &optional translator) 149 &optional translator)
diff --git a/test/src/indent-tests.el b/test/src/indent-tests.el
new file mode 100644
index 00000000000..7d1a6ce6dc3
--- /dev/null
+++ b/test/src/indent-tests.el
@@ -0,0 +1,59 @@
1;;; indent-tests.el --- tests for src/indent.c -*- lexical-binding:t -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; This program is free software: you can redistribute it and/or
8;; modify it under the terms of the GNU General Public License as
9;; published by the Free Software Foundation, either version 3 of the
10;; License, or (at your option) any later version.
11;;
12;; This program is distributed in the hope that it will be useful, but
13;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15;; General Public License for more details.
16;;
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see `https://www.gnu.org/licenses/'.
19
20;;; Commentary:
21
22;;; Code:
23
24(ert-deftest indent-tests-move-to-column-invis-1tab ()
25 "Test `move-to-column' when a TAB is followed by invisible text."
26 (should
27 (string=
28 (with-temp-buffer
29 (insert "\tLine starting with INVISIBLE text after TAB\n")
30 (add-text-properties 2 21 '(invisible t))
31 (goto-char (point-min))
32 (move-to-column 7 t)
33 (buffer-substring-no-properties 1 8))
34 " ")))
35
36(ert-deftest indent-tests-move-to-column-invis-2tabs ()
37 "Test `move-to-column' when 2 TABs are followed by invisible text."
38 (should
39 (string=
40 (with-temp-buffer
41 (insert "\t\tLine starting with INVISIBLE text after TAB\n")
42 (add-text-properties 3 22 '(invisible t))
43 (goto-char (point-min))
44 (move-to-column 12 t)
45 (buffer-substring-no-properties 1 11))
46 "\t \tLine")))
47
48(ert-deftest indent-tests-move-to-column-invis-between-tabs ()
49 "Test `move-to-column' when 2 TABs are mixed with invisible text."
50 (should
51 (string=
52 (with-temp-buffer
53 (insert "\txxx\tLine starting with INVISIBLE text after TAB\n")
54 (add-text-properties 6 25 '(invisible t))
55 (add-text-properties 2 5 '(invisible t))
56 (goto-char (point-min))
57 (move-to-column 12 t)
58 (buffer-substring-no-properties 1 14))
59 "\txxx \tLine")))
diff --git a/test/src/regex-resources/BOOST.tests b/test/src/regex-resources/BOOST.tests
index 98fd3b6abf3..756fa00486b 100644
--- a/test/src/regex-resources/BOOST.tests
+++ b/test/src/regex-resources/BOOST.tests
@@ -93,7 +93,7 @@ aa\) !
93. \0 0 1 93. \0 0 1
94 94
95; 95;
96; now move on to the repetion ops, 96; now move on to the repetition ops,
97; starting with operator * 97; starting with operator *
98- match_default normal REG_EXTENDED 98- match_default normal REG_EXTENDED
99a* b 0 0 99a* b 0 0
@@ -275,7 +275,7 @@ a(b*)c\1d abbcbbbd -1 -1
275^(.)\1 abc -1 -1 275^(.)\1 abc -1 -1
276a([bc])\1d abcdabbd 4 8 5 6 276a([bc])\1d abcdabbd 4 8 5 6
277; strictly speaking this is at best ambiguous, at worst wrong, this is what most 277; strictly speaking this is at best ambiguous, at worst wrong, this is what most
278; re implimentations will match though. 278; re implementations will match though.
279a(([bc])\2)*d abbccd 0 6 3 5 3 4 279a(([bc])\2)*d abbccd 0 6 3 5 3 4
280 280
281a(([bc])\2)*d abbcbd -1 -1 281a(([bc])\2)*d abbcbd -1 -1
diff --git a/test/src/syntax-tests.el b/test/src/syntax-tests.el
index 65c56b3b29d..56e03380579 100644
--- a/test/src/syntax-tests.el
+++ b/test/src/syntax-tests.el
@@ -82,4 +82,353 @@ also has open paren syntax (see Bug#24870)."
82 (should (equal (parse-partial-sexp pointC pointX nil nil ppsC) 82 (should (equal (parse-partial-sexp pointC pointX nil nil ppsC)
83 ppsX))))) 83 ppsX)))))
84 84
85
86;;; Commentary:
87;; The next bit tests the handling of comments in syntax.c, in
88;; particular the functions `forward-comment' and `scan-lists' and
89;; `parse-partial-sexp' (in so far as they relate to comments).
90
91;; It is intended to enhance this bit to test nested comments
92;; (2020-10-01).
93
94;; This bit uses the data file test/data/syntax-comments.txt.
95
96(defun syntax-comments-point (n forw)
97 "Return the buffer offset corresponding to the \"label\" N.
98N is a decimal number which appears in the data file, usually
99twice, as \"labels\". It can also be a negative number or zero.
100FORW is t when we're using the label at BOL, nil for the one at EOL.
101
102If the label N doesn't exist in the current buffer, an exception
103is thrown.
104
105When FORW is t and N positive, we return the position after the
106first occurrence of label N at BOL in the data file. With FORW
107nil, we return the position before the last occurrence of the
108label at EOL in the data file.
109
110When N is negative, we return instead the position of the end of
111line that the -N label is on. When it is zero, we return POINT."
112 (if (zerop n)
113 (point)
114 (let ((str (format "%d" (abs n))))
115 (save-excursion
116 (if forw
117 (progn
118 (goto-char (point-min))
119 (re-search-forward
120 (concat "^\\(" str "\\)\\([^0-9\n]\\|$\\)"))
121 (if (< n 0)
122 (progn (end-of-line) (point))
123 (match-end 1)))
124 (goto-char (point-max))
125 (re-search-backward
126 (concat "\\(^\\|[^0-9]\\)\\(" str "\\)$"))
127 (if (< n 0)
128 (progn (end-of-line) (point))
129 (match-beginning 2)))))))
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
148(eval-and-compile
149 (defvar syntax-comments-section))
150
151(defmacro syntax-comments (-type- -dir- res start &optional stop)
152 "Create an ERT test to test (forward-comment 1/-1).
153The test uses a fixed name data file, which it visits. It calls
154entry and exit functions to set up and tear down syntax entries
155for comment characters. The test is given a name based on the
156global variable `syntax-comments-section', the direction of
157movement and the value of START.
158
159-TYPE- (unquoted) is a symbol from whose name the entry and exit
160function names are derived by appending \"-in\" and \"-out\".
161
162-DIR- (unquoted) is `forward' or `backward', the direction
163`forward-comment' is attempted.
164
165RES, t or nil, is the expected result from `forward-comment'.
166
167START and STOP are decimal numbers corresponding to labels in the
168data file marking the start and expected stop positions. See
169`syntax-comments-point' for a precise specification. If STOP is
170missing or nil, the value of START is assumed for it."
171 (declare (debug t))
172 (let ((forw
173 (cond
174 ((eq -dir- 'forward) t)
175 ((eq -dir- 'backward) nil)
176 (t (error "Invalid -dir- argument \"%s\" to `syntax-comments'" -dir-))))
177 (start-str (format "%d" (abs start)))
178 (type -type-))
179 `(ert-deftest ,(intern (concat "syntax-comments-"
180 syntax-comments-section
181 (if forw "-f" "-b") start-str))
182 ()
183 (with-current-buffer
184 (find-file
185 ,(expand-file-name "data/syntax-comments.txt"
186 (getenv "EMACS_TEST_DIRECTORY")))
187 (,(intern (concat (symbol-name type) "-in")))
188 (goto-char (syntax-comments-point ,start ,forw))
189 (let ((stop (syntax-comments-point ,(or stop start) ,(not forw))))
190 (should (eq (forward-comment ,(if forw 1 -1)) ,res))
191 (should (eq (point) stop)))
192 (,(intern (concat (symbol-name type) "-out")))))))
193
194(defmacro syntax-br-comments (-type- -dir- res -start- &optional stop)
195 "Create an ERT test to test (scan-lists <position> 1/-1 0).
196This is to test the interface between scan-lists and the internal
197comment routines in syntax.c.
198
199The test uses a fixed name data file, which it visits. It calls
200entry and exit functions to set up and tear down syntax entries
201for comment and paren characters. The test is given a name based
202on the global variable `syntax-comments-section', the direction
203of movement and the value of -START-.
204
205-TYPE- (unquoted) is a symbol from whose name the entry and exit
206function names are derived by appending \"-in\" and \"-out\".
207
208-DIR- (unquoted) is `forward' or `backward', the direction
209`scan-lists' is attempted.
210
211RES is t if `scan-lists' is expected to return, nil if it is
212expected to raise a `scan-error' exception.
213
214-START- and STOP are decimal numbers corresponding to labels in the
215data file marking the start and expected stop positions. See
216`syntax-comments-point' for a precise specification. If STOP is
217missing or nil, the value of -START- is assumed for it."
218 (declare (debug t))
219 (let* ((forw
220 (cond
221 ((eq -dir- 'forward) t)
222 ((eq -dir- 'backward) nil)
223 (t (error "Invalid -dir- argument \"%s\" to `syntax-comments'" -dir-))))
224 (start -start-)
225 (start-str (format "%d" (abs start)))
226 (type -type-))
227 `(ert-deftest ,(intern (concat "syntax-br-comments-"
228 syntax-comments-section
229 (if forw "-f" "-b") start-str))
230 ()
231 (with-current-buffer
232 (find-file
233 ,(expand-file-name "data/syntax-comments.txt"
234 (getenv "EMACS_TEST_DIRECTORY")))
235 (,(intern (concat (symbol-name type) "-in")))
236 (let ((start-pos (syntax-comments-point ,start ,forw))
237 ,@(if res
238 `((stop-pos (syntax-comments-point
239 ,(or stop start) ,(not forw))))))
240 ,(if res
241 `(should
242 (eq (scan-lists start-pos ,(if forw 1 -1) 0)
243 stop-pos))
244 `(should-error (scan-lists start-pos ,(if forw 1 -1) 0)
245 :type 'scan-error)))
246 (,(intern (concat (symbol-name type) "-out")))))))
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
306;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
307;; "Pascal" style comments - single character delimiters, the closing
308;; delimiter not being newline.
309;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310(defun {-in ()
311 (setq parse-sexp-ignore-comments t)
312 (setq comment-end-can-be-escaped nil)
313 (modify-syntax-entry ?{ "<")
314 (modify-syntax-entry ?} ">"))
315(defun {-out ()
316 (modify-syntax-entry ?{ "(}")
317 (modify-syntax-entry ?} "){"))
318(eval-and-compile
319 (setq syntax-comments-section "pascal"))
320
321(syntax-comments { forward nil 20 0)
322(syntax-comments { backward nil 20 0)
323(syntax-comments { forward t 21)
324(syntax-comments { backward t 21)
325(syntax-comments { forward t 22)
326(syntax-comments { backward t 22)
327
328(syntax-comments { forward t 23)
329(syntax-comments { backward t 23)
330(syntax-comments { forward t 24)
331(syntax-comments { backward t 24)
332(syntax-comments { forward t 26)
333(syntax-comments { backward t 26)
334
335;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
336;; "Lisp" style comments - single character opening delimiters on line
337;; comments.
338;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339(defun \;-in ()
340 (setq parse-sexp-ignore-comments t)
341 (setq comment-end-can-be-escaped nil)
342 (modify-syntax-entry ?\n ">")
343 (modify-syntax-entry ?\; "<"))
344(defun \;-out ()
345 (modify-syntax-entry ?\n " ")
346 (modify-syntax-entry ?\; "."))
347(eval-and-compile
348 (setq syntax-comments-section "lisp"))
349
350(syntax-comments \; backward nil 30 30)
351(syntax-comments \; forward t 31)
352(syntax-comments \; backward t 31)
353(syntax-comments \; forward t 32)
354(syntax-comments \; backward t 32)
355(syntax-comments \; forward t 33)
356(syntax-comments \; backward t 33)
357
358;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
359;; Emacs 27 "C" style comments - `comment-end-can-be-escaped' is non-nil.
360;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
361(defun /*-in ()
362 (setq parse-sexp-ignore-comments t)
363 (setq comment-end-can-be-escaped t)
364 (modify-syntax-entry ?/ ". 124b")
365 (modify-syntax-entry ?* ". 23")
366 (modify-syntax-entry ?\n "> b"))
367(defun /*-out ()
368 (setq comment-end-can-be-escaped nil)
369 (modify-syntax-entry ?/ ".")
370 (modify-syntax-entry ?* ".")
371 (modify-syntax-entry ?\n " "))
372(eval-and-compile
373 (setq syntax-comments-section "c"))
374
375(syntax-comments /* forward t 1)
376(syntax-comments /* backward t 1)
377(syntax-comments /* forward t 2)
378(syntax-comments /* backward t 2)
379(syntax-comments /* forward t 3)
380(syntax-comments /* backward t 3)
381
382(syntax-comments /* forward t 4)
383(syntax-comments /* backward t 4)
384(syntax-comments /* forward t 5 6)
385(syntax-comments /* backward nil 5 0)
386(syntax-comments /* forward nil 6 0)
387(syntax-comments /* backward t 6 5)
388
389(syntax-comments /* forward t 7 8)
390(syntax-comments /* backward nil 7 0)
391(syntax-comments /* forward nil 8 0)
392(syntax-comments /* backward t 8 7)
393(syntax-comments /* forward t 9)
394(syntax-comments /* backward t 9)
395
396(syntax-comments /* forward nil 10 0)
397(syntax-comments /* backward nil 10 0)
398(syntax-comments /* forward t 11)
399(syntax-comments /* backward t 11)
400
401(syntax-comments /* forward t 13 14)
402(syntax-comments /* backward nil 13 -14)
403(syntax-comments /* forward t 15)
404(syntax-comments /* backward t 15)
405
406;; Emacs 27 "C" style comments inside brace lists.
407(syntax-br-comments /* forward t 50)
408(syntax-br-comments /* backward t 50)
409(syntax-br-comments /* forward t 51)
410(syntax-br-comments /* backward t 51)
411(syntax-br-comments /* forward t 52)
412(syntax-br-comments /* backward t 52)
413
414(syntax-br-comments /* forward t 53)
415(syntax-br-comments /* backward t 53)
416(syntax-br-comments /* forward t 54 20)
417(syntax-br-comments /* backward t 54)
418(syntax-br-comments /* forward t 55)
419(syntax-br-comments /* backward t 55)
420
421(syntax-br-comments /* forward t 56 58)
422(syntax-br-comments /* backward t 58 56)
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)
433
85;;; syntax-tests.el ends here 434;;; syntax-tests.el ends here