; Remove extraneous "coding: utf-8" specifications in Elisp files
[emacs.git] / test / automated / syntax-tests.el
blobb884c3ef5b80186444b412dd4037edbbe1cb3495
1 ;;; syntax-tests.el --- Testing syntax rules and basic movement -*- lexical-binding: t -*-
3 ;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
5 ;; Author: Daniel Colascione <dancol@dancol.org>
6 ;; Keywords:
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
25 ;;; Code:
26 (require 'ert)
27 (require 'cl-lib)
29 (defun run-up-list-test (fn data start instructions)
30 (cl-labels ((posof (thing)
31 (and (symbolp thing)
32 (= (length (symbol-name thing)) 1)
33 (- (aref (symbol-name thing) 0) ?a -1))))
34 (with-temp-buffer
35 (set-syntax-table (make-syntax-table))
36 ;; Use a syntax table in which single quote is a string
37 ;; character so that we can embed the test data in a lisp string
38 ;; literal.
39 (modify-syntax-entry ?\' "\"")
40 (insert data)
41 (goto-char (posof start))
42 (dolist (instruction instructions)
43 (cond ((posof instruction)
44 (funcall fn)
45 (should (eql (point) (posof instruction))))
46 ((symbolp instruction)
47 (should-error (funcall fn)
48 :type instruction))
49 (t (cl-assert nil nil "unknown ins")))))))
51 (defmacro define-up-list-test (name fn data start &rest expected)
52 `(ert-deftest ,name ()
53 (run-up-list-test ,fn ,data ',start ',expected)))
55 (define-up-list-test up-list-basic
56 (lambda () (up-list))
57 (or "(1 1 (1 1) 1 (1 1) 1)")
58 ;; abcdefghijklmnopqrstuv
59 i k v scan-error)
61 (define-up-list-test up-list-with-forward-sexp-function
62 (lambda ()
63 (let ((forward-sexp-function
64 (lambda (&optional arg)
65 (let ((forward-sexp-function nil))
66 (forward-sexp arg)))))
67 (up-list)))
68 (or "(1 1 (1 1) 1 (1 1) 1)")
69 ;; abcdefghijklmnopqrstuv
70 i k v scan-error)
72 (define-up-list-test up-list-out-of-string
73 (lambda () (up-list 1 t))
74 (or "1 (1 '2 2 (2 2 2' 1) 1")
75 ;; abcdefghijklmnopqrstuvwxy
76 o r u scan-error)
78 (define-up-list-test up-list-cross-string
79 (lambda () (up-list 1 t))
80 (or "(1 '2 ( 2' 1 '2 ) 2' 1)")
81 ;; abcdefghijklmnopqrstuvwxy
82 i r u x scan-error)
84 (define-up-list-test up-list-no-cross-string
85 (lambda () (up-list 1 t t))
86 (or "(1 '2 ( 2' 1 '2 ) 2' 1)")
87 ;; abcdefghijklmnopqrstuvwxy
88 i k x scan-error)
90 (define-up-list-test backward-up-list-basic
91 (lambda () (backward-up-list))
92 (or "(1 1 (1 1) 1 (1 1) 1)")
93 ;; abcdefghijklmnopqrstuv
94 i f a scan-error)
96 (provide 'syntax-tests)
97 ;;; syntax-tests.el ends here