all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 7ba270a11de481befa576c76eec9598a36fc5e90 6677 bytes (raw)
name: test/automated/tildify-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 
;;; tildify-test.el --- ERT tests for tildify.el

;; Copyright (C) 2014 Free Software Foundation, Inc.

;; Author:     Michal Nazarewicz <mina86@mina86.com>
;; Version:    4.5
;; Keywords:   text, TeX, SGML, wp

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This package defines regression tests for the tildify package.

;;; Code:

(require 'ert)
(require 'tildify)

(defun tildify-test--example-sentence (space)
  "Return an example sentence with SPACE where hard space is required."
  (concat "Lorem ipsum v" space "dolor sit amet, a" space
          "consectetur adipiscing elit."))


(defun tildify-test--example-html (sentence &optional with-nbsp is-xml)
  "Return an example HTML code.
SENTENCE is placed where spaces should not be replaced with hard spaces, and
WITH-NBSP is placed where spaces should be replaced with hard spaces.  If the
latter is missing, SENTENCE will be used in all placeholder positions.
If IS-XML is non-nil, <pre> tag is not treated specially."
  (let ((with-nbsp (or with-nbsp sentence)))
    (concat "<p>" with-nbsp "</p>\n"
            "<pre>" (if is-xml with-nbsp sentence) "</pre>\n"
            "<! -- " sentence " -- >\n"
            "<p>" with-nbsp "</p>\n"
            "<" sentence ">\n")))


(defun tildify-test--test (modes input expected)
  "Test tildify running in MODES.
INPUT is the initial content of the buffer and EXPECTED is expected result
after `tildify-buffer' is run."
  (with-temp-buffer
    (dolist (mode modes)
      (erase-buffer)
      (funcall mode)
      (let ((header (concat "Testing `tildify-buffer' in "
                            (symbol-name mode) "\n")))
        (insert header input)
        (tildify-buffer t)
        (should (string-equal (concat header expected) (buffer-string))))
      (erase-buffer)
      (let ((header (concat "Testing `tildify-region' in "
                            (symbol-name mode) "\n")))
        (insert header input)
        (tildify-region (point-min) (point-max) t)
        (should (string-equal (concat header expected) (buffer-string)))))))

(ert-deftest tildify-test-html ()
  "Tests tildification in an HTML document"
  (let* ((sentence (tildify-test--example-sentence " "))
         (with-nbsp (tildify-test--example-sentence "&nbsp;")))
    (tildify-test--test '(html-mode sgml-mode)
                        (tildify-test--example-html sentence sentence)
                        (tildify-test--example-html sentence with-nbsp))))

(ert-deftest tildify-test-xml ()
  "Tests tildification in an XML document"
  (let* ((sentence (tildify-test--example-sentence " "))
         (with-nbsp (tildify-test--example-sentence "&#160;")))
    (tildify-test--test '(nxml-mode)
                        (tildify-test--example-html sentence sentence t)
                        (tildify-test--example-html sentence with-nbsp t))))


(defun tildify-test--example-tex (sentence &optional with-nbsp)
  "Return an example (La)Tex code.
SENTENCE is placed where spaces should not be replaced with hard spaces, and
WITH-NBSP is placed where spaces should be replaced with hard spaces.  If the
latter is missing, SENTENCE will be used in all placeholder positions."
  (let ((with-nbsp (or with-nbsp sentence)))
    (concat with-nbsp "\n"
            "\\begin{verbatim}\n" sentence "\n\\end{verbatim}\n"
            "\\verb#" sentence "#\n"
            "$$" sentence "$$\n"
            "$" sentence "$\n"
            "\\[" sentence "\\]\n"
            "\\v A % " sentence "\n"
            with-nbsp "\n")))

(ert-deftest tildify-test-tex ()
  "Tests tildification in a (La)TeX document"
  (let* ((sentence (tildify-test--example-sentence " "))
         (with-nbsp (tildify-test--example-sentence "~")))
    (tildify-test--test '(tex-mode latex-mode plain-tex-mode)
                        (tildify-test--example-tex sentence sentence)
                        (tildify-test--example-tex sentence with-nbsp))))


(ert-deftest tildify-test-find-env-end-re-bug ()
    "Tests generation of end-regex using mix of indexes and strings"
  (with-temp-buffer
    (insert "foo whatever end-foo")
    (goto-char (point-min))
    (should (string-equal "end-foo"
                          (tildify-find-env "foo\\|bar"
                                            '(("foo\\|bar" . ("end-" 0))))))))


(ert-deftest tildify-test-find-env-group-index-bug ()
    "Tests generation of match-string indexes"
  (with-temp-buffer
    (let ((pairs '(("start-\\(foo\\|bar\\)" . ("end-" 1))
                   ("open-\\(foo\\|bar\\)" . ("close-" 1))))
          (beg-re "start-\\(foo\\|bar\\)\\|open-\\(foo\\|bar\\)"))
      (insert "open-foo whatever close-foo")
      (goto-char (point-min))
      (should (string-equal "close-foo" (tildify-find-env beg-re pairs))))))


(defun tildify-space-test--test (modes nbsp env-open)
  (with-temp-buffer
    (dolist (mode modes)
      (erase-buffer)
      (funcall mode)
      (let ((header (concat "Testing `tildify-space' in "
                            (symbol-name mode) "\n")))
        (insert header "Lorem v ")
        (should (tildify-space))
        (should (string-equal (concat header "Lorem v" nbsp) (buffer-string))))
      (erase-buffer)
      (let ((header (concat "Testing `tildify-space' in "
                            (symbol-name mode) "\n")))
        (insert header env-open "Lorem v ")
        (should (not (tildify-space)))
        (should (string-equal (concat header env-open "Lorem v ")
                              (buffer-string)))))))

(ert-deftest tildify-space-test-html ()
  "Tests auto-tildification in an HTML document"
  (tildify-space-test--test '(html-mode sgml-mode) "&nbsp;" "<pre>"))

(ert-deftest tildify-space-test-xml ()
  "Tests auto-tildification in an XML document"
  (tildify-space-test--test '(nxml-mode) "&#160;" "<! -- "))

(ert-deftest tildify-space-test-tex ()
  "Tests tildification in a TeX document"
  (tildify-space-test--test '(tex-mode latex-mode plain-tex-mode)
                           "~" "\\verb# "))


(provide 'tildify-tests)

;;; tildify-tests.el ends here

debug log:

solving 7ba270a ...
found 7ba270a in https://yhetil.org/emacs/1413473652-26262-2-git-send-email-mina86@mina86.com/
found 53c2e62 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 53c2e620195bcbe3895054e2cafaf8a6c7df9f4d	test/automated/tildify-tests.el

applying [1/1] https://yhetil.org/emacs/1413473652-26262-2-git-send-email-mina86@mina86.com/
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el
index 53c2e62..7ba270a 100644

Checking patch test/automated/tildify-tests.el...
Applied patch test/automated/tildify-tests.el cleanly.

index at:
100644 7ba270a11de481befa576c76eec9598a36fc5e90	test/automated/tildify-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.