1 ;;;; markdown-test.el --- Tests for markdown-mode
3 ;; Copyright (C) 2013 Jason R. Blevins <jrblevin@sdf.org>
4 ;; Copyright (C) 2013 Makoto Motohashi <mkt.motohashi@gmail.com>
6 ;; This file is not part of GNU Emacs.
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 2, or (at your option)
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, write to the Free Software
20 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
25 ;; This file contains the `markdown-mode' test suite. To run the tests:
27 ;; M-x load-file RET markdown-test.el RET
28 ;; M-x markdown-test RET
32 (unless (featurep 'markdown-mode
)
33 (require 'markdown-mode
))
35 (defconst markdown-test-dir
36 (expand-file-name (file-name-directory
37 (or load-file-name buffer-file-name
))))
39 (defmacro markdown-test-string
(string &rest body
)
40 "Run body in a temporary buffer containing STRING."
43 (setq-default indent-tabs-mode nil
)
45 (goto-char (point-min))
46 (font-lock-fontify-buffer)
47 (prog1 ,@body
(kill-buffer))))
48 (def-edebug-spec markdown-test-string
(form body
))
50 (defmacro markdown-test-file
(file &rest body
)
51 "Open FILE from `markdown-test-dir' and execute body."
52 `(let ((fn (concat markdown-test-dir
,file
)))
53 (save-window-excursion
55 (insert-file-contents fn
)
57 (goto-char (point-min))
58 (font-lock-fontify-buffer)
60 (def-edebug-spec markdown-test-file
(form body
))
62 (defmacro markdown-test-file-gfm
(file &rest body
)
63 "Open FILE from `markdown-test-dir' and execute body."
64 `(let ((fn (concat markdown-test-dir
,file
)))
65 (save-window-excursion
67 (insert-file-contents fn
)
69 (goto-char (point-min))
70 (font-lock-fontify-buffer)
72 (def-edebug-spec markdown-test-file-gfm
(form body
))
74 (defmacro markdown-test-temp-file
(file &rest body
)
75 "Open FILE from `markdown-test-dir' visiting temp file and execute body.
76 This file is not saved."
77 `(let ((fn (concat markdown-test-dir
,file
))
78 (tmp (make-temp-file "markdown-test" nil
".text"))
80 (save-window-excursion
81 (setq buf
(find-file tmp
))
82 (insert-file-contents fn
)
84 (goto-char (point-min))
85 (font-lock-fontify-buffer)
87 (set-buffer-modified-p nil
)
90 (def-edebug-spec markdown-test-temp-file
(form body
))
92 (defun markdown-test-range-has-property (begin end prop value
)
93 "Verify that the range from BEGIN to END has property PROP equal to VALUE."
95 (dolist (loc (number-sequence begin end
))
96 (setq props
(get-char-property loc prop
))
97 (cond ((and props
(listp props
))
98 (should (memq value props
)))
100 (should (eq props value
)))))))
102 (defun markdown-test-range-has-face (begin end face
)
103 "Verify that the range from BEGIN to END has face equal to FACE."
104 (markdown-test-range-has-property begin end
'face face
))
106 (defun markdown-test-goto-heading (title)
107 "Move the point to section with TITLE."
108 (let ((regexp (format "\\(^#+ %s\\( #+\\)?\\|^%s\n[=-]+\n\\)" title title
)))
109 (if (re-search-forward regexp nil t
)
110 (goto-char (match-end 0)))))
112 (defun markdown-test ()
113 "Run all defined tests for `markdown-mode'."
119 (ert-deftest test-markdown-example
/string
()
120 "An example string test using the `ert' framework."
121 (markdown-test-string "foo *bar* baz"
124 (should (looking-at "bar"))))
126 (ert-deftest test-markdown-example
/file
()
127 "An example file test using the `ert' framework."
128 (markdown-test-file "inline.text"
130 (should (looking-at "\*"))))
132 ;;; Basic mode tests:
134 (ert-deftest test-markdown-mode
/variables
()
135 "Test `markdown-mode' variables."
136 (markdown-test-file "inline.text"
137 (should (= tab-width
4))
138 (should (eq font-lock-multiline t
))
139 (should (eq major-mode
'markdown-mode
))))
141 ;;; Element insertion tests:
143 (ert-deftest test-markdown-insertion
/blank-line-before-1
()
144 "Test function `markdown-ensure-blank-line-before' at beginning of line."
145 (markdown-test-file "syntax.text"
146 (search-forward "as plain text")
147 (should (= (point) 1556))
149 (should (= (point) 1505))
150 (should (looking-back "A Markdown-formatted\n"))
151 (should (not (markdown-prev-line-blank-p)))
152 (markdown-ensure-blank-line-before)
153 (should (looking-back "A Markdown-formatted\n\n"))
154 (should (markdown-prev-line-blank-p))))
156 (ert-deftest test-markdown-insertion
/blank-line-before-2
()
157 "Test function `markdown-ensure-blank-line-before' in middle of line."
158 (markdown-test-file "syntax.text"
159 (search-forward "as plain text")
160 (should (= (point) 1556))
161 (should (looking-back "as plain text"))
162 (should (not (markdown-prev-line-blank-p)))
163 (markdown-ensure-blank-line-before)
164 (should (looking-back "as plain text\n\n"))
165 (should (markdown-prev-line-blank-p))))
167 (ert-deftest test-markdown-insertion
/blank-line-before-3
()
168 "Test function `markdown-ensure-blank-line-before' with blank line before."
169 (markdown-test-file "syntax.text"
170 (search-forward "web.\n\nMarkdown is not a replacement for HTML")
172 (should (= (point) 2704))
173 (should (looking-back "web.\n\n"))
174 (should (markdown-prev-line-blank-p))
175 (markdown-ensure-blank-line-before)
176 (should (= (point) 2704))
177 (should (looking-back "web.\n\n"))
178 (should (markdown-prev-line-blank-p))))
180 (ert-deftest test-markdown-insertion
/blank-line-before-4
()
181 "Test function `markdown-ensure-blank-line-before' at beginning of buffer."
182 (markdown-test-string "first line"
185 (should (= (point-max) 11))
186 (markdown-ensure-blank-line-before)
187 (should (= (point-max) 11))
188 (should (string-equal (buffer-substring (point-min) (point-max))
191 (markdown-ensure-blank-line-before)
192 (should (string-equal (buffer-substring (point-min) (point-max))
195 (ert-deftest test-markdown-insertion
/blank-line-after-1
()
196 "Test function `markdown-ensure-blank-line-after' at end of line."
197 (markdown-test-file "syntax.text"
198 (search-forward "as plain text")
199 (should (= (point) 1556))
201 (should (= (point) 1573))
202 (should (looking-at "\nlike it's been"))
203 (should (not (markdown-next-line-blank-p)))
204 (markdown-ensure-blank-line-after)
205 (should (looking-at "\n\nlike it's been"))
206 (should (markdown-next-line-blank-p))))
208 (ert-deftest test-markdown-insertion
/blank-line-after-2
()
209 "Test function `markdown-ensure-blank-line-after' in middle of line."
210 (markdown-test-file "syntax.text"
211 (search-forward "as plain text")
212 (should (= (point) 1556))
213 (should (looking-at ", without looking"))
214 (should (not (markdown-next-line-blank-p)))
215 (markdown-ensure-blank-line-after)
216 (should (looking-at "\n\n, without looking"))
217 (should (markdown-next-line-blank-p))))
219 (ert-deftest test-markdown-insertion
/blank-line-after-3
()
220 "Test function `markdown-ensure-blank-line-after' with blank line after."
221 (markdown-test-file "syntax.text"
222 (search-forward "*writing* for the web.")
223 (should (= (point) 2702))
224 (should (looking-at "\n\nMarkdown is not a replacement for HTML"))
225 (should (markdown-next-line-blank-p))
226 (markdown-ensure-blank-line-after)
227 (should (= (point) 2702))
228 (should (looking-at "\n\nMarkdown is not a replacement for HTML"))
229 (should (markdown-next-line-blank-p))))
231 (ert-deftest test-markdown-insertion
/blank-line-after-4
()
232 "Test function `markdown-ensure-blank-line-after' at end of buffer."
233 (markdown-test-string "last line"
236 (should (= (point-max) 10))
237 (markdown-ensure-blank-line-after)
238 (should (= (point-max) 10))
239 (should (string-equal (buffer-substring (point-min) (point-max))
242 (markdown-ensure-blank-line-after)
243 (should (string-equal (buffer-substring (point-min) (point-max))
246 (ert-deftest test-markdown-insertion
/point-after-unwrap
()
247 "Test new point position calculations after unwrap operations."
248 (markdown-test-string "line **one**\n"
249 (let ((prefix (cons 6 8)) (suffix (cons 11 13)))
251 (should (eq (markdown-point-after-unwrap 6 prefix suffix
) 6))
252 (should (eq (markdown-point-after-unwrap 7 prefix suffix
) 6))
254 (should (eq (markdown-point-after-unwrap 8 prefix suffix
) 6))
255 (should (eq (markdown-point-after-unwrap 9 prefix suffix
) 7))
256 (should (eq (markdown-point-after-unwrap 10 prefix suffix
) 8))
258 (should (eq (markdown-point-after-unwrap 11 prefix suffix
) 9))
259 (should (eq (markdown-point-after-unwrap 12 prefix suffix
) 9))
261 (should (eq (markdown-point-after-unwrap 13 prefix suffix
) 9))))
262 (markdown-test-string "line _one_\n"
263 (let ((prefix (cons 6 7)) (suffix (cons 10 11)))
265 (should (eq (markdown-point-after-unwrap 6 prefix suffix
) 6))
267 (should (eq (markdown-point-after-unwrap 7 prefix suffix
) 6))
268 (should (eq (markdown-point-after-unwrap 8 prefix suffix
) 7))
269 (should (eq (markdown-point-after-unwrap 9 prefix suffix
) 8))
271 (should (eq (markdown-point-after-unwrap 10 prefix suffix
) 9))
273 (should (eq (markdown-point-after-unwrap 10 prefix suffix
) 9)))))
275 (ert-deftest test-markdown-insertion
/unwrap-thing-at-point-italic
()
276 "Test function `markdown-unwrap-thing-at-point' on italics."
277 (markdown-test-file "syntax.text"
280 (should (thing-at-point-looking-at markdown-regex-italic
))
281 (should (equal (markdown-unwrap-thing-at-point
282 markdown-regex-italic
2 4)
284 (should (= (point) 2859))
285 ;; Unwrap *publishing*
287 (should (thing-at-point-looking-at markdown-regex-italic
))
288 (should (equal (markdown-unwrap-thing-at-point
289 markdown-regex-italic
2 4)
291 (should (= (point) 3063))
294 (should (thing-at-point-looking-at markdown-regex-italic
))
295 (should (equal (markdown-unwrap-thing-at-point
296 markdown-regex-italic
2 4)
298 (should (= (point) 3100))))
300 (ert-deftest test-markdown-insertion
/unwrap-things-in-region-italic
()
301 "Test function `markdown-unwrap-things-in-region' on italics."
302 (markdown-test-file "syntax.text"
303 (should (equal (markdown-unwrap-things-in-region
304 2704 3207 markdown-regex-italic
2 4)
307 (ert-deftest test-markdown-insertion
/unwrap-things-in-region-bound
()
308 "Ensure that `markdown-unwrap-things-in-region' respects end bound"
309 (markdown-test-string "**a** **b** **c** **d** **e** **f**"
310 ;; Set region to unrwap a, b, c, and d only. If endpoint is not
311 ;; respected (i.e, not adjusted for character removal), the
312 ;; function will unwrap e and f also.
313 (should (equal (markdown-unwrap-things-in-region
314 1 24 markdown-regex-bold
2 4)
316 (should (string-equal (buffer-string) "a b c d **e** **f**"))))
318 (ert-deftest test-markdown-insertion
/unwrap-things-in-region-links
()
319 "Test function `markdown-unwrap-things-in-region' on inline links."
320 (markdown-test-string "a [link](http://jblevins.org/) or [two](/).\n"
321 (should (equal (markdown-unwrap-things-in-region
322 (point-min) (point-max) markdown-regex-link-inline
0 3)
324 (should (string-equal (buffer-string) "a link or two.\n"))))
326 (ert-deftest test-markdown-insertion
/toggle-bold
()
327 "Test toggling functionality of `markdown-insert-bold'."
328 (markdown-test-string "one **two** three"
330 (markdown-insert-bold)
331 (should (string-equal (buffer-string) "one two three"))
332 (should (= (point) 8))
334 (markdown-insert-bold)
335 (should (= (point) 16))
336 (should (string-equal (buffer-string) "one two **three**"))))
338 (ert-deftest test-markdown-insertion
/toggle-italic
()
339 "Test toggling functionality of `markdown-insert-italic'."
340 (markdown-test-string "one *two* three"
342 (markdown-insert-italic)
343 (should (string-equal (buffer-string) "one two three"))
344 (should (= (point) 8))
346 (markdown-insert-italic)
347 (should (string-equal (buffer-string) "one two *three*"))
348 (should (= (point) 15))))
350 (ert-deftest test-markdown-insertion
/toggle-code
()
351 "Test toggling functionality of `markdown-insert-code'."
352 (markdown-test-string "one `two` three"
354 (markdown-insert-code)
355 (should (string-equal (buffer-string) "one two three"))
356 (should (= (point) 8))
358 (markdown-insert-code)
359 (should (string-equal (buffer-string) "one two `three`"))
360 (should (= (point) 15))))
362 (ert-deftest test-markdown-insertion
/toggle-wiki-link-alias-first
()
363 "Test toggling of `markdown-insert-wiki-link' with alias first.
364 Test point position upon removal and insertion."
365 (let ((markdown-wiki-link-alias-first t
))
366 (markdown-test-string "[[text|page]]"
367 (goto-char 5) ; point in interior of alias text, at 'x'
368 (call-interactively 'markdown-insert-wiki-link
)
369 (should (= (point) 3)) ; leave point at, at 'x'
370 (should (string-equal (buffer-string) "text"))
371 (call-interactively 'markdown-insert-wiki-link
)
372 (should (= (point) 5)) ; leave point at, at 'x'
373 (should (string-equal (buffer-string) "[[text]]")))
374 (markdown-test-string "[[text|page]]"
375 (goto-char 10) ; point in interior of link text, at 'g'
376 (call-interactively 'markdown-insert-wiki-link
)
377 (should (= (point) 5)) ; leave point at end of alias text
378 (should (string-equal (buffer-string) "text"))
379 (call-interactively 'markdown-insert-wiki-link
)
380 (should (= (point) 7)) ; leave point at end of alias text
381 (should (string-equal (buffer-string) "[[text]]")))))
383 (ert-deftest test-markdown-insertion
/toggle-wiki-link-alias-last
()
384 "Test toggling of `markdown-insert-wiki-link' with alias last.
385 Test point position upon removal and insertion."
386 (let ((markdown-wiki-link-alias-first nil
))
387 (markdown-test-string "[[page|text]]"
388 (goto-char 10) ; point in interior of alias text, at 'x'
389 (call-interactively 'markdown-insert-wiki-link
)
390 (goto-char 3) ; leave point at, at 'x'
391 (should (string-equal (buffer-string) "text"))
392 (call-interactively 'markdown-insert-wiki-link
)
393 (should (= (point) 5)) ; leave point at, at 'x'
394 (should (string-equal (buffer-string) "[[text]]")))
395 (markdown-test-string "[[page|text]]"
396 (goto-char 3) ; point in interior of link text, at 'g'
397 (call-interactively 'markdown-insert-wiki-link
)
398 (should (= (point) 1)) ; leave point at beginning of alias text
399 (should (string-equal (buffer-string) "text"))
400 (call-interactively 'markdown-insert-wiki-link
)
401 (should (= (point) 3)) ; leave point at beginning of alias text
402 (should (string-equal (buffer-string) "[[text]]")))))
404 (ert-deftest test-markdown-insertion
/bold-region
()
405 "Test region functionality of `markdown-insert-bold'."
406 (markdown-test-string "one two three"
407 (push-mark (point) t t
)
409 (markdown-insert-bold)
410 (should (string-equal (buffer-string) "**one two** three"))
411 (should (= (point) 10))))
413 (ert-deftest test-markdown-insertion
/italic-region
()
414 "Test region functionality of `markdown-insert-italic'."
415 (markdown-test-string "one two three"
416 (transient-mark-mode)
417 (push-mark (point) t t
)
419 (markdown-insert-italic)
420 (should (string-equal (buffer-string) "*one two* three"))
421 (should (= (point) 9))))
423 (ert-deftest test-markdown-insertion
/code-region
()
424 "Test region functionality of `markdown-insert-code'."
425 (markdown-test-string "one two three"
426 (transient-mark-mode)
427 (push-mark (point) t t
)
429 (markdown-insert-code)
430 (should (string-equal (buffer-string) "`one two` three"))
431 (should (= (point) 9))))
433 (ert-deftest test-markdown-insertion
/atx-line
()
434 "Test ATX header insertion without region."
435 (markdown-test-string "line one\nline two\n"
437 (markdown-insert-header-atx-1)
438 (should (string-equal (buffer-substring (point-min) (point-max))
439 "# line one #\n\nline two\n"))
441 (markdown-insert-header-atx-2)
442 (should (string-equal (buffer-substring (point-min) (point-max))
443 "# line one #\n\n## line two ##\n\n"))))
445 (ert-deftest test-markdown-insertion
/atx-region
()
446 "Test ATX header insertion with region."
447 (markdown-test-string "line one\nline two\n"
448 (transient-mark-mode)
450 (push-mark (point) t t
)
452 (should (string-equal (buffer-substring (region-beginning) (region-end))
454 (markdown-insert-header-atx-4)
455 (should (string-equal (buffer-substring (point-min) (point-max))
456 "line \n\n#### one ####\n\nline two\n"))))
458 (ert-deftest test-markdown-insertion
/atx-blank
()
459 "Test ATX header insertion on blank line."
460 (markdown-test-string "line one\n\nline two\n"
462 (markdown-insert-header-atx-3)
463 (should (string-equal (buffer-substring (point-min) (point-max))
464 "line one\n\n### ###\n\nline two\n"))
465 (should (= (point) 15))
466 (should (looking-at " ###\n"))))
468 (ert-deftest test-markdown-insertion
/atx-region-whitespace
()
469 "Test ATX header insertion using a region with whitespace."
470 (markdown-test-string " line one\n\nline two\n \n"
471 (transient-mark-mode)
472 (push-mark (point) t t
)
473 (goto-char (point-max))
474 (markdown-insert-header-atx-2)
475 (should (string-equal (buffer-substring (point-min) (point-max))
476 "## line one line two ##"))
477 (should (= (point) 21))
478 (should (looking-at " ##"))))
480 (ert-deftest test-markdown-insertion
/atx-line-whitespace
()
481 "Test ATX header insertion using current line with whitespace."
482 (markdown-test-string " line one \n\nline two\n"
483 (goto-char (line-end-position))
484 (markdown-insert-header-atx-3)
485 (should (string-equal (buffer-substring (point-min) (point-max))
486 "### line one ###\n\nline two\n"))
487 (should (= (point) 13))
488 (should (looking-at " ###\n"))))
490 (ert-deftest test-markdown-insertion
/atx-replace-atx
()
491 "Test ATX header insertion when replacing an existing ATX header."
492 (markdown-test-string "## replace ##\n"
493 (markdown-insert-header-atx-4)
494 (should (string-equal (buffer-string) "#### replace ####\n\n"))
495 (should (looking-at " ####\n"))))
497 (ert-deftest test-markdown-insertion
/atx-replace-setext-1
()
498 "Test ATX header insertion when replacing an existing setext header."
499 (markdown-test-string "replace\n=======\n"
500 (markdown-insert-header-atx-2)
501 (should (string-equal (buffer-string) "## replace ##\n\n"))
502 (should (looking-at " ##\n"))))
504 (ert-deftest test-markdown-insertion
/atx-replace-setext-2
()
505 "Test ATX header insertion when replacing an existing setext header."
506 (markdown-test-string "replace\n-------\n"
507 (markdown-insert-header-atx-5)
508 (should (string-equal (buffer-string) "##### replace #####\n\n"))
509 (should (looking-at " #####\n"))))
511 (ert-deftest test-markdown-insertion
/setext-line
()
512 "Test setext header insertion without region."
513 (markdown-test-string "line one\nline two\n"
515 (markdown-insert-header-setext-1)
516 (should (string-equal (buffer-substring (point-min) (point-max))
517 "line one\n========\n\nline two\n"))
519 (markdown-insert-header-setext-2)
520 (should (string-equal (buffer-substring (point-min) (point-max))
521 "line one\n========\n\nline two\n--------\n\n"))))
523 (ert-deftest test-markdown-insertion
/setext-region
()
524 "Test setext header insertion with region."
525 (markdown-test-string "line one\nline two\n"
526 (transient-mark-mode)
528 (push-mark (point) t t
)
530 (should (string-equal (buffer-substring (region-beginning) (region-end))
532 (markdown-insert-header-setext-1)
533 (should (string-equal (buffer-substring (point-min) (point-max))
534 "line \n\none\n===\n\nline two\n"))))
536 (ert-deftest test-markdown-insertion
/setext-blank
()
537 "Test setext header insertion on blank line."
538 (markdown-test-string "line one\n\nline two\n"
540 (markdown-insert-header 2 "foo" t
)
541 (should (string-equal (buffer-substring (point-min) (point-max))
542 "line one\n\nfoo\n---\n\nline two\n"))
543 (should (= (point) 14))
544 (should (looking-at "\n---"))))
546 (ert-deftest test-markdown-insertion
/setext-region-whitespace
()
547 "Test setext header insertion using a region with whitespace."
548 (markdown-test-string " line one\n\nline two\n \n"
549 (transient-mark-mode)
550 (push-mark (point) t t
)
551 (goto-char (point-max))
552 (markdown-insert-header-setext-1)
553 (should (string-equal (buffer-substring (point-min) (point-max))
554 "line one line two\n================="))
555 (should (= (point) 18))
556 (should (looking-at "\n===="))))
558 (ert-deftest test-markdown-insertion
/setext-line-whitespace
()
559 "Test setext header insertion using current line with whitespace."
560 (markdown-test-string " line one \n\nline two\n"
561 (goto-char (line-end-position))
562 (markdown-insert-header-setext-2)
563 (should (string-equal (buffer-substring (point-min) (point-max))
564 "line one\n--------\n\nline two\n"))
565 (should (= (point) 9))
566 (should (looking-at "\n---"))))
568 (ert-deftest test-markdown-insertion
/setext-replace-atx
()
569 "Test setext header insertion when replacing an existing ATX header."
570 (markdown-test-string "## replace ##\n"
571 (markdown-insert-header-setext-1)
572 (should (string-equal (buffer-string) "replace\n=======\n\n"))
573 (should (looking-at "\n==="))))
575 (ert-deftest test-markdown-insertion
/setext-replace-setext-1
()
576 "Test setext header insertion when replacing an existing setext title."
577 (markdown-test-string "replace\n=======\n"
578 (markdown-insert-header-setext-2)
579 (should (string-equal (buffer-string) "replace\n-------\n\n"))
580 (should (looking-at "\n---"))))
582 (ert-deftest test-markdown-insertion
/setext-replace-setext-2
()
583 "Test setext header insertion when replacing an existing setext section."
584 (markdown-test-string "replace\n-------\n"
585 (markdown-insert-header-setext-1)
586 (should (string-equal (buffer-string) "replace\n=======\n\n"))
587 (should (looking-at "\n==="))))
589 (ert-deftest test-markdown-insertion
/header-dwim
()
590 "Test 'do what I mean' header insertion."
591 (markdown-test-file "outline.text"
592 (call-interactively 'markdown-insert-header-dwim
)
593 (should (looking-at " #$"))
595 (call-interactively 'markdown-insert-header-dwim
)
597 (should (looking-at "^# #$"))
599 (call-interactively 'markdown-insert-header-dwim
)
601 (should (looking-at "^### ###$"))))
603 (ert-deftest test-markdown-insertion
/header-dwim-prefix
()
604 "Test 'do what I mean' header insertion with prefix arguments."
605 (let ((tests (list '(nil .
"# abc #")
609 '(4 .
"#### abc ####")
610 '(5 .
"##### abc #####")
611 '(6 .
"###### abc ######")
613 '((16) .
"abc\n---"))))
615 (markdown-test-string "abc"
616 (let ((current-prefix-arg (car test
)))
617 (call-interactively 'markdown-insert-header-dwim
)
618 (should (string-equal (buffer-string) (cdr test
))))))))
620 (ert-deftest test-markdown-insertion
/header-setext-dwim-prefix
()
621 "Test 'do what I mean' header insertion with prefix arguments."
622 (let ((tests (list '(nil .
"abc\n===")
626 '(4 .
"#### abc ####")
627 '(5 .
"##### abc #####")
628 '(6 .
"###### abc ######")
630 '((16) .
"abc\n---"))))
632 (markdown-test-string "abc"
633 (let ((current-prefix-arg (car test
)))
634 (call-interactively 'markdown-insert-header-setext-dwim
)
635 (should (string-equal (buffer-string) (cdr test
))))))))
637 (ert-deftest test-markdown-insertion
/remove-header
()
638 "Test ATX and setext header."
639 (markdown-test-string
640 "# atx1\n\n## atx2 ##\n\nsetext1\n=======\n\nsetext2\n-------\n"
641 (should (equal (markdown-remove-header) (cons 1 5)))
643 (should (not (markdown-remove-header)))
645 (should (equal (markdown-remove-header) (cons 7 11)))
647 (should (not (markdown-remove-header)))
649 (should (equal (markdown-remove-header) (cons 13 20)))
651 (should (not (markdown-remove-header)))
653 (should (equal (markdown-remove-header) (cons 22 29)))
654 (should (string-equal (buffer-string)
655 "atx1\n\natx2\n\nsetext1\n\nsetext2\n"))))
657 (ert-deftest test-markdown-insertion
/italic-unwrap-region
()
658 "A test of inserting italics with italic text in the region."
659 (markdown-test-string "*foo* bar *baz*"
660 (transient-mark-mode)
661 (push-mark (point) t t
)
663 (markdown-insert-italic)
664 (should (string-equal (buffer-string) "*foo bar baz*"))))
666 (ert-deftest test-markdown-insertion
/bold-unwrap-region
()
667 "A test of inserting bold with italic text in the region."
668 (markdown-test-string "*foo* **bar** *baz*"
669 (transient-mark-mode)
670 (push-mark (point) t t
)
672 (markdown-insert-bold)
673 (should (string-equal (buffer-string) "***foo* bar *baz***"))))
675 (ert-deftest test-markdown-insertion
/code-unwrap-region
()
676 "A test of inserting code with code already in the region."
677 (markdown-test-string "`foo` *bar* `baz`"
678 (transient-mark-mode)
679 (push-mark (point) t t
)
681 (markdown-insert-code)
682 (should (string-equal (buffer-string) "`foo *bar* baz`"))))
684 (ert-deftest test-markdown-insertion
/hr-order
()
685 "Test inserting horizontal rules."
686 (dotimes (n (length markdown-hr-strings
))
687 (markdown-test-string ""
688 (let ((current-prefix-arg n
))
689 (call-interactively 'markdown-insert-hr
))
690 (should (string-equal (buffer-string) (nth (1- n
) markdown-hr-strings
))))))
692 (ert-deftest test-markdown-insertion
/hr-prefix
()
693 "Test inserting horizontal rule with C-u prefix."
694 (markdown-test-string ""
695 (let ((current-prefix-arg '(4)))
696 (call-interactively 'markdown-insert-hr
))
697 (should (string-equal (buffer-string) (car (last markdown-hr-strings
))))))
699 (ert-deftest test-markdown-insertion
/hr-bob
()
700 "Test inserting horizontal rule at beginning of buffer."
701 (markdown-test-string "one line\n"
702 (call-interactively 'markdown-insert-hr
)
703 (should (string-equal (buffer-string)
704 (concat (car markdown-hr-strings
)
705 "\n\none line\n")))))
707 (ert-deftest test-markdown-insertion
/hr-eob
()
708 "Test inserting horizontal rule at end of buffer."
709 (markdown-test-string "one line\n"
711 (call-interactively 'markdown-insert-hr
)
712 (should (string-equal (buffer-string)
713 (concat "one line\n\n" (car markdown-hr-strings
))))))
715 (ert-deftest test-markdown-insertion
/hr-mob
()
716 "Test inserting horizontal rule in middle of buffer."
717 (markdown-test-string "one line\n"
719 (let ((markdown-hr-strings '("----------")))
720 (call-interactively 'markdown-insert-hr
)
721 (should (string-equal (buffer-string)
722 (concat "one\n\n" (car markdown-hr-strings
)
725 (ert-deftest test-markdown-insertion
/pre-region-1
()
726 "Test `markdown-pre-region'."
727 ;; Simple test as non-interactive command
728 (markdown-test-string "line one\nline two\n"
729 (markdown-pre-region (line-beginning-position) (line-end-position))
730 (should (string-equal (buffer-string) " line one\n\nline two\n")))
731 ;; Test removal of whitespace before and after region
732 (markdown-test-string "line one abc\nline two\n"
733 (markdown-pre-region 6 9)
734 (should (string-equal (buffer-string) "line\n\n one\n\nabc\nline two\n")))
735 ;; Simple test as interactive command
736 (markdown-test-string "line one\nline two\n"
737 (push-mark (point) t t
)
739 (call-interactively 'markdown-pre-region
)
740 (should (string-equal (buffer-string) " line one\n line two\n\n"))))
742 (ert-deftest test-markdown-insertion
/blockquote-region-1
()
743 "Test `markdown-blockquote-region'."
744 ;; Simple test as non-interactive command
745 (markdown-test-string "line one\nline two\n"
746 (markdown-blockquote-region (line-beginning-position) (line-end-position))
747 (should (string-equal (buffer-string) "> line one\n\nline two\n")))
748 ;; Test removal of whitespace before and after region
749 (markdown-test-string "line one abc\nline two\n"
750 (markdown-blockquote-region 6 9)
751 (should (string-equal (buffer-string) "line\n\n> one\n\nabc\nline two\n")))
752 ;; Simple test as interactive command
753 (markdown-test-string "line one\nline two\n"
754 (push-mark (point) t t
)
756 (call-interactively 'markdown-blockquote-region
)
757 (should (string-equal (buffer-string) "> line one\n> line two\n\n"))))
759 (ert-deftest test-markdown-insertion
/pre-nested-lists
()
760 "Test `markdown-pre-indentation' and `markdown-insert-pre' with nested list."
761 (markdown-test-string "* item\n * item\n"
762 ;; before the first item
763 (should (string-equal (markdown-pre-indentation (point)) " "))
764 (markdown-insert-pre)
766 (should (markdown-prev-line-blank-p))
767 (should (looking-at "^ $"))
768 (should (markdown-next-line-blank-p))
769 ;; before the second item
771 (should (string-equal (markdown-pre-indentation (point)) " "))
772 (markdown-insert-pre)
774 (should (markdown-prev-line-blank-p))
775 (should (looking-at "^ $"))
776 (should (markdown-next-line-blank-p))
777 ;; after the second item
779 (should (string-equal (markdown-pre-indentation (point)) " "))
780 (markdown-insert-pre)
782 (should (markdown-prev-line-blank-p))
783 (should (looking-at "^ $"))
784 (should (markdown-next-line-blank-p))))
786 (ert-deftest test-markdown-insertion
/pre-faux-list
()
787 "Test `markdown-pre-indentation' following a list-marker in a pre block."
788 (markdown-test-string " * pre block, not a list item\n"
789 (should (string-equal (markdown-pre-indentation (point-max)) " "))))
791 (ert-deftest test-markdown-insertion
/blockquote-nested-lists
()
792 "Test blockquote insertion in a nested list context."
793 (markdown-test-string "* item\n * item\n"
794 ;; before the first item
795 (should (string-equal (markdown-blockquote-indentation (point)) ""))
796 (markdown-insert-blockquote)
798 (should (markdown-prev-line-blank-p))
799 (should (looking-at "^> $"))
800 (should (markdown-next-line-blank-p))
801 ;; before the second item
803 (should (string-equal (markdown-blockquote-indentation (point)) " "))
804 (markdown-insert-blockquote)
806 (should (markdown-prev-line-blank-p))
807 (should (looking-at "^ > $"))
808 (should (markdown-next-line-blank-p))
809 ;; after the second item
811 (should (string-equal (markdown-blockquote-indentation (point)) " "))
812 (markdown-insert-blockquote)
814 (should (markdown-prev-line-blank-p))
815 (should (looking-at "^ > $"))
816 (should (markdown-next-line-blank-p))))
818 (ert-deftest test-markdown-insertion
/empty-italic
()
819 "Test `markdown-insert-italic' with no word at point and no region."
820 (markdown-test-string ""
821 (call-interactively 'markdown-insert-italic
)
822 (should (string-equal (buffer-string) "**"))
823 (should (= (point) 2))))
825 (ert-deftest test-markdown-insertion
/empty-bold
()
826 "Test `markdown-insert-bold' with no word at point and no region."
827 (markdown-test-string ""
828 (call-interactively 'markdown-insert-bold
)
829 (should (string-equal (buffer-string) "****"))
830 (should (= (point) 3))))
832 (ert-deftest test-markdown-insertion
/uri
()
833 "Test `markdown-insert-uri'."
834 (markdown-test-string "http://jblevins.org/projects/markdown-mode/"
835 (call-interactively 'markdown-insert-uri
)
836 (should (string-equal (buffer-string) "<http://jblevins.org/projects/markdown-mode/>"))
837 (should (= (point) 2))
838 (call-interactively 'markdown-insert-uri
)
839 (should (string-equal (buffer-string) "http://jblevins.org/projects/markdown-mode/"))
840 (should (= (point) 1))
842 (call-interactively 'markdown-insert-uri
)
843 (should (string-equal (buffer-string) "<>"))
844 (should (= (point) 2))))
846 (ert-deftest test-markdown-insertion
/list-item
()
847 "Test `markdown-insert-list-item' on several lists."
849 (markdown-test-string "abc"
850 (goto-char (point-max))
851 (call-interactively 'markdown-insert-list-item
)
852 (should (string-equal (buffer-string) "abc\n* "))
853 (should (= (point) 7)))
854 ;; Following a list item, on the same line
855 (markdown-test-string " * foo"
856 (goto-char (point-max))
857 (call-interactively 'markdown-insert-list-item
)
858 (should (string-equal (buffer-string) " * foo\n * ")))
859 ;; Following a list item, on the next line
860 (markdown-test-string "- foo\n"
861 (goto-char (point-max))
862 (call-interactively 'markdown-insert-list-item
)
863 (should (string-equal (buffer-string) "- foo\n- ")))
864 ;; Following a list item, after a blank line
865 (markdown-test-string "- foo\n\n"
866 (goto-char (point-max))
867 (call-interactively 'markdown-insert-list-item
)
868 (should (string-equal (buffer-string) "- foo\n\n- ")))
869 ;; Preceding a list item
870 (markdown-test-string "- foo\n"
871 (goto-char (point-min))
872 (call-interactively 'markdown-insert-list-item
)
873 (should (string-equal (buffer-string) "- \n- foo\n")))
874 ;; Preceding a list item and a blank line
875 (markdown-test-string "\n\n- foo\n"
876 (goto-char (point-min))
877 (call-interactively 'markdown-insert-list-item
)
878 (should (string-equal (buffer-string) "- \n\n- foo\n")))
879 ;; In the middle of a list item
880 (markdown-test-string "- foo bar\n"
882 (call-interactively 'markdown-insert-list-item
)
883 (should (string-equal (buffer-string) "- foo\n- bar\n")))
884 ;; Before a list marker, but not at beginning of line
885 (markdown-test-string " - foo\n"
887 (call-interactively 'markdown-insert-list-item
)
888 (should (string-equal (buffer-string) " - \n - foo\n")))
889 ;; Following an ordered list item
890 (markdown-test-string "6. foo"
891 (goto-char (point-max))
892 (call-interactively 'markdown-insert-list-item
)
893 (should (string-equal (buffer-string) "6. foo\n7. ")))
894 ;; Following a nested ordered list item
895 (markdown-test-string "6. foo\n 1. bar"
896 (goto-char (point-max))
897 (call-interactively 'markdown-insert-list-item
)
898 (should (string-equal (buffer-string) "6. foo\n 1. bar\n 2. "))))
900 (ert-deftest test-markdown-insertion
/reference-link
()
901 "Basic tests for `markdown-insert-reference-link'."
902 ;; Test optional parameters (leave point after link)
903 (markdown-test-string ""
904 (markdown-insert-reference-link "abc" "1")
905 (should (string-equal (buffer-string) "[abc][1]"))
906 (should (= (point) 9)))
907 ;; Full link without title (leave point after link)
908 (markdown-test-string ""
909 (markdown-insert-reference-link "link" "label" "http://jblevins.org/")
910 (should (string-equal (buffer-string) "[link][label]\n\n[label]: http://jblevins.org/\n"))
911 (should (= (point) 14)))
912 ;; Full link without label or title (leave point after link)
913 (markdown-test-string ""
914 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
915 (should (string-equal (buffer-string) "[link][]\n\n[link]: http://jblevins.org/\n"))
916 (should (= (point) 9)))
917 ;; Link only with no label, URL, or title (leave point after link)
918 (markdown-test-string ""
919 (markdown-insert-reference-link "link" "")
920 (should (string-equal (buffer-string) "[link][]"))
921 (should (= (point) 9))))
923 (ert-deftest test-markdown-insertion
/reference-link-end
()
924 "Basic reference link insertion test for 'end location."
925 (let ((markdown-reference-location 'end
))
926 (markdown-test-string "first para\n\nsecond para\n"
928 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
929 (should (= (point) 19))
931 (should (looking-at "\\[link\\]: http://jblevins.org/")))))
933 (ert-deftest test-markdown-insertion
/reference-link-immediately
()
934 "Basic reference link insertion test for 'immediately location."
935 (let ((markdown-reference-location 'immediately
))
936 (markdown-test-string "first para\n\nsecond para\n"
938 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
939 (should (= (point) 19))
941 (should (looking-at "\\[link\\]: http://jblevins.org/")))))
943 (ert-deftest test-markdown-insertion
/reference-link-header
()
944 "Basic reference link insertion test for 'header location."
945 (let ((markdown-reference-location 'header
))
946 (markdown-test-string "par one\n\npar two\n\n### header\n"
948 (markdown-insert-reference-link "link" "" "")
949 (should (= (point) 35))
950 (should (looking-back "\\[link\\]: ")))))
952 (ert-deftest test-markdown-insertion
/inline-link
()
953 "Basic tests for `markdown-insert-link'."
954 ;; Test empty markup insertion (leave point in square brackets)
955 (markdown-test-string "abc "
957 (call-interactively 'markdown-insert-link
)
958 (should (string-equal (buffer-string) "abc []()"))
959 (should (= (point) 6)))
960 ;; Test with word at point (leave point in parentheses)
961 (markdown-test-string "abc def ghi"
963 (call-interactively 'markdown-insert-link
)
964 (should (string-equal (buffer-string) "abc [def]() ghi"))
965 (should (= (point) 11)))
966 ;; Test with region (leave point in parentheses)
967 (markdown-test-string "abc def ghi"
968 (transient-mark-mode)
969 (push-mark (point) t t
)
971 (call-interactively 'markdown-insert-link
)
972 (should (string-equal (buffer-string) "[abc def]() ghi"))
973 (should (= (point) 11))))
977 (ert-deftest test-markdown-footnote
/basic-end
()
978 "Basic footnote insertion and deletion tests for 'end location."
979 (let ((markdown-footnote-location 'end
))
980 (markdown-test-string "first line\nsecond line\n"
981 ;; new buffer with no footnotes
982 (should (= markdown-footnote-counter
0))
983 ;; footnote insertion
985 (markdown-footnote-new)
986 (should (= (point) 35))
987 (should (= markdown-footnote-counter
1))
988 (should (looking-back "\\[^1\\]: "))
989 ;; kill with point in footnote definition
990 (insert "footnote text")
992 (markdown-footnote-kill))
993 (should (= (point) 24))
995 (should (string-equal (buffer-string) "first line\nsecond line\n"))
996 ;; insertion, counter should increment
997 (goto-char (point-min))
999 (markdown-footnote-new)
1000 (should (= (point) 35))
1001 (should (= markdown-footnote-counter
2))
1002 (should (looking-back "\\[^2\\]: "))
1003 (insert "footnote text")
1005 (markdown-footnote-return)
1006 (should (= (point) 15))
1007 (should (looking-back "\\[^2\\]"))
1008 ;; kill with point at marker
1010 (markdown-footnote-kill))
1011 (should (= (point) 11))
1013 (should (string-equal (buffer-string) "first line\nsecond line\n")))))
1015 (ert-deftest test-markdown-footnote
/basic-immediately
()
1016 "Basic footnote insertion and deletion tests for 'immediately location."
1017 (let ((markdown-footnote-location 'immediately
))
1018 (markdown-test-string "first paragraph\n\nsecond paragraph\n"
1019 ;; new buffer with no footnotes
1020 (should (= markdown-footnote-counter
0))
1021 ;; footnote insertion
1023 (markdown-footnote-new)
1024 (should (= (point) 28))
1025 (should (= markdown-footnote-counter
1))
1026 (should (looking-back "\\[^1\\]: "))
1027 ;; kill with point in footnote definition
1028 (insert "footnote text")
1030 (markdown-footnote-kill))
1031 (should (= (point) 18))
1033 (should (string-equal (buffer-string)
1034 "first paragraph\n\nsecond paragraph\n")))))
1036 (ert-deftest test-markdown-footnote
/basic-header
()
1037 "Basic footnote insertion and deletion tests for 'header location."
1038 (let ((markdown-footnote-location 'header
))
1039 (markdown-test-string "par one\n\npar two\n\n### header\n"
1040 ;; new buffer with no footnotes
1041 (should (= markdown-footnote-counter
0))
1042 ;; footnote insertion
1044 (markdown-footnote-new)
1045 (should (= (point) 29))
1046 (should (= markdown-footnote-counter
1))
1047 (should (looking-back "\\[^1\\]: "))
1048 ;; kill with point in footnote definition
1049 (insert "footnote text")
1051 (markdown-footnote-kill))
1052 (should (= (point) 19))
1054 (should (string-equal (buffer-string)
1055 "par one\n\npar two\n\n### header\n"))
1056 ;; insertion, counter should increment
1057 (goto-char (point-min))
1059 (markdown-footnote-new)
1060 (should (= (point) 29))
1061 (should (= markdown-footnote-counter
2))
1062 (should (looking-back "\\[^2\\]: "))
1063 (insert "footnote text")
1065 (markdown-footnote-return)
1066 (should (= (point) 12))
1067 (should (looking-back "\\[^2\\]"))
1068 ;; kill with point at marker
1070 (markdown-footnote-kill))
1071 (should (= (point) 8))
1073 (should (string-equal (buffer-string)
1074 "par one\n\npar two\n\n### header\n")))))
1076 (ert-deftest test-markdown-footnote
/kill-empty-text
()
1077 "Test killing a footnote with marker but no text."
1078 (markdown-test-string "no text[^1]\n\n[^1]: \n"
1080 (markdown-footnote-goto-text)
1081 (should (looking-back "\\[^1\\]: "))
1083 (markdown-footnote-kill))
1084 (should (string-equal (buffer-string) "no text\n"))))
1086 ;;; Element removal tests:
1088 (ert-deftest test-markdown-kill
/simple
()
1089 "Simple tests for `markdown-kill-thing-at-point'."
1090 (let ((kill-ring nil
)
1091 (tests (list '("`foo`" .
"foo")
1092 '("## foo ##" .
"foo")
1094 '("foo\n---" .
"foo")
1095 '("foo\n===" .
"foo")
1096 '("* * * * *" .
"* * * * *")
1097 '("[foo](http://bar.com/)" .
"foo")
1098 '("![foo](http://bar.com/)" .
"foo")
1099 '("[foo][bar]" .
"foo")
1100 '("![foo][bar]" .
"foo")
1101 '("<http://foo.com/>" .
"http://foo.com/")
1102 '("<foo@bar.com>" .
"foo@bar.com")
1103 '("[[foo]]" .
"foo")
1104 '("[[foo|bar]]" .
"foo")
1105 '("**foo**" .
"foo")
1106 '("__foo__" .
"foo")
1109 '(" [foo]: http://bar.com/" .
"http://bar.com/")
1110 '(" [foo]: http://bar.com/ \"title\"" .
"http://bar.com/")
1111 '("foo[^bar]\n\n[^bar]: baz" .
"baz")
1112 '("[^bar]: baz" .
"baz")
1113 '(" * foo\n bar" .
" * foo\n bar"))))
1114 (dolist (test tests
)
1115 ;; Load test string (the car), move to end of first line, kill
1116 ;; thing at point, and then verify that the kill ring contains cdr.
1117 (markdown-test-string (car test
)
1119 (call-interactively 'markdown-kill-thing-at-point
)
1120 (should (string-equal (current-kill 0) (cdr test
)))))))
1122 (ert-deftest test-markdown-kill
/footnote-text
()
1123 "Test killing a footnote with point at footnote text."
1124 (markdown-test-string "some text[^1]\n\n[^1]: footnote\n"
1126 (markdown-footnote-goto-text)
1128 (markdown-footnote-kill))
1129 (should (string-equal (buffer-string) "some text\n"))))
1131 (ert-deftest test-markdown-kill
/code
()
1132 "Test killing with code regex.."
1133 (let ((kill-ring nil
))
1134 (markdown-test-string "Lorem `ipsum` dolor `sit` `amet`."
1135 (goto-char 22) ; position point at s in `sit`
1136 (call-interactively 'markdown-kill-thing-at-point
)
1137 (should (string-equal (current-kill 0) "sit")))))
1139 ;;; Promotion and demotion tests:
1141 (ert-deftest test-markdown-promote
/atx-header
()
1142 "Test `markdown-promote' for atx headers."
1143 (markdown-test-string "###### test ######"
1145 (should (string-equal (buffer-string) "##### test #####"))
1147 (should (string-equal (buffer-string) "#### test ####"))
1149 (should (string-equal (buffer-string) "### test ###"))
1151 (should (string-equal (buffer-string) "## test ##"))
1153 (should (string-equal (buffer-string) "# test #"))
1155 (should (string-equal (buffer-string) "test"))
1157 (should (string-equal (buffer-string) "test"))))
1159 (ert-deftest test-markdown-demote
/atx-header
()
1160 "Test `markdown-demote' for atx headers."
1161 (markdown-test-string "test"
1163 (should (string-equal (buffer-string) "# test #"))
1165 (should (string-equal (buffer-string) "## test ##"))
1167 (should (string-equal (buffer-string) "### test ###"))
1169 (should (string-equal (buffer-string) "#### test ####"))
1171 (should (string-equal (buffer-string) "##### test #####"))
1173 (should (string-equal (buffer-string) "###### test ######"))
1175 (should (string-equal (buffer-string) "###### test ######"))))
1177 (ert-deftest test-markdown-promote
/setext-header
()
1178 "Test `markdown-promote' for setext headers."
1179 (markdown-test-string "test\n----"
1181 (should (string-equal (buffer-string) "test\n===="))
1183 (should (string-equal (buffer-string) "test"))
1185 (should (string-equal (buffer-string) "test"))))
1187 (ert-deftest test-markdown-demote
/setext-header
()
1188 "Test `markdown-demote' for setext headers."
1189 (markdown-test-string "test\n===="
1191 (should (string-equal (buffer-string) "test\n----"))
1193 (should (string-equal (buffer-string) "### test ###"))
1195 (should (string-equal (buffer-string) "#### test ####"))
1197 (should (string-equal (buffer-string) "##### test #####"))
1199 (should (string-equal (buffer-string) "###### test ######"))
1201 (should (string-equal (buffer-string) "###### test ######"))))
1203 (ert-deftest test-markdown-promote
/hr
()
1204 "Test `markdown-promote' for horizontal rules."
1205 (markdown-test-string (car (reverse markdown-hr-strings
))
1206 (dolist (n (number-sequence 4 0 -
1))
1208 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))
1210 (should (string-equal (buffer-string) (nth 0 markdown-hr-strings
)))))
1212 (ert-deftest test-markdown-demote
/hr
()
1213 "Test `markdown-demote' for horizontal rules."
1214 (markdown-test-string (car markdown-hr-strings
)
1215 (dolist (n (number-sequence 1 5))
1217 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))
1219 (should (string-equal (buffer-string) ""))))
1221 ;;; Completion and cycling:
1223 (ert-deftest test-markdown-complete-or-cycle
/atx-header-incomplete
()
1224 "Test `markdown-incomplete-atx-p' for headers with no text."
1225 (markdown-test-string "### ###"
1226 (should (looking-at markdown-regex-header-atx
))
1227 (should-not (markdown-incomplete-atx-p)))
1228 (markdown-test-string "###abc###"
1229 (should (looking-at markdown-regex-header-atx
))
1230 (should (markdown-incomplete-atx-p)))
1231 (markdown-test-string "### ###"
1232 (should (looking-at markdown-regex-header-atx
))
1233 (should (markdown-incomplete-atx-p))))
1235 (ert-deftest test-markdown-complete-or-cycle
/atx-header
()
1236 "Test `markdown-complete-or-cycle' for atx headers."
1237 (markdown-test-string "##### test"
1238 (call-interactively 'markdown-complete-or-cycle
)
1239 (should (string-equal (buffer-string) "##### test #####"))
1240 (call-interactively 'markdown-complete-or-cycle
)
1241 (should (string-equal (buffer-string) "###### test ######"))
1242 (call-interactively 'markdown-complete-or-cycle
)
1243 (should (string-equal (buffer-string) "# test #"))
1244 (call-interactively 'markdown-complete-or-cycle
)
1245 (should (string-equal (buffer-string) "## test ##"))))
1247 (ert-deftest test-markdown-complete-or-cycle
/setext-header
()
1248 "Test `markdown-complete-or-cycle' for setext headers."
1249 (markdown-test-string " test \n=="
1250 (call-interactively 'markdown-complete-or-cycle
)
1251 (should (string-equal (buffer-string) "test\n===="))
1252 (call-interactively 'markdown-complete-or-cycle
)
1253 (should (string-equal (buffer-string) "test\n----"))
1254 (call-interactively 'markdown-complete-or-cycle
)
1255 (should (string-equal (buffer-string) "### test ###"))))
1257 (ert-deftest test-markdown-complete
/hr
()
1258 "Test completion via `markdown-complete-or-cycle' for horizontal rules."
1259 (markdown-test-string "- - - - -"
1260 (call-interactively 'markdown-complete-or-cycle
)
1261 (should (string-equal (buffer-string) (car markdown-hr-strings
)))))
1263 (ert-deftest test-markdown-cycle
/hr
()
1264 "Test cycling via `markdown-complete-or-cycle' for horizontal rules."
1265 (markdown-test-string (car markdown-hr-strings
)
1266 (dolist (n (number-sequence 1 5))
1267 (call-interactively 'markdown-complete-or-cycle
)
1268 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))))
1270 (ert-deftest test-markdown-cycle
/bold
()
1271 "Test cycling via `markdown-complete-or-cycle' for bold markup."
1272 (markdown-test-string "**bold**"
1273 (call-interactively 'markdown-complete-or-cycle
)
1274 (should (string-equal (buffer-string) "__bold__"))
1275 (call-interactively 'markdown-complete-or-cycle
)
1276 (should (string-equal (buffer-string) "**bold**"))))
1278 (ert-deftest test-markdown-cycle
/italic
()
1279 "Test cycling via `markdown-complete-or-cycle' for italic markup."
1280 (markdown-test-string "*italic*"
1281 (call-interactively 'markdown-complete-or-cycle
)
1282 (should (string-equal (buffer-string) "_italic_"))
1283 (call-interactively 'markdown-complete-or-cycle
)
1284 (should (string-equal (buffer-string) "*italic*"))))
1286 ;;; Indentation tests:
1288 (ert-deftest test-markdown-indentation
/calc-indents
()
1289 "Test `markdown-calc-indents' a nested list context."
1290 (markdown-test-file "nested-list.text"
1291 (goto-char (point-max))
1292 (let ((indents (markdown-calc-indents)))
1293 (should (= (car indents
) 17)) ; indentation of previous line first
1294 (should (equal (sort indents
'<)
1296 0 ; beginning of line
1297 3 ; first-level list marker
1298 7 ; second-level list marker
1299 11 ; third-level list marker
1300 13 ; previous list item text
1301 16 ; pre-block indentation
1302 17 ; indentation of previous line
1303 21 ; previous line plus tab-width
1306 (ert-deftest test-markdown-indentation
/indent-region
()
1307 "Test `markdown-indent-region'."
1308 ;; Basic test with multiple lines
1309 (markdown-test-string "abc\ndef\nghi\n"
1310 (markdown-indent-region (point-min) (point-max) nil
)
1311 (should (string-equal (buffer-string) " abc\n def\n ghi\n")))
1312 ;; Following a list item
1313 (markdown-test-string " * abc\ndef\n"
1315 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
1316 (should (string-equal (buffer-string) " * abc\n def\n"))
1317 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
1318 (should (string-equal (buffer-string) " * abc\n def\n"))))
1320 ;;; Font lock tests:
1322 (ert-deftest test-markdown-font-lock
/italics-1
()
1323 "A simple italics test."
1324 (markdown-test-file "inline.text"
1326 (should (looking-at "\*"))
1327 ;; Check face of char before leading asterisk
1328 (markdown-test-range-has-face 8 8 nil
)
1329 ;; Check face of italic range
1330 (markdown-test-range-has-face 9 17 markdown-italic-face
)
1331 ;; Check face of point past leading asterisk
1332 (markdown-test-range-has-face 18 18 nil
)))
1334 (ert-deftest test-markdown-font-lock
/italics-2
()
1335 "Test space after leading asterisk or underscore."
1336 (markdown-test-string
1337 "This is * not italic*, nor _ is this_."
1338 (markdown-test-range-has-face (point-min) (point-max) nil
)))
1340 (ert-deftest test-markdown-font-lock
/italics-3
()
1341 "Test that slash inside asterisks is not italic."
1342 (markdown-test-string
1344 (markdown-test-range-has-face (point-min) (point-max) nil
)))
1346 (ert-deftest test-markdown-font-lock
/italics-4
()
1347 "Test that escaped asterisk inside italics is not bold."
1348 (markdown-test-string
1350 (markdown-test-range-has-face 1 7 nil
)
1351 (markdown-test-range-has-face 8 12 markdown-italic-face
)))
1353 (ert-deftest test-markdown-font-lock
/italics-5
()
1354 "Test italic single letter."
1355 (markdown-test-string
1357 (markdown-test-range-has-face 1 3 markdown-italic-face
)))
1359 (ert-deftest test-markdown-font-lock
/italics-after-hr
()
1360 "Test italics after a horizontal rule with asterisks."
1361 (markdown-test-string "* * *\n\n*italic*\n"
1362 (markdown-test-range-has-face 1 5 markdown-header-face
)
1363 (markdown-test-range-has-face 8 15 markdown-italic-face
)))
1365 (ert-deftest test-markdown-font-lock
/bold-1
()
1366 "A simple bold test."
1367 (markdown-test-file "inline.text"
1369 (should (looking-at "\*\*"))
1370 ;; Check face of char before leading asterisk
1371 (markdown-test-range-has-face 26 26 nil
)
1372 ;; Check face of bold range
1373 (markdown-test-range-has-face 27 35 markdown-bold-face
)
1374 ;; Check face of point past leading asterisk
1375 (markdown-test-range-has-face 36 36 nil
)))
1377 (ert-deftest test-markdown-font-lock
/bold-2
()
1378 "Test space after leading asterisks or underscores."
1379 (markdown-test-string
1380 "This is ** not bold**, nor __ is this__ (but they match italics)."
1381 (markdown-test-range-has-face 1 8 nil
)
1382 (markdown-test-range-has-face 9 20 markdown-italic-face
)
1383 (markdown-test-range-has-face 21 27 nil
)
1384 (markdown-test-range-has-face 28 38 markdown-italic-face
)
1385 (markdown-test-range-has-face 39 (point-max) nil
)))
1387 (ert-deftest test-markdown-font-lock
/bold-3
()
1388 "Test escaped asterisk inside bold."
1389 (markdown-test-string
1391 (markdown-test-range-has-face 6 11 markdown-bold-face
)))
1393 (ert-deftest test-markdown-font-lock
/bold-4
()
1394 "Test bold single letter."
1395 (markdown-test-string
1397 (markdown-test-range-has-face 1 5 markdown-bold-face
)))
1399 (ert-deftest test-markdown-font-lock
/bold-after-hr
()
1400 "Test bold after a horizontal rule with asterisks."
1401 (markdown-test-string "* * *\n\n**bold**\n"
1402 (markdown-test-range-has-face 1 5 markdown-header-face
)
1403 (markdown-test-range-has-face 8 15 markdown-bold-face
)))
1405 (ert-deftest test-markdown-font-lock
/code-1
()
1406 "A simple inline code test."
1407 (markdown-test-file "inline.text"
1409 (should (looking-at "`"))
1410 ;; Regular code span
1411 (markdown-test-range-has-face 45 50 markdown-inline-code-face
)
1412 ;; Code containing backticks
1413 (markdown-test-range-has-face 61 89 markdown-inline-code-face
)
1414 ;; Seven backquotes in a row
1415 (markdown-test-range-has-face 119 125 nil
)
1416 ;; Backquotes at beginning or end
1417 (markdown-test-range-has-face 228 239 markdown-inline-code-face
)
1418 (markdown-test-range-has-face 341 351 markdown-inline-code-face
)
1419 ;; Backslash as final character
1420 (markdown-test-range-has-face 460 468 markdown-inline-code-face
)
1421 ;; Escaping of leading backquotes
1422 (markdown-test-range-has-face 586 592 nil
)
1423 (markdown-test-range-has-face 597 603 nil
)
1424 ;; A code span crossing lines
1425 (markdown-test-range-has-face 652 656 nil
)
1426 (markdown-test-range-has-face 657 666 markdown-inline-code-face
)
1427 ;; Three backquotes: same line, across lines, not across blocks
1428 (markdown-test-range-has-face 695 748 nil
)
1429 (markdown-test-range-has-face 749 757 markdown-inline-code-face
)
1430 (markdown-test-range-has-face 758 805 nil
)
1431 (markdown-test-range-has-face 806 814 markdown-inline-code-face
)
1432 (markdown-test-range-has-face 815 891 nil
)
1435 (ert-deftest test-markdown-font-lock
/code-2
()
1436 "Multiple code spans in a row and on different lines."
1437 (markdown-test-string "`foo` `bar` `baz`"
1438 (markdown-test-range-has-face 1 5 markdown-inline-code-face
)
1439 (markdown-test-range-has-face 6 6 nil
)
1440 (markdown-test-range-has-face 7 11 markdown-inline-code-face
)
1441 (markdown-test-range-has-face 12 12 nil
)
1442 (markdown-test-range-has-face 13 17 markdown-inline-code-face
))
1443 (markdown-test-string "`a`\n`b`\n`c`\n"
1444 (markdown-test-range-has-face 1 3 markdown-inline-code-face
)
1445 (markdown-test-range-has-face 4 4 nil
)
1446 (markdown-test-range-has-face 5 7 markdown-inline-code-face
)
1447 (markdown-test-range-has-face 8 8 nil
)
1448 (markdown-test-range-has-face 9 11 markdown-inline-code-face
)
1449 (markdown-test-range-has-face 12 12 nil
))
1450 (markdown-test-string "a`foo`b`bar`c`baz`d"
1451 (markdown-test-range-has-face 1 1 nil
)
1452 (markdown-test-range-has-face 2 6 markdown-inline-code-face
)
1453 (markdown-test-range-has-face 7 7 nil
)
1454 (markdown-test-range-has-face 8 12 markdown-inline-code-face
)
1455 (markdown-test-range-has-face 13 13 nil
)
1456 (markdown-test-range-has-face 14 18 markdown-inline-code-face
)
1457 (markdown-test-range-has-face 19 19 nil
)))
1459 (ert-deftest test-markdown-font-lock
/lists-1
()
1460 "A simple list marker font lock test."
1461 (markdown-test-file "lists.text"
1462 (dolist (loc (list 1063 1283 1659 1830 1919 2150 2393 2484
1463 2762 2853 3097 3188 3700 3903 4009))
1465 (should (looking-at "[*+-]"))
1466 (markdown-test-range-has-face loc loc markdown-list-face
))))
1468 (ert-deftest test-markdown-font-lock
/pre-1
()
1469 "Nested list and pre block font lock test."
1470 (markdown-test-file "nested-list.text"
1471 (dolist (loc (list 4 29 194 224 491 525))
1472 (markdown-test-range-has-face loc loc markdown-list-face
))
1473 (markdown-test-range-has-face 6 25 nil
)
1474 (markdown-test-range-has-face 31 83 nil
)
1475 (markdown-test-range-has-face 85 155 markdown-pre-face
)
1476 (markdown-test-range-has-face 157 189 nil
)
1477 (markdown-test-range-has-face 196 215 nil
)
1478 (markdown-test-range-has-face 226 403 nil
)
1479 (markdown-test-range-has-face 405 482 markdown-pre-face
)
1480 (markdown-test-range-has-face 493 512 nil
)
1481 (markdown-test-range-has-face 527 546 nil
)
1482 (markdown-test-range-has-face 548 581 markdown-pre-face
)))
1484 (ert-deftest test-markdown-font-lock
/pre-2
()
1485 (markdown-test-string "* item\n\nreset baseline\n\n pre block\n"
1486 (markdown-test-range-has-face 2 24 nil
)
1487 (markdown-test-range-has-face 29 37 markdown-pre-face
)))
1489 (ert-deftest test-markdown-font-lock
/pre-3
()
1490 (markdown-test-string "It is interesting to see what happens when one queries
1491 `social upheaval` and `protopalatial era`.
1493 * `social upheaval`: the follwing queries have been tried:
1495 social upheaval subClassOf"
1496 (markdown-test-range-has-face 160 190 nil
)))
1498 (ert-deftest test-markdown-font-lock
/atx-no-spaces
()
1499 "Test font-lock for atx headers with no spaces."
1500 (markdown-test-string "##abc##"
1501 (markdown-test-range-has-face 1 2 markdown-header-delimiter-face
)
1502 (markdown-test-range-has-face 3 5 markdown-header-face-2
)
1503 (markdown-test-range-has-face 6 7 markdown-header-delimiter-face
))
1504 (markdown-test-string "##"
1505 (markdown-test-range-has-face 1 1 markdown-header-delimiter-face
)
1506 (markdown-test-range-has-face 2 2 markdown-header-face-1
))
1507 (markdown-test-string "###"
1508 (markdown-test-range-has-face 1 2 markdown-header-delimiter-face
)
1509 (markdown-test-range-has-face 3 3 markdown-header-face-2
)))
1511 (ert-deftest test-markdown-font-lock
/setext-1-letter
()
1512 "An edge case for level-one setext headers."
1513 (markdown-test-string "a\n=\n"
1514 (markdown-test-range-has-face 1 1 markdown-header-face-1
)
1515 (markdown-test-range-has-face 3 3 markdown-header-rule-face
)))
1517 (ert-deftest test-markdown-font-lock
/setext-2-letter
()
1518 "An edge case for level-two setext headers."
1519 (markdown-test-string "b\n-\n"
1520 (markdown-test-range-has-face 1 1 markdown-header-face-2
)
1521 (markdown-test-range-has-face 3 3 markdown-header-rule-face
)))
1523 (ert-deftest test-markdown-font-lock
/inline-links
()
1524 "Test font lock for inline links."
1525 (markdown-test-file "inline.text"
1526 (markdown-test-range-has-face 925 930 markdown-link-face
)
1527 (markdown-test-range-has-face 931 950 markdown-url-face
)
1528 (markdown-test-range-has-face 951 957 markdown-link-title-face
)
1529 (markdown-test-range-has-face 958 958 markdown-url-face
)))
1531 (ert-deftest test-markdown-font-lock
/pre-comment
()
1532 "Test comments inside of a pre block."
1533 (markdown-test-string " <!-- pre, not comment -->"
1534 (markdown-test-range-has-face (point-min) (1- (point-max)) markdown-pre-face
)))
1536 (ert-deftest test-markdown-font-lock
/footnote-markers-links
()
1537 "Test an edge case involving footnote markers and inline reference links."
1538 (markdown-test-string "Harvard[^1] [tuition][]"
1539 (markdown-test-range-has-face 8 11 markdown-footnote-face
)
1540 (markdown-test-range-has-face 13 21 markdown-link-face
)
1541 (markdown-test-range-has-face 22 23 markdown-reference-face
)))
1543 (ert-deftest test-markdown-font-lock
/mmd-metadata
()
1544 "Basic MultMarkdown metadata tests."
1545 (markdown-test-string "Title: peg-multimarkdown User's Guide
1546 Author: Fletcher T. Penney
1547 Base Header Level: 2 "
1548 (markdown-test-range-has-face 1 5 markdown-metadata-key-face
)
1549 (markdown-test-range-has-face 6 6 nil
)
1550 (markdown-test-range-has-face 8 37 markdown-metadata-value-face
)
1551 (markdown-test-range-has-face 41 46 markdown-metadata-key-face
)
1552 (markdown-test-range-has-face 47 47 nil
)
1553 (markdown-test-range-has-face 49 66 markdown-metadata-value-face
)
1554 (markdown-test-range-has-face 70 86 markdown-metadata-key-face
)
1555 (markdown-test-range-has-face 87 87 nil
)
1556 (markdown-test-range-has-face 89 89 markdown-metadata-value-face
))
1557 ;; Avoid triggering when a title contains a colon (e.g., Markdown: Syntax)
1558 (markdown-test-file "syntax.text"
1559 (markdown-test-range-has-face 1 16 markdown-header-face-1
)))
1561 (ert-deftest test-markdown-font-lock
/mmd-metadata-after-header
()
1562 "Ensure that similar lines are not matched after the header."
1563 (markdown-test-string "Title: peg-multimarkdown User's Guide
1565 Author: Fletcher T. Penney
1566 Base Header Level: 2 "
1567 (markdown-test-range-has-face 1 5 markdown-metadata-key-face
)
1568 (markdown-test-range-has-face 6 6 nil
)
1569 (markdown-test-range-has-face 8 37 markdown-metadata-value-face
)
1570 (markdown-test-range-has-face 40 67 nil
)
1571 (markdown-test-range-has-face 71 90 nil
)))
1573 (ert-deftest test-markdown-font-lock
/pandoc-metadata
()
1574 "Basic Pandoc metadata tests."
1575 (markdown-test-string "% title
1582 (markdown-test-range-has-face 1 1 markdown-comment-face
)
1583 (markdown-test-range-has-face 3 24 markdown-metadata-value-face
)
1584 (markdown-test-range-has-face 26 26 markdown-comment-face
)
1585 (markdown-test-range-has-face 28 56 markdown-metadata-value-face
)
1586 (markdown-test-range-has-face 58 58 markdown-comment-face
)
1587 (markdown-test-range-has-face 60 63 markdown-metadata-value-face
)
1588 (markdown-test-range-has-face 64 69 nil
)))
1590 (ert-deftest test-markdown-font-lock
/line-break
()
1591 "Basic line break tests."
1592 (markdown-test-string " \nasdf \n"
1593 (markdown-test-range-has-face 1 9 nil
)
1594 (markdown-test-range-has-face 10 11 markdown-line-break-face
)))
1596 ;;; Markdown Parsing Functions:
1598 (ert-deftest test-markdown-parsing
/reference-definition-basic
()
1599 "Test reference definition function."
1600 (markdown-test-file "syntax.text"
1601 ;; Test accuracy of returned text and bounds
1602 (should (equal (markdown-reference-definition "[1]")
1603 (list "http://docutils.sourceforge.net/mirror/setext.html" 1942 1992)))
1604 (should (equal (markdown-reference-definition "[2]")
1605 (list "http://www.aaronsw.com/2002/atx/" 2000 2032)))
1606 ;; Test that match data remains intact
1607 (should (string-equal (match-string 2) "http://www.aaronsw.com/2002/atx/"))
1608 ;; Test anchor-only relative URL
1609 (should (equal (markdown-reference-definition "[bq]")
1610 (list "#blockquote" 7536 7547)))
1611 ;; Example references that appear in pre blocks in the text
1612 (should (not (markdown-reference-definition "[]")))
1613 (should (not (markdown-reference-definition "[id]")))
1614 (should (not (markdown-reference-definition "[foo]")))
1615 (should (not (markdown-reference-definition "[A]")))
1616 (should (not (markdown-reference-definition "[Google]")))
1617 ;; Test that we don't pick up other text in square brackets
1618 (should (not (markdown-reference-definition "[blockquoting]")))
1619 (should (not (markdown-reference-definition "[square brackets]")))
1620 ;; Test case insensitivity
1621 (should (equal (markdown-reference-definition "[SRC]")
1622 (list "/projects/markdown/syntax.text" 1245 1275)))))
1624 (ert-deftest test-markdown-parsing
/get-defined-references
()
1625 "Test `markdown-get-defined-references'."
1626 (markdown-test-file "syntax.text"
1627 (should (equal (markdown-get-defined-references)
1628 '("[src]" "[1]" "[2]" "[3]" "[4]" "[5]" "[6]" "[bq]" "[l]"))))
1629 (markdown-test-file "outline.text"
1630 (should (equal (markdown-get-defined-references) nil
)))
1631 (markdown-test-file "wiki-links.text"
1632 (should (equal (markdown-get-defined-references) nil
))))
1634 (ert-deftest test-markdown-parsing
/code-at-point-inline
()
1635 "Test `markdown-code-at-point'."
1637 (defun test-region (beg end
)
1638 (goto-char (1- beg
))
1639 (should-not (markdown-code-at-point-p))
1640 (goto-char (1+ end
))
1641 (should-not (markdown-code-at-point-p))
1642 (dolist (loc (number-sequence beg end
))
1644 (should (markdown-code-at-point-p))
1645 (should (equal (match-beginning 0) beg
))
1646 (should (equal (match-end 0) end
))))
1648 (markdown-test-file "inline.text"
1649 (test-region 45 51) ; Regular code span
1650 (test-region 61 90) ; Code containing backticks
1651 (test-region 228 240) ; Backquotes at beginning
1652 (test-region 341 352) ; Backquotes at end
1653 (test-region 460 469) ; Backslash as final character
1654 (test-region 657 667) ; A code span crossing lines
1655 (test-region 749 758) ; Three backquotes on same line
1656 (test-region 806 815) ; Three backquotes across lines
1659 (ert-deftest test-markdown-parsing
/code-at-point-one-space
()
1660 "Test `markdown-code-at-point' with multiple code spans in a row."
1661 (markdown-test-string "`foo` `bar` `baz`"
1662 (dolist (loc (number-sequence 1 6))
1664 (should (markdown-code-at-point-p))
1665 (should (equal (match-data) (list 1 6 2 5))))
1666 (dolist (loc (number-sequence 7 12))
1668 (should (markdown-code-at-point-p))
1669 (should (equal (match-data) (list 7 12 8 11))))
1670 (dolist (loc (number-sequence 13 18))
1672 (should (markdown-code-at-point-p))
1673 (should (equal (match-data) (list 13 18 14 17))))))
1675 (ert-deftest test-markdown-parsing
/code-at-point-no-space
()
1676 "Test `markdown-code-at-point` with multiple code spans in a row."
1677 (markdown-test-string "a`foo`b`bar`c`baz`d"
1679 (should-not (markdown-code-at-point-p))
1680 (dolist (loc (number-sequence 2 7)) ; "`foo`b"
1682 (should (markdown-code-at-point-p))
1683 (should (equal (match-data) (list 2 7 3 6))))
1684 (dolist (loc (number-sequence 8 13)) ; "`bar`c"
1686 (should (markdown-code-at-point-p))
1687 (should (equal (match-data) (list 8 13 9 12))))
1688 (dolist (loc (number-sequence 14 19)) ; "`baz`d"
1690 (should (markdown-code-at-point-p))
1691 (should (equal (match-data) (list 14 19 15 18))))))
1693 ;;; Reference Checking:
1695 (ert-deftest test-markdown-references
/goto-line-button
()
1696 "Create and test a goto line button."
1697 (markdown-test-string "line 1\nline 2\n"
1698 ;; Store the temporary buffer with the text
1699 (let ((target (current-buffer)))
1700 ;; Create a new buffer for inserting
1702 ;; Verify that point is in a different buffer
1703 (should (not (equal (current-buffer) target
)))
1704 ;; Insert and press the button
1705 (insert-button "goto line 2"
1706 :type
'markdown-goto-line-button
1707 'target-buffer target
1709 (should (string-equal (buffer-string) "goto line 2"))
1711 (call-interactively 'push-button
)
1712 ;; Verify that point is on line 2 of target buffer
1713 (should (= (line-number-at-pos) 2))
1714 (should (looking-at "line 2"))
1715 (should (equal (current-buffer) target
))))))
1717 (ert-deftest test-markdown-references
/button-map
()
1718 "Verify that button-buffer-map is used for check references buffer."
1719 (markdown-test-string "[undefined][ref]\n"
1720 (let* ((target (buffer-name))
1721 (check (format "*Undefined references for %s*" target
)))
1722 (markdown-check-refs)
1723 (with-current-buffer (get-buffer check
)
1724 (should (equal (local-key-binding (kbd "TAB")) 'forward-button
))
1725 (should (equal (local-key-binding (kbd "<backtab>")) 'backward-button
))))))
1729 (ert-deftest test-markdown-lists
/levels-1
()
1730 "Test list levels function `markdown-calculate-list-levels'."
1731 (markdown-test-file "nested-list.text"
1732 (let ((values '(((1 .
1) . nil
) ((2 .
13) .
(3)) ((14 .
23) .
(7 3))
1733 ((24 .
26) .
(11 7 3)))))
1734 (loop for
(range . value
) in values
1735 do
(goto-char (point-min))
1736 (forward-line (1- (car range
)))
1737 (dotimes (n (- (cdr range
) (car range
)))
1738 (should (equal (markdown-calculate-list-levels) value
))
1741 (ert-deftest test-markdown-lists
/levels-2
()
1742 "Test list levels function `markdown-calculate-list-levels'."
1743 (markdown-test-file "syntax.text"
1744 (let ((values '(((1 .
13) . nil
) ((14 .
14) .
(0)) ((15 .
17) .
(4 0))
1745 ((18 .
18) .
(0)) ((19 .
24) .
(4 0)) ((25 .
25) .
(0))
1746 ((26 .
29) .
(4 0)) ((30 .
30) .
(0)) ((31 .
33) .
(4 0))
1747 ((34 .
588) . nil
) ((589 .
595) .
(0)) ((596 .
814) . nil
)
1748 ((815 .
820) .
(0)) ((821 .
898) . nil
))))
1749 (loop for
(range . value
) in values
1750 do
(goto-char (point-min))
1751 (forward-line (1- (car range
)))
1752 (dotimes (n (- (cdr range
) (car range
)))
1753 (should (equal (markdown-calculate-list-levels) value
))
1756 (ert-deftest test-markdown-lists
/levels-interior
()
1757 "Test `markdown-calculate-list-levels' from inside a list item."
1758 (markdown-test-file "nested-list.text"
1760 (should (equal (markdown-calculate-list-levels) (list 3)))
1762 (should (equal (markdown-calculate-list-levels) (list 7 3)))
1764 (should (equal (markdown-calculate-list-levels) (list 11 7 3)))))
1766 (ert-deftest test-markdown-lists
/bounds-1
()
1767 "Test list item bounds function `markdown-cur-list-item-bounds'."
1768 (markdown-test-file "lists.text"
1769 (markdown-test-goto-heading "Case 9")
1771 (should (eq (point) 3699))
1772 (markdown-next-list-item 4)
1773 (should (eq (point) 3700))
1774 (should (equal (markdown-cur-list-item-bounds)
1775 (list 3700 3901 0 4 "- ")))
1776 (markdown-next-list-item 4)
1777 (should (eq (point) 3903))
1778 (should (equal (markdown-cur-list-item-bounds)
1779 (list 3903 3937 0 4 "* ")))))
1781 (ert-deftest test-markdown-lists
/bounds-2
()
1782 "Function `markdown-cur-list-item-bounds' should return nil outside of list items."
1783 (markdown-test-string "line one\n\n* item\n"
1784 (should (null (markdown-cur-list-item-bounds)))
1786 (should (null (markdown-cur-list-item-bounds)))
1788 (should (markdown-cur-list-item-bounds))))
1790 (ert-deftest test-markdown-lists
/promotion-and-demotion
()
1791 "Test function `markdown-promote-list-item'."
1792 (markdown-test-file "nested-list.text"
1794 (should (looking-at " - List level 1 item 2
1796 Second paragraph of item 2
1798 Nested pre block in item 2
1799 Four spaces past the marker
1801 Another paragraph of item 2"))
1802 (markdown-demote-list-item)
1803 (should (looking-at " - List level 1 item 2
1805 Second paragraph of item 2
1807 Nested pre block in item 2
1808 Four spaces past the marker
1810 Another paragraph of item 2"))
1811 (markdown-promote-list-item)
1812 (should (looking-at " - List level 1 item 2
1814 Second paragraph of item 2
1816 Nested pre block in item 2
1817 Four spaces past the marker
1819 Another paragraph of item 2"))
1821 (should (looking-at " - List level 3 item 1
1824 (markdown-demote-list-item)
1825 (should (looking-at " - List level 3 item 1
1828 (markdown-promote-list-item)
1829 (should (looking-at " - List level 3 item 1
1831 Nested pre block"))))
1833 ;;; Outline minor mode tests:
1835 (ert-deftest test-markdown-outline
/navigation
()
1836 "Test outline navigation functions."
1837 (markdown-test-file "outline.text"
1838 ;; Navigate to the first visible heading
1839 (outline-next-visible-heading 1)
1840 (should (eq (point) 19))
1841 (should (looking-at "^# A top-level header"))
1842 ;; Navigate forward at the same level
1843 (outline-forward-same-level 1)
1844 (should (eq (point) 377))
1845 (should (looking-at "^=+$"))
1846 ;; Navigate backward by four visible headings
1847 (outline-previous-visible-heading 4)
1848 (should (eq (point) 69))
1849 (should (looking-at "^## A second-level header$"))))
1851 (ert-deftest test-markdown-outline
/visibility-atx
()
1852 "Test outline visibility cycling for ATX-style headers."
1853 (markdown-test-file "outline.text"
1854 (let (last-command this-command
)
1855 ;; Navigate to the second visible heading
1856 (outline-next-visible-heading 2)
1857 (should (eq (point) 69))
1858 (should (looking-at "^## A second-level header$"))
1859 ;; Cycle visibility of this subtree
1860 (setq this-command
'markdown-cycle
)
1862 (setq last-command
'markdown-cycle
)
1863 (should (eq (point) 69))
1864 (should (looking-at "^## A second-level header$"))
1865 ;; Test that the entire subtree is invisible
1866 (markdown-test-range-has-property 93 349 'invisible
'outline
)
1867 ;; Cycle visibility of this subtree again
1869 (should (eq (point) 69))
1870 (should (looking-at "^## A second-level header$"))
1871 ;; Test that text is visible
1872 (markdown-test-range-has-property 95 121 'invisible nil
)
1873 ;; Test that subheadings are visible
1874 (markdown-test-range-has-property 123 141 'invisible nil
)
1875 ;; Cycle visibility of this subtree again
1877 (should (eq (point) 69))
1878 (should (looking-at "^## A second-level header$"))
1879 ;; Verify that entire subtree is visible
1880 (markdown-test-range-has-property 93 349 'invisible nil
))))
1882 (ert-deftest test-markdown-outline
/visibility-setext
()
1883 "Test outline visibility cycling for setext-style headers."
1884 (markdown-test-file "outline.text"
1885 ;; Navigate to the sixth visible heading
1886 (outline-next-visible-heading 7)
1887 (outline-previous-visible-heading 1)
1888 (should (looking-at markdown-regex-header
))
1889 (should (string-equal (match-string-no-properties 1) "An underline-style header"))
1890 (should (string-equal (match-string-no-properties 2) "========================="))
1891 ;; Cycle visibility subtree, test that it's invisible
1893 (markdown-test-range-has-property 404 515 'invisible
'outline
)
1894 ;; Cycle visibility subtree, test that text and headers are visible
1896 (markdown-test-range-has-property 404 417 'invisible nil
)
1897 (markdown-test-range-has-property 420 451 'invisible nil
)))
1901 (ert-deftest test-markdown-movement
/defun
()
1902 "Test defun navigation."
1903 (markdown-test-file "outline.text"
1904 ;; end-of-defun should go to point-max
1906 (should (= (point) (point-max)))
1907 ;; end-of-defun should stop just before the next header
1908 (goto-char (point-min))
1910 (should (looking-at "\n# A top-level header"))
1912 (should (looking-at "\n## A second-level header"))
1914 (should (looking-at "\n### Third level ###"))
1916 (should (looking-at "\n### Third level number two ###"))
1917 ;; beginning-of-defun should move to the start of the previous header
1918 (beginning-of-defun)
1919 (should (looking-at "### Third level ###"))
1920 (beginning-of-defun)
1921 (should (looking-at "## A second-level header"))
1922 (beginning-of-defun)
1923 (should (looking-at "# A top-level header"))
1924 (beginning-of-defun)
1925 ;; beginning-of-defun should move up to point-min
1926 (should (= (point) (point-min)))))
1928 (ert-deftest test-markdown-movement
/block
()
1929 "Test block movement."
1930 (markdown-test-file "outline.text"
1931 (markdown-end-of-block)
1932 (should (looking-at "\n# A top-level header"))
1933 (markdown-end-of-block)
1934 (should (looking-at "\nfollowed by some body text"))
1935 (markdown-end-of-block)
1936 (should (looking-at "\n## A second-level header"))
1937 (markdown-end-of-block)
1938 (should (looking-at "\nfollowed by some body text"))
1939 (markdown-end-of-block)
1940 (should (looking-at "\n### Third level ###"))
1941 (markdown-end-of-block)
1942 (should (looking-at "\n\\* A list item"))
1943 (markdown-end-of-block)
1944 (should (looking-at "\n### Third level number two ###"))
1945 (markdown-end-of-block)
1946 (should (looking-at "\n### Level two again"))
1947 (markdown-end-of-block)
1948 (should (looking-at "\nfollowed by some body text"))
1950 (markdown-test-goto-heading "Level two")
1951 (markdown-end-of-block)
1952 (should (looking-at "\nbar"))
1953 (markdown-end-of-block)
1954 (should (= (point) (point-max)))
1955 (markdown-beginning-of-block)
1956 (should (looking-at "bar"))
1957 (markdown-beginning-of-block)
1958 (should (looking-at "## Level two"))
1959 (markdown-beginning-of-block)
1960 (should (looking-at "foo"))
1961 (markdown-beginning-of-block)
1962 (should (looking-at "# Level one"))
1963 (markdown-beginning-of-block)
1964 (should (looking-at "* With"))
1965 (markdown-beginning-of-block)
1966 (should (looking-at "And a level two underline header"))
1968 (goto-char (point-min))
1969 (markdown-test-goto-heading "A top-level header")
1971 (markdown-beginning-of-block)
1972 (should (= (point) (point-min)))))
1974 (ert-deftest test-markdown-movement
/reference-definition
()
1975 "Test jumping to reference definitions."
1976 ;; Jumping to explicit reference definition
1977 (markdown-test-string "[a][ref]\n\n[ref]: gopher://localhost/\n"
1978 (markdown-reference-goto-definition)
1979 (should (= (point) 18)))
1980 ;; Jumping to implicit reference definition
1981 (markdown-test-string "[a][]\n\n[a]: ftp://localhost/\n"
1982 (markdown-reference-goto-definition)
1983 (should (= (point) 13)))
1984 ;; Creating non-existent reference definition
1985 (markdown-test-string "[a][]\n"
1986 (markdown-reference-goto-definition)
1987 (should (= (point) 13))
1988 (should (string-equal (buffer-string) "[a][]\n\n[a]: "))))
1990 ;;; Wiki link tests:
1992 (ert-deftest test-markdown-wiki-link
/aliasing
()
1993 "Test filename extraction for aliased wiki links."
1994 (markdown-test-file "wiki-links.text"
1995 ;; Confirm location of first wiki link
1996 (should (eq (markdown-next-link) 8))
1997 ;; Confirm location of second wiki link
1998 (should (eq (markdown-next-link) 73))
1999 ;; Test predicate function
2000 (should (markdown-wiki-link-p))
2001 ;; Test alias-first filename extraction
2002 (setq markdown-wiki-link-alias-first t
)
2003 (should (string-equal (markdown-wiki-link-link) "second"))
2004 ;; Test alias-second filename extraction
2005 (setq markdown-wiki-link-alias-first nil
)
2006 (should (string-equal (markdown-wiki-link-link) "first"))))
2008 (ert-deftest test-markdown-wiki-link
/navigation
()
2009 "Test wiki link navigation."
2010 (markdown-test-file "wiki-links.text"
2011 ;; Advance to first link
2012 (should (eq (markdown-next-link) 8))
2013 ;; Advance to second link
2014 (should (eq (markdown-next-link) 73))
2015 ;; Avance to final link
2016 (should (eq (markdown-next-link) 155))
2017 ;; Return nil and don't advance point
2018 (should (eq (markdown-next-link) nil
))
2019 (should (eq (point) 155))
2020 ;; Move back to second link
2021 (should (eq (markdown-previous-link) 73))
2022 ;; Move back to first link
2023 (should (eq (markdown-previous-link) 8))
2024 ;; Return nil and don't move point
2025 (should (eq (markdown-previous-link) nil
))
2026 (should (eq (point) 8))))
2028 (ert-deftest test-markdown-wiki-link
/font-lock
()
2029 "Test font lock faces for wiki links."
2030 (markdown-test-temp-file "wiki-links.text"
2031 (let* ((fn (concat (file-name-directory buffer-file-name
)
2033 ;; Create inline.text in the same temp directory, refontify
2034 (write-region "" nil fn nil
1)
2035 (markdown-fontify-buffer-wiki-links)
2036 ;; Confirm location of first wiki link
2037 (should (eq (markdown-next-link) 8))
2038 ;; First wiki link doesn't have a corresponding file
2039 (markdown-test-range-has-property 8 20 'font-lock-face markdown-missing-link-face
)
2040 ;; Second wiki link doesn't have a corresponding file
2041 (should (eq (markdown-next-link) 73))
2042 (markdown-test-range-has-property 73 88 'font-lock-face markdown-missing-link-face
)
2043 ;; Move to third wiki link, and create the missing file
2044 (should (eq (markdown-next-link) 155))
2045 (should (string-equal (markdown-wiki-link-link) "inline"))
2046 (markdown-test-range-has-property 155 164 'font-lock-face markdown-link-face
)
2047 ;; Remove temporary files
2053 (ert-deftest test-markdown-filling
/blockquote
()
2054 "Test filling of blockquotes.
2055 See `adaptive-fill-first-line-regexp'."
2056 (markdown-test-string "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
2058 (should (string-equal (buffer-string) "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do\n> eiusmod tempor incididunt ut labore et dolore magna aliqua."))))
2060 (ert-deftest test-markdown-filling
/list-item-plus
()
2061 "Test filling of list items with plus sign markers.
2062 See `adaptive-fill-regexp'."
2063 (markdown-test-string " + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
2065 (should (string-equal (buffer-string) " + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do\n eiusmod tempor incididunt ut labore et dolore magna aliqua."))))
2067 (ert-deftest test-markdown-filling
/list-item-plus-in-blockquote
()
2068 "Test filling of list items with plus sign markers inside blockquote.
2069 See `adaptive-fill-regexp'."
2070 (markdown-test-string "> + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
2072 (should (string-equal (buffer-string) "> + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do\n> eiusmod tempor incididunt ut labore et dolore magna aliqua."))))
2074 (ert-deftest test-markdown-filling
/line-break
()
2075 "Test filling of paragraphs with hard line breaks.
2076 See `paragraph-separate'."
2077 (markdown-test-string "Lorem ipsum dolor sit amet, \nconsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
2078 (let ((fill-column 70))
2080 (should (string-equal (buffer-string) "Lorem ipsum dolor sit amet, \nconsectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua.")))))
2084 (ert-deftest test-markdown-hook
/xhtml-standalone
()
2085 "Test `markdown-xhtml-standalone-regexp' and `markdown-output-standalone-p'."
2086 (should (string-match markdown-xhtml-standalone-regexp
2087 "<?xml version='1.0' encoding='UTF-8'?>"))
2088 (should (string-match markdown-xhtml-standalone-regexp
2090 (should (string-match markdown-xhtml-standalone-regexp
2092 (should-not (string-match markdown-xhtml-standalone-regexp
2094 (should-not (string-match markdown-xhtml-standalone-regexp
2095 "<div id=\"name\">")))
2099 (ert-deftest test-markdown-hook
/before-export
()
2100 "Test hook run before export XHTML."
2101 (markdown-test-temp-file "lists.text"
2102 (let* ((before-hook-run nil
)
2103 (ofile (concat buffer-file-name
".html"))
2104 (func (lambda (fname)
2105 (setq before-hook-run t
)
2106 (should (string-equal fname ofile
)))))
2107 ;; Register function
2108 (add-hook 'markdown-before-export-hooks func
)
2110 (markdown-export ofile
)
2111 (should (eq before-hook-run t
))
2113 (remove-hook 'markdown-before-export-hooks func
)
2114 (kill-buffer (get-file-buffer ofile
))
2115 (delete-file ofile
))))
2117 (ert-deftest test-markdown-hook
/after-export
()
2118 "Test hook run after export XHTML."
2119 (markdown-test-temp-file "lists.text"
2120 (let* ((after-hook-run nil
)
2121 (ofile (concat buffer-file-name
".html"))
2122 (func (lambda (fname)
2123 (setq after-hook-run t
)
2124 (should (string-equal fname ofile
)))))
2125 ;; Register function
2126 (add-hook 'markdown-after-export-hooks func
)
2128 (markdown-export ofile
)
2129 (should (eq after-hook-run t
))
2131 (remove-hook 'markdown-after-export-hooks func
)
2132 (kill-buffer (get-file-buffer ofile
))
2133 (delete-file ofile
))))
2135 ;;; Extension: math support
2137 (ert-deftest test-markdown-math
/file-local-variable
()
2138 "Test enabling math mode via `hack-local-variables-hook'."
2139 (markdown-test-file "math.text"
2140 (should-not markdown-enable-math
)
2141 (hack-local-variables)
2142 (should markdown-enable-math
)))
2144 (ert-deftest test-markdown-math
/reload
()
2145 "Test enabling math mode via function `markdown-enable-math'."
2146 (markdown-test-file "math.text"
2147 (markdown-enable-math t
)
2148 ;; Flag should be set to t
2149 (should markdown-enable-math
)
2150 ;; Font-lock keywords should be updated
2151 (should (member (cons markdown-regex-math-display
'markdown-math-face
)
2152 markdown-mode-font-lock-keywords
))))
2154 (ert-deftest test-markdown-math
/font-lock
()
2155 "Test markdown math mode."
2156 (markdown-test-file "math.text"
2157 (markdown-enable-math t
)
2158 (font-lock-fontify-buffer)
2159 (markdown-test-range-has-face 1 32 nil
)
2160 (markdown-test-range-has-face 33 46 markdown-math-face
)
2161 (markdown-test-range-has-face 47 49 nil
)
2162 (markdown-test-range-has-face 50 65 markdown-math-face
)
2163 (markdown-test-range-has-face 66 98 nil
)
2164 (markdown-test-range-has-face 99 114 markdown-math-face
)))
2168 (ert-deftest test-markdown-gfm
/pre-1
()
2169 "GFM pre block font lock test."
2170 (markdown-test-file-gfm "gfm.text"
2171 (markdown-test-range-has-face 2626 2637 nil
)
2172 (markdown-test-range-has-face 2639 2641 markdown-pre-face
)
2173 (markdown-test-range-has-face 2642 2645 markdown-language-keyword-face
)
2174 (markdown-test-range-has-face 2647 2728 markdown-pre-face
)
2175 (markdown-test-range-has-face 2730 2732 markdown-pre-face
)))
2177 (ert-deftest test-markdown-gfm
/italic-1
()
2178 "GFM italic font lock test."
2179 (markdown-test-file-gfm "gfm.text"
2180 (markdown-test-range-has-face 1483 1488 markdown-italic-face
)
2181 (markdown-test-range-has-face 1729 1790 nil
)))
2183 (provide 'markdown-test
)
2185 ;;; markdown-test.el ends here