1;;; syntax-tests.el --- tests for syntax.c functions -*- lexical-binding: t -*-
2
3;; Copyright (C) 2017-2021 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(ert-deftest parse-partial-sexp-continue-over-comment-marker ()
25  "Continue a parse that stopped in the middle of a comment marker."
26  (with-temp-buffer
27    (let ((table (make-syntax-table)))
28      (modify-syntax-entry ?/ ". 124")
29      (modify-syntax-entry ?* ". 23b")
30      (set-syntax-table table))
31    (insert "/*C*/\nX")
32    (goto-char (point-min))
33    (let* ((pointC (progn (search-forward "C") (1- (point))))
34           (preC (1- pointC))
35           (pointX (progn (search-forward "X") (1- (point))))
36           (aftC (+ 2 pointC))
37           (ppsC (parse-partial-sexp (point-min) pointC))
38           (pps-preC (parse-partial-sexp (point-min) preC))
39           (pps-aftC (parse-partial-sexp (point-min) aftC))
40           (ppsX (parse-partial-sexp (point-min) pointX)))
41      ;; C should be inside comment.
42      (should (= (nth 0 ppsC) 0))
43      (should (eq (nth 4 ppsC) t))
44      (should (= (nth 8 ppsC) (- pointC 2)))
45      ;; X should not be in comment or list.
46      (should (= (nth 0 ppsX) 0))
47      (should-not (nth 4 ppsX))
48      ;; Try using OLDSTATE.
49      (should (equal (parse-partial-sexp preC pointC nil nil pps-preC)
50                     ppsC))
51      (should (equal (parse-partial-sexp pointC aftC nil nil ppsC)
52                     pps-aftC))
53      (should (equal (parse-partial-sexp preC aftC nil nil pps-preC)
54                     pps-aftC))
55      (should (equal (parse-partial-sexp aftC pointX nil nil pps-aftC)
56                     ppsX)))))
57
58(ert-deftest parse-partial-sexp-paren-comments ()
59  "Test syntax parsing with paren comment markers.
60Specifically, where the first character of the comment marker is
61also has open paren syntax (see Bug#24870)."
62  (with-temp-buffer
63    (let ((table (make-syntax-table)))
64      (modify-syntax-entry ?\{  "(}1nb" table)
65      (modify-syntax-entry ?\}  "){4nb" table)
66      (modify-syntax-entry ?-  ". 123" table)
67      (set-syntax-table table))
68    (insert "{-C-}\nX")
69    (goto-char (point-min))
70    (let* ((pointC (progn (search-forward "C") (1- (point))))
71           (pointX (progn (search-forward "X") (1- (point))))
72           (ppsC (parse-partial-sexp (point-min) pointC))
73           (ppsX (parse-partial-sexp (point-min) pointX)))
74      ;; C should be inside nestable comment, not list.
75      (should (= (nth 0 ppsC) 0))
76      (should (= (nth 4 ppsC) 1))
77      (should (= (nth 8 ppsC) (- pointC 2)))
78      ;; X should not be in comment or list.
79      (should (= (nth 0 ppsX) 0))
80      (should-not (nth 4 ppsX))
81      ;; Try using OLDSTATE.
82      (should (equal (parse-partial-sexp pointC pointX nil nil ppsC)
83                     ppsX)))))
84
85;;; syntax-tests.el ends here
86