diff options
Diffstat (limited to 'test/src/syntax-tests.el')
| -rw-r--r-- | test/src/syntax-tests.el | 92 |
1 files changed, 88 insertions, 4 deletions
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. | ||
| 133 | N is a positive decimal number which should appear in the buffer | ||
| 134 | exactly once. The label need not be at the beginning or end of a | ||
| 135 | line. | ||
| 136 | |||
| 137 | The return value is the position just before the label. | ||
| 138 | |||
| 139 | If the label N doesn't exist in the current buffer, an exception | ||
| 140 | is 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. | ||
| 250 | This is to test the interface between `parse-partial-sexp' and | ||
| 251 | the internal comment routines in syntax.c. | ||
| 252 | |||
| 253 | The test uses a fixed name data file, which it visits. It calls | ||
| 254 | entry and exit functions to set up and tear down syntax entries | ||
| 255 | for comment and paren characters. The test is given a name based | ||
| 256 | on the global variable `syntax-comments-section', and the value | ||
| 257 | of -START-. | ||
| 258 | |||
| 259 | The generated test calls `parse-partial-sexp' three times, the | ||
| 260 | first two with COMMENTSTOP set to `syntax-table' so as to stop | ||
| 261 | after the start and end of the comment. The third call is | ||
| 262 | expected to stop at the brace/paren matching the one where the | ||
| 263 | test started. | ||
| 264 | |||
| 265 | -TYPE- (unquoted) is a symbol from whose name the entry and exit | ||
| 266 | function names are derived by appending \"-in\" and \"-out\". | ||
| 267 | |||
| 268 | -START- and -STOP- are decimal numbers corresponding to labels in | ||
| 269 | the data file marking the start and expected stop positions. See | ||
| 270 | `syntax-comments-point' for a precise specification. If -STOP- | ||
| 271 | is missing or nil, the value of -START- is assumed for it. | ||
| 272 | |||
| 273 | OPEN and CLOSE are decimal numbers corresponding to labels in the | ||
| 274 | data file marking just after the comment opener and closer where | ||
| 275 | the `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 |