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
/bold-region
()
363 "Test region functionality of `markdown-insert-bold'."
364 (markdown-test-string "one two three"
365 (push-mark (point) t t
)
367 (markdown-insert-bold)
368 (should (string-equal (buffer-string) "**one two** three"))
369 (should (= (point) 10))))
371 (ert-deftest test-markdown-insertion
/italic-region
()
372 "Test region functionality of `markdown-insert-italic'."
373 (markdown-test-string "one two three"
374 (push-mark (point) t t
)
376 (markdown-insert-italic)
377 (should (string-equal (buffer-string) "*one two* three"))
378 (should (= (point) 9))))
380 (ert-deftest test-markdown-insertion
/code-region
()
381 "Test region functionality of `markdown-insert-code'."
382 (markdown-test-string "one two three"
383 (push-mark (point) t t
)
385 (markdown-insert-code)
386 (should (string-equal (buffer-string) "`one two` three"))
387 (should (= (point) 9))))
389 (ert-deftest test-markdown-insertion
/atx-line
()
390 "Test ATX header insertion without region."
391 (markdown-test-string "line one\nline two\n"
393 (markdown-insert-header-atx-1)
394 (should (string-equal (buffer-substring (point-min) (point-max))
395 "# line one #\n\nline two\n"))
397 (markdown-insert-header-atx-2)
398 (should (string-equal (buffer-substring (point-min) (point-max))
399 "# line one #\n\n## line two ##\n\n"))))
401 (ert-deftest test-markdown-insertion
/atx-region
()
402 "Test ATX header insertion with region."
403 (markdown-test-string "line one\nline two\n"
404 (transient-mark-mode)
406 (push-mark (point) t t
)
408 (should (string-equal (buffer-substring (region-beginning) (region-end))
410 (markdown-insert-header-atx-4)
411 (should (string-equal (buffer-substring (point-min) (point-max))
412 "line \n\n#### one ####\n\nline two\n"))))
414 (ert-deftest test-markdown-insertion
/atx-blank
()
415 "Test ATX header insertion on blank line."
416 (markdown-test-string "line one\n\nline two\n"
418 (markdown-insert-header-atx-3)
419 (should (string-equal (buffer-substring (point-min) (point-max))
420 "line one\n\n### ###\n\nline two\n"))
421 (should (= (point) 15))
422 (should (looking-at " ###\n"))))
424 (ert-deftest test-markdown-insertion
/atx-region-whitespace
()
425 "Test ATX header insertion using a region with whitespace."
426 (markdown-test-string " line one\n\nline two\n \n"
427 (transient-mark-mode)
428 (push-mark (point) t t
)
429 (goto-char (point-max))
430 (markdown-insert-header-atx-2)
431 (should (string-equal (buffer-substring (point-min) (point-max))
432 "## line one line two ##"))
433 (should (= (point) 21))
434 (should (looking-at " ##"))))
436 (ert-deftest test-markdown-insertion
/atx-line-whitespace
()
437 "Test ATX header insertion using current line with whitespace."
438 (markdown-test-string " line one \n\nline two\n"
439 (goto-char (line-end-position))
440 (markdown-insert-header-atx-3)
441 (should (string-equal (buffer-substring (point-min) (point-max))
442 "### line one ###\n\nline two\n"))
443 (should (= (point) 13))
444 (should (looking-at " ###\n"))))
446 (ert-deftest test-markdown-insertion
/atx-replace-atx
()
447 "Test ATX header insertion when replacing an existing ATX header."
448 (markdown-test-string "## replace ##\n"
449 (markdown-insert-header-atx-4)
450 (should (string-equal (buffer-string) "#### replace ####\n\n"))
451 (should (looking-at " ####\n"))))
453 (ert-deftest test-markdown-insertion
/atx-replace-setext-1
()
454 "Test ATX header insertion when replacing an existing setext header."
455 (markdown-test-string "replace\n=======\n"
456 (markdown-insert-header-atx-2)
457 (should (string-equal (buffer-string) "## replace ##\n\n"))
458 (should (looking-at " ##\n"))))
460 (ert-deftest test-markdown-insertion
/atx-replace-setext-2
()
461 "Test ATX header insertion when replacing an existing setext header."
462 (markdown-test-string "replace\n-------\n"
463 (markdown-insert-header-atx-5)
464 (should (string-equal (buffer-string) "##### replace #####\n\n"))
465 (should (looking-at " #####\n"))))
467 (ert-deftest test-markdown-insertion
/setext-line
()
468 "Test setext header insertion without region."
469 (markdown-test-string "line one\nline two\n"
471 (markdown-insert-header-setext-1)
472 (should (string-equal (buffer-substring (point-min) (point-max))
473 "line one\n========\n\nline two\n"))
475 (markdown-insert-header-setext-2)
476 (should (string-equal (buffer-substring (point-min) (point-max))
477 "line one\n========\n\nline two\n--------\n\n"))))
479 (ert-deftest test-markdown-insertion
/setext-region
()
480 "Test setext header insertion with region."
481 (markdown-test-string "line one\nline two\n"
482 (transient-mark-mode)
484 (push-mark (point) t t
)
486 (should (string-equal (buffer-substring (region-beginning) (region-end))
488 (markdown-insert-header-setext-1)
489 (should (string-equal (buffer-substring (point-min) (point-max))
490 "line \n\none\n===\n\nline two\n"))))
492 (ert-deftest test-markdown-insertion
/setext-blank
()
493 "Test setext header insertion on blank line."
494 (markdown-test-string "line one\n\nline two\n"
496 (markdown-insert-header 2 "foo" t
)
497 (should (string-equal (buffer-substring (point-min) (point-max))
498 "line one\n\nfoo\n---\n\nline two\n"))
499 (should (= (point) 14))
500 (should (looking-at "\n---"))))
502 (ert-deftest test-markdown-insertion
/setext-region-whitespace
()
503 "Test setext header insertion using a region with whitespace."
504 (markdown-test-string " line one\n\nline two\n \n"
505 (transient-mark-mode)
506 (push-mark (point) t t
)
507 (goto-char (point-max))
508 (markdown-insert-header-setext-1)
509 (should (string-equal (buffer-substring (point-min) (point-max))
510 "line one line two\n================="))
511 (should (= (point) 18))
512 (should (looking-at "\n===="))))
514 (ert-deftest test-markdown-insertion
/setext-line-whitespace
()
515 "Test setext header insertion using current line with whitespace."
516 (markdown-test-string " line one \n\nline two\n"
517 (goto-char (line-end-position))
518 (markdown-insert-header-setext-2)
519 (should (string-equal (buffer-substring (point-min) (point-max))
520 "line one\n--------\n\nline two\n"))
521 (should (= (point) 9))
522 (should (looking-at "\n---"))))
524 (ert-deftest test-markdown-insertion
/setext-replace-atx
()
525 "Test setext header insertion when replacing an existing ATX header."
526 (markdown-test-string "## replace ##\n"
527 (markdown-insert-header-setext-1)
528 (should (string-equal (buffer-string) "replace\n=======\n\n"))
529 (should (looking-at "\n==="))))
531 (ert-deftest test-markdown-insertion
/setext-replace-setext-1
()
532 "Test setext header insertion when replacing an existing setext title."
533 (markdown-test-string "replace\n=======\n"
534 (markdown-insert-header-setext-2)
535 (should (string-equal (buffer-string) "replace\n-------\n\n"))
536 (should (looking-at "\n---"))))
538 (ert-deftest test-markdown-insertion
/setext-replace-setext-2
()
539 "Test setext header insertion when replacing an existing setext section."
540 (markdown-test-string "replace\n-------\n"
541 (markdown-insert-header-setext-1)
542 (should (string-equal (buffer-string) "replace\n=======\n\n"))
543 (should (looking-at "\n==="))))
545 (ert-deftest test-markdown-insertion
/header-dwim
()
546 "Test 'do what I mean' header insertion."
547 (markdown-test-file "outline.text"
548 (call-interactively 'markdown-insert-header-dwim
)
549 (should (looking-at " #$"))
551 (call-interactively 'markdown-insert-header-dwim
)
553 (should (looking-at "^# #$"))
555 (call-interactively 'markdown-insert-header-dwim
)
557 (should (looking-at "^### ###$"))))
559 (ert-deftest test-markdown-insertion
/header-dwim-prefix
()
560 "Test 'do what I mean' header insertion with prefix arguments."
561 (let ((tests (list '(nil .
"# abc #")
565 '(4 .
"#### abc ####")
566 '(5 .
"##### abc #####")
567 '(6 .
"###### abc ######")
569 '((16) .
"abc\n---"))))
571 (markdown-test-string "abc"
572 (let ((current-prefix-arg (car test
)))
573 (call-interactively 'markdown-insert-header-dwim
)
574 (should (string-equal (buffer-string) (cdr test
))))))))
576 (ert-deftest test-markdown-insertion
/header-setext-dwim-prefix
()
577 "Test 'do what I mean' header insertion with prefix arguments."
578 (let ((tests (list '(nil .
"abc\n===")
582 '(4 .
"#### abc ####")
583 '(5 .
"##### abc #####")
584 '(6 .
"###### abc ######")
586 '((16) .
"abc\n---"))))
588 (markdown-test-string "abc"
589 (let ((current-prefix-arg (car test
)))
590 (call-interactively 'markdown-insert-header-setext-dwim
)
591 (should (string-equal (buffer-string) (cdr test
))))))))
593 (ert-deftest test-markdown-insertion
/remove-header
()
594 "Test ATX and setext header."
595 (markdown-test-string
596 "# atx1\n\n## atx2 ##\n\nsetext1\n=======\n\nsetext2\n-------\n"
597 (should (equal (markdown-remove-header) (cons 1 5)))
599 (should (not (markdown-remove-header)))
601 (should (equal (markdown-remove-header) (cons 7 11)))
603 (should (not (markdown-remove-header)))
605 (should (equal (markdown-remove-header) (cons 13 20)))
607 (should (not (markdown-remove-header)))
609 (should (equal (markdown-remove-header) (cons 22 29)))
610 (should (string-equal (buffer-string)
611 "atx1\n\natx2\n\nsetext1\n\nsetext2\n"))))
613 (ert-deftest test-markdown-insertion
/italic-unwrap-region
()
614 "A test of inserting italics with italic text in the region."
615 (markdown-test-string "*foo* bar *baz*"
616 (transient-mark-mode)
617 (push-mark (point) t t
)
619 (markdown-insert-italic)
620 (should (string-equal (buffer-string) "*foo bar baz*"))))
622 (ert-deftest test-markdown-insertion
/bold-unwrap-region
()
623 "A test of inserting bold with italic text in the region."
624 (markdown-test-string "*foo* **bar** *baz*"
625 (transient-mark-mode)
626 (push-mark (point) t t
)
628 (markdown-insert-bold)
629 (should (string-equal (buffer-string) "***foo* bar *baz***"))))
631 (ert-deftest test-markdown-insertion
/code-unwrap-region
()
632 "A test of inserting code with code already in the region."
633 (markdown-test-string "`foo` *bar* `baz`"
634 (transient-mark-mode)
635 (push-mark (point) t t
)
637 (markdown-insert-code)
638 (should (string-equal (buffer-string) "`foo *bar* baz`"))))
640 (ert-deftest test-markdown-insertion
/hr-order
()
641 "Test inserting horizontal rules."
642 (dotimes (n (length markdown-hr-strings
))
643 (markdown-test-string ""
644 (let ((current-prefix-arg n
))
645 (call-interactively 'markdown-insert-hr
))
646 (should (string-equal (buffer-string) (nth (1- n
) markdown-hr-strings
))))))
648 (ert-deftest test-markdown-insertion
/hr-prefix
()
649 "Test inserting horizontal rule with C-u prefix."
650 (markdown-test-string ""
651 (let ((current-prefix-arg '(4)))
652 (call-interactively 'markdown-insert-hr
))
653 (should (string-equal (buffer-string) (car (last markdown-hr-strings
))))))
655 (ert-deftest test-markdown-insertion
/hr-bob
()
656 "Test inserting horizontal rule at beginning of buffer."
657 (markdown-test-string "one line\n"
658 (call-interactively 'markdown-insert-hr
)
659 (should (string-equal (buffer-string)
660 (concat (car markdown-hr-strings
)
661 "\n\none line\n")))))
663 (ert-deftest test-markdown-insertion
/hr-eob
()
664 "Test inserting horizontal rule at end of buffer."
665 (markdown-test-string "one line\n"
667 (call-interactively 'markdown-insert-hr
)
668 (should (string-equal (buffer-string)
669 (concat "one line\n\n" (car markdown-hr-strings
))))))
671 (ert-deftest test-markdown-insertion
/hr-mob
()
672 "Test inserting horizontal rule in middle of buffer."
673 (markdown-test-string "one line\n"
675 (let ((markdown-hr-strings '("----------")))
676 (call-interactively 'markdown-insert-hr
)
677 (should (string-equal (buffer-string)
678 (concat "one\n\n" (car markdown-hr-strings
)
681 (ert-deftest test-markdown-insertion
/pre-region-1
()
682 "Test `markdown-pre-region'."
683 ;; Simple test as non-interactive command
684 (markdown-test-string "line one\nline two\n"
685 (markdown-pre-region (line-beginning-position) (line-end-position))
686 (should (string-equal (buffer-string) " line one\n\nline two\n")))
687 ;; Test removal of whitespace before and after region
688 (markdown-test-string "line one abc\nline two\n"
689 (markdown-pre-region 6 9)
690 (should (string-equal (buffer-string) "line\n\n one\n\nabc\nline two\n")))
691 ;; Simple test as interactive command
692 (markdown-test-string "line one\nline two\n"
693 (push-mark (point) t t
)
695 (call-interactively 'markdown-pre-region
)
696 (should (string-equal (buffer-string) " line one\n line two\n\n"))))
698 (ert-deftest test-markdown-insertion
/blockquote-region-1
()
699 "Test `markdown-blockquote-region'."
700 ;; Simple test as non-interactive command
701 (markdown-test-string "line one\nline two\n"
702 (markdown-blockquote-region (line-beginning-position) (line-end-position))
703 (should (string-equal (buffer-string) "> line one\n\nline two\n")))
704 ;; Test removal of whitespace before and after region
705 (markdown-test-string "line one abc\nline two\n"
706 (markdown-blockquote-region 6 9)
707 (should (string-equal (buffer-string) "line\n\n> one\n\nabc\nline two\n")))
708 ;; Simple test as interactive command
709 (markdown-test-string "line one\nline two\n"
710 (push-mark (point) t t
)
712 (call-interactively 'markdown-blockquote-region
)
713 (should (string-equal (buffer-string) "> line one\n> line two\n\n"))))
715 (ert-deftest test-markdown-insertion
/pre-nested-lists
()
716 "Test `markdown-pre-indentation' and `markdown-insert-pre' with nested list."
717 (markdown-test-string "* item\n * item\n"
718 ;; before the first item
719 (should (string-equal (markdown-pre-indentation (point)) " "))
720 (markdown-insert-pre)
722 (should (markdown-prev-line-blank-p))
723 (should (looking-at "^ $"))
724 (should (markdown-next-line-blank-p))
725 ;; before the second item
727 (should (string-equal (markdown-pre-indentation (point)) " "))
728 (markdown-insert-pre)
730 (should (markdown-prev-line-blank-p))
731 (should (looking-at "^ $"))
732 (should (markdown-next-line-blank-p))
733 ;; after the second item
735 (should (string-equal (markdown-pre-indentation (point)) " "))
736 (markdown-insert-pre)
738 (should (markdown-prev-line-blank-p))
739 (should (looking-at "^ $"))
740 (should (markdown-next-line-blank-p))))
742 (ert-deftest test-markdown-insertion
/pre-faux-list
()
743 "Test `markdown-pre-indentation' following a list-marker in a pre block."
744 (markdown-test-string " * pre block, not a list item\n"
745 (should (string-equal (markdown-pre-indentation (point-max)) " "))))
747 (ert-deftest test-markdown-insertion
/blockquote-nested-lists
()
748 "Test blockquote insertion in a nested list context."
749 (markdown-test-string "* item\n * item\n"
750 ;; before the first item
751 (should (string-equal (markdown-blockquote-indentation (point)) ""))
752 (markdown-insert-blockquote)
754 (should (markdown-prev-line-blank-p))
755 (should (looking-at "^> $"))
756 (should (markdown-next-line-blank-p))
757 ;; before the second item
759 (should (string-equal (markdown-blockquote-indentation (point)) " "))
760 (markdown-insert-blockquote)
762 (should (markdown-prev-line-blank-p))
763 (should (looking-at "^ > $"))
764 (should (markdown-next-line-blank-p))
765 ;; after the second item
767 (should (string-equal (markdown-blockquote-indentation (point)) " "))
768 (markdown-insert-blockquote)
770 (should (markdown-prev-line-blank-p))
771 (should (looking-at "^ > $"))
772 (should (markdown-next-line-blank-p))))
774 (ert-deftest test-markdown-insertion
/empty-italic
()
775 "Test `markdown-insert-italic' with no word at point and no region."
776 (markdown-test-string ""
777 (call-interactively 'markdown-insert-italic
)
778 (should (string-equal (buffer-string) "**"))
779 (should (= (point) 2))))
781 (ert-deftest test-markdown-insertion
/empty-bold
()
782 "Test `markdown-insert-bold' with no word at point and no region."
783 (markdown-test-string ""
784 (call-interactively 'markdown-insert-bold
)
785 (should (string-equal (buffer-string) "****"))
786 (should (= (point) 3))))
788 (ert-deftest test-markdown-insertion
/list-item
()
789 "Test `markdown-insert-list-item' on several lists."
791 (markdown-test-string "abc"
792 (goto-char (point-max))
793 (call-interactively 'markdown-insert-list-item
)
794 (should (string-equal (buffer-string) "abc\n* "))
795 (should (= (point) 7)))
796 ;; Following a list item, on the same line
797 (markdown-test-string " * foo"
798 (goto-char (point-max))
799 (call-interactively 'markdown-insert-list-item
)
800 (should (string-equal (buffer-string) " * foo\n * ")))
801 ;; Following a list item, on the next line
802 (markdown-test-string "- foo\n"
803 (goto-char (point-max))
804 (call-interactively 'markdown-insert-list-item
)
805 (should (string-equal (buffer-string) "- foo\n- ")))
806 ;; Following a list item, after a blank line
807 (markdown-test-string "- foo\n\n"
808 (goto-char (point-max))
809 (call-interactively 'markdown-insert-list-item
)
810 (should (string-equal (buffer-string) "- foo\n\n- ")))
811 ;; Preceding a list item
812 (markdown-test-string "- foo\n"
813 (goto-char (point-min))
814 (call-interactively 'markdown-insert-list-item
)
815 (should (string-equal (buffer-string) "- \n- foo\n")))
816 ;; Preceding a list item and a blank line
817 (markdown-test-string "\n\n- foo\n"
818 (goto-char (point-min))
819 (call-interactively 'markdown-insert-list-item
)
820 (should (string-equal (buffer-string) "- \n\n- foo\n")))
821 ;; In the middle of a list item
822 (markdown-test-string "- foo bar\n"
824 (call-interactively 'markdown-insert-list-item
)
825 (should (string-equal (buffer-string) "- foo\n- bar\n")))
826 ;; Before a list marker, but not at beginning of line
827 (markdown-test-string " - foo\n"
829 (call-interactively 'markdown-insert-list-item
)
830 (should (string-equal (buffer-string) " - \n - foo\n")))
831 ;; Following an ordered list item
832 (markdown-test-string "6. foo"
833 (goto-char (point-max))
834 (call-interactively 'markdown-insert-list-item
)
835 (should (string-equal (buffer-string) "6. foo\n7. ")))
836 ;; Following a nested ordered list item
837 (markdown-test-string "6. foo\n 1. bar"
838 (goto-char (point-max))
839 (call-interactively 'markdown-insert-list-item
)
840 (should (string-equal (buffer-string) "6. foo\n 1. bar\n 2. "))))
842 (ert-deftest test-markdown-insertion
/reference-link
()
843 "Basic tests for `markdown-insert-reference-link'."
844 ;; Test optional parameters (leave point after link)
845 (markdown-test-string ""
846 (markdown-insert-reference-link "abc" "1")
847 (should (string-equal (buffer-string) "[abc][1]"))
848 (should (= (point) 9)))
849 ;; Full link without title (leave point after link)
850 (markdown-test-string ""
851 (markdown-insert-reference-link "link" "label" "http://jblevins.org/")
852 (should (string-equal (buffer-string) "[link][label]\n\n[label]: http://jblevins.org/\n"))
853 (should (= (point) 14)))
854 ;; Full link without label or title (leave point after link)
855 (markdown-test-string ""
856 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
857 (should (string-equal (buffer-string) "[link][]\n\n[link]: http://jblevins.org/\n"))
858 (should (= (point) 9)))
859 ;; Link only with no label, URL, or title (leave point after link)
860 (markdown-test-string ""
861 (markdown-insert-reference-link "link" "")
862 (should (string-equal (buffer-string) "[link][]"))
863 (should (= (point) 9))))
865 (ert-deftest test-markdown-insertion
/inline-link
()
866 "Basic tests for `markdown-insert-link'."
867 ;; Test empty markup insertion (leave point in square brackets)
868 (markdown-test-string "abc "
870 (call-interactively 'markdown-insert-link
)
871 (should (string-equal (buffer-string) "abc []()"))
872 (should (= (point) 6)))
873 ;; Test with word at point (leave point in parentheses)
874 (markdown-test-string "abc def ghi"
876 (call-interactively 'markdown-insert-link
)
877 (should (string-equal (buffer-string) "abc [def]() ghi"))
878 (should (= (point) 11)))
879 ;; Test with region (leave point in parentheses)
880 (markdown-test-string "abc def ghi"
881 (push-mark (point) t t
)
883 (call-interactively 'markdown-insert-link
)
884 (should (string-equal (buffer-string) "[abc def]() ghi"))
885 (should (= (point) 11))))
889 (ert-deftest test-markdown-footnote
/basic-end
()
890 "Basic footnote insertion and deletion tests for 'end location."
891 (let ((markdown-footnote-location 'end
))
892 (markdown-test-string "first line\nsecond line\n"
893 ;; new buffer with no footnotes
894 (should (= markdown-footnote-counter
0))
895 ;; footnote insertion
897 (markdown-footnote-new)
898 (should (= (point) 35))
899 (should (= markdown-footnote-counter
1))
900 (should (looking-back "\\[^1\\]: "))
901 ;; kill with point in footnote definition
902 (insert "footnote text")
904 (markdown-footnote-kill))
905 (should (= (point) 24))
907 (should (string-equal (buffer-string) "first line\nsecond line\n"))
908 ;; insertion, counter should increment
909 (goto-char (point-min))
911 (markdown-footnote-new)
912 (should (= (point) 35))
913 (should (= markdown-footnote-counter
2))
914 (should (looking-back "\\[^2\\]: "))
915 (insert "footnote text")
917 (markdown-footnote-return)
918 (should (= (point) 15))
919 (should (looking-back "\\[^2\\]"))
920 ;; kill with point at marker
922 (markdown-footnote-kill))
923 (should (= (point) 11))
925 (should (string-equal (buffer-string) "first line\nsecond line\n")))))
927 (ert-deftest test-markdown-footnote
/basic-immediately
()
928 "Basic footnote insertion and deletion tests for 'immediately location."
929 (let ((markdown-footnote-location 'immediately
))
930 (markdown-test-string "first paragraph\n\nsecond paragraph\n"
931 ;; new buffer with no footnotes
932 (should (= markdown-footnote-counter
0))
933 ;; footnote insertion
935 (markdown-footnote-new)
936 (should (= (point) 28))
937 (should (= markdown-footnote-counter
1))
938 (should (looking-back "\\[^1\\]: "))
939 ;; kill with point in footnote definition
940 (insert "footnote text")
942 (markdown-footnote-kill))
943 (should (= (point) 18))
945 (should (string-equal (buffer-string)
946 "first paragraph\n\nsecond paragraph\n")))))
948 (ert-deftest test-markdown-footnote
/basic-header
()
949 "Basic footnote insertion and deletion tests for 'header location."
950 (let ((markdown-footnote-location 'header
))
951 (markdown-test-string "par one\n\npar two\n\n### header\n"
952 ;; new buffer with no footnotes
953 (should (= markdown-footnote-counter
0))
954 ;; footnote insertion
956 (markdown-footnote-new)
957 (should (= (point) 29))
958 (should (= markdown-footnote-counter
1))
959 (should (looking-back "\\[^1\\]: "))
960 ;; kill with point in footnote definition
961 (insert "footnote text")
963 (markdown-footnote-kill))
964 (should (= (point) 19))
966 (should (string-equal (buffer-string)
967 "par one\n\npar two\n\n### header\n"))
968 ;; insertion, counter should increment
969 (goto-char (point-min))
971 (markdown-footnote-new)
972 (should (= (point) 29))
973 (should (= markdown-footnote-counter
2))
974 (should (looking-back "\\[^2\\]: "))
975 (insert "footnote text")
977 (markdown-footnote-return)
978 (should (= (point) 12))
979 (should (looking-back "\\[^2\\]"))
980 ;; kill with point at marker
982 (markdown-footnote-kill))
983 (should (= (point) 8))
985 (should (string-equal (buffer-string)
986 "par one\n\npar two\n\n### header\n")))))
988 (ert-deftest test-markdown-footnote
/kill-empty-text
()
989 "Test killing a footnote with marker but no text."
990 (markdown-test-string "no text[^1]\n\n[^1]: \n"
992 (markdown-footnote-goto-text)
993 (should (looking-back "\\[^1\\]: "))
995 (markdown-footnote-kill))
996 (should (string-equal (buffer-string) "no text\n"))))
998 ;;; Element removal tests:
1000 (ert-deftest test-markdown-kill
/simple
()
1001 "Simple tests for `markdown-kill-thing-at-point'."
1002 (let ((kill-ring nil
)
1003 (tests (list '("`foo`" .
"foo")
1004 '("## foo ##" .
"foo")
1006 '("foo\n---" .
"foo")
1007 '("foo\n===" .
"foo")
1008 '("* * * * *" .
"* * * * *")
1009 '("[foo](http://bar.com/)" .
"foo")
1010 '("![foo](http://bar.com/)" .
"foo")
1011 '("[foo][bar]" .
"foo")
1012 '("![foo][bar]" .
"foo")
1013 '("<http://foo.com/>" .
"http://foo.com/")
1014 '("<foo@bar.com>" .
"foo@bar.com")
1015 '("[[foo]]" .
"foo")
1016 '("[[foo|bar]]" .
"foo")
1017 '("**foo**" .
"foo")
1018 '("__foo__" .
"foo")
1021 '(" [foo]: http://bar.com/" .
"http://bar.com/")
1022 '(" [foo]: http://bar.com/ \"title\"" .
"http://bar.com/")
1023 '("foo[^bar]\n\n[^bar]: baz" .
"baz")
1024 '("[^bar]: baz" .
"baz")
1025 '(" * foo\n bar" .
" * foo\n bar"))))
1026 (dolist (test tests
)
1027 ;; Load test string (the car), move to end of first line, kill
1028 ;; thing at point, and then verify that the kill ring contains cdr.
1029 (markdown-test-string (car test
)
1031 (call-interactively 'markdown-kill-thing-at-point
)
1032 (should (string-equal (current-kill 0) (cdr test
)))))))
1034 ;;; Promotion and demotion tests:
1036 (ert-deftest test-markdown-promote
/atx-header
()
1037 "Test `markdown-promote' for atx headers."
1038 (markdown-test-string "###### test ######"
1040 (should (string-equal (buffer-string) "##### test #####"))
1042 (should (string-equal (buffer-string) "#### test ####"))
1044 (should (string-equal (buffer-string) "### test ###"))
1046 (should (string-equal (buffer-string) "## test ##"))
1048 (should (string-equal (buffer-string) "# test #"))
1050 (should (string-equal (buffer-string) "test"))
1052 (should (string-equal (buffer-string) "test"))))
1054 (ert-deftest test-markdown-demote
/atx-header
()
1055 "Test `markdown-demote' for atx headers."
1056 (markdown-test-string "test"
1058 (should (string-equal (buffer-string) "# test #"))
1060 (should (string-equal (buffer-string) "## test ##"))
1062 (should (string-equal (buffer-string) "### test ###"))
1064 (should (string-equal (buffer-string) "#### test ####"))
1066 (should (string-equal (buffer-string) "##### test #####"))
1068 (should (string-equal (buffer-string) "###### test ######"))
1070 (should (string-equal (buffer-string) "###### test ######"))))
1072 (ert-deftest test-markdown-promote
/setext-header
()
1073 "Test `markdown-promote' for setext headers."
1074 (markdown-test-string "test\n----"
1076 (should (string-equal (buffer-string) "test\n===="))
1078 (should (string-equal (buffer-string) "test"))
1080 (should (string-equal (buffer-string) "test"))))
1082 (ert-deftest test-markdown-demote
/setext-header
()
1083 "Test `markdown-demote' for setext headers."
1084 (markdown-test-string "test\n===="
1086 (should (string-equal (buffer-string) "test\n----"))
1088 (should (string-equal (buffer-string) "### test ###"))
1090 (should (string-equal (buffer-string) "#### test ####"))
1092 (should (string-equal (buffer-string) "##### test #####"))
1094 (should (string-equal (buffer-string) "###### test ######"))
1096 (should (string-equal (buffer-string) "###### test ######"))))
1098 (ert-deftest test-markdown-promote
/hr
()
1099 "Test `markdown-promote' for horizontal rules."
1100 (markdown-test-string (car (reverse markdown-hr-strings
))
1101 (dolist (n (number-sequence 4 0 -
1))
1103 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))
1105 (should (string-equal (buffer-string) (nth 0 markdown-hr-strings
)))))
1107 (ert-deftest test-markdown-demote
/hr
()
1108 "Test `markdown-demote' for horizontal rules."
1109 (markdown-test-string (car markdown-hr-strings
)
1110 (dolist (n (number-sequence 1 5))
1112 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))
1114 (should (string-equal (buffer-string) ""))))
1116 ;;; Completion and cycling:
1118 (ert-deftest test-markdown-complete-or-cycle
/atx-header
()
1119 "Test `markdown-complete-or-cycle' for atx headers."
1120 (markdown-test-string "##### test"
1121 (call-interactively 'markdown-complete-or-cycle
)
1122 (should (string-equal (buffer-string) "##### test #####"))
1123 (call-interactively 'markdown-complete-or-cycle
)
1124 (should (string-equal (buffer-string) "###### test ######"))
1125 (call-interactively 'markdown-complete-or-cycle
)
1126 (should (string-equal (buffer-string) "# test #"))
1127 (call-interactively 'markdown-complete-or-cycle
)
1128 (should (string-equal (buffer-string) "## test ##"))))
1130 (ert-deftest test-markdown-complete-or-cycle
/setext-header
()
1131 "Test `markdown-complete-or-cycle' for setext headers."
1132 (markdown-test-string " test \n=="
1133 (call-interactively 'markdown-complete-or-cycle
)
1134 (should (string-equal (buffer-string) "test\n===="))
1135 (call-interactively 'markdown-complete-or-cycle
)
1136 (should (string-equal (buffer-string) "test\n----"))
1137 (call-interactively 'markdown-complete-or-cycle
)
1138 (should (string-equal (buffer-string) "### test ###"))))
1140 (ert-deftest test-markdown-complete
/hr
()
1141 "Test completion via `markdown-complete-or-cycle' for horizontal rules."
1142 (markdown-test-string "- - - - -"
1143 (call-interactively 'markdown-complete-or-cycle
)
1144 (should (string-equal (buffer-string) (car markdown-hr-strings
)))))
1146 (ert-deftest test-markdown-cycle
/hr
()
1147 "Test cycling via `markdown-complete-or-cycle' for horizontal rules."
1148 (markdown-test-string (car markdown-hr-strings
)
1149 (dolist (n (number-sequence 1 5))
1150 (call-interactively 'markdown-complete-or-cycle
)
1151 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))))
1153 (ert-deftest test-markdown-cycle
/bold
()
1154 "Test cycling via `markdown-complete-or-cycle' for bold markup."
1155 (markdown-test-string "**bold**"
1156 (call-interactively 'markdown-complete-or-cycle
)
1157 (should (string-equal (buffer-string) "__bold__"))
1158 (call-interactively 'markdown-complete-or-cycle
)
1159 (should (string-equal (buffer-string) "**bold**"))))
1161 (ert-deftest test-markdown-cycle
/italic
()
1162 "Test cycling via `markdown-complete-or-cycle' for italic markup."
1163 (markdown-test-string "*italic*"
1164 (call-interactively 'markdown-complete-or-cycle
)
1165 (should (string-equal (buffer-string) "_italic_"))
1166 (call-interactively 'markdown-complete-or-cycle
)
1167 (should (string-equal (buffer-string) "*italic*"))))
1169 ;;; Indentation tests:
1171 (ert-deftest test-markdown-indentation
/calc-indents
()
1172 "Test `markdown-calc-indents' a nested list context."
1173 (markdown-test-file "nested-list.text"
1174 (goto-char (point-max))
1175 (let ((indents (markdown-calc-indents)))
1176 (should (= (car indents
) 17)) ; indentation of previous line first
1177 (should (equal (sort indents
'<)
1179 0 ; beginning of line
1180 3 ; first-level list marker
1181 7 ; second-level list marker
1182 11 ; third-level list marker
1183 13 ; previous list item text
1184 16 ; pre-block indentation
1185 17 ; indentation of previous line
1186 21 ; previous line plus tab-width
1189 (ert-deftest test-markdown-indentation
/indent-region
()
1190 "Test `markdown-indent-region'."
1191 ;; Basic test with multiple lines
1192 (markdown-test-string "abc\ndef\nghi\n"
1193 (markdown-indent-region (point-min) (point-max) nil
)
1194 (should (string-equal (buffer-string) " abc\n def\n ghi\n")))
1195 ;; Following a list item
1196 (markdown-test-string " * abc\ndef\n"
1198 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
1199 (should (string-equal (buffer-string) " * abc\n def\n"))
1200 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
1201 (should (string-equal (buffer-string) " * abc\n def\n"))))
1203 ;;; Font lock tests:
1205 (ert-deftest test-markdown-font-lock
/italics-1
()
1206 "A simple italics test."
1207 (markdown-test-file "inline.text"
1209 (should (looking-at "\*"))
1210 ;; Check face of char before leading asterisk
1211 (markdown-test-range-has-face 8 8 nil
)
1212 ;; Check face of italic range
1213 (markdown-test-range-has-face 9 17 markdown-italic-face
)
1214 ;; Check face of point past leading asterisk
1215 (markdown-test-range-has-face 18 18 nil
)))
1217 (ert-deftest test-markdown-font-lock
/italics-2
()
1218 "Test space after leading asterisk or underscore."
1219 (markdown-test-string
1220 "This is * not italic*, nor _ is this_."
1221 (markdown-test-range-has-face (point-min) (point-max) nil
)))
1223 (ert-deftest test-markdown-font-lock
/italics-3
()
1224 "Test that slash inside asterisks is not italic."
1225 (markdown-test-string
1227 (markdown-test-range-has-face (point-min) (point-max) nil
)))
1229 (ert-deftest test-markdown-font-lock
/italics-4
()
1230 "Test that escaped asterisk inside italics is not bold."
1231 (markdown-test-string
1233 (markdown-test-range-has-face 1 7 nil
)
1234 (markdown-test-range-has-face 8 12 markdown-italic-face
)))
1236 (ert-deftest test-markdown-font-lock
/italics-5
()
1237 "Test italic single letter."
1238 (markdown-test-string
1240 (markdown-test-range-has-face 1 3 markdown-italic-face
)))
1242 (ert-deftest test-markdown-font-lock
/italics-after-hr
()
1243 "Test italics after a horizontal rule with asterisks."
1244 (markdown-test-string "* * *\n\n*italic*\n"
1245 (markdown-test-range-has-face 1 5 markdown-header-face
)
1246 (markdown-test-range-has-face 8 15 markdown-italic-face
)))
1248 (ert-deftest test-markdown-font-lock
/bold-1
()
1249 "A simple bold test."
1250 (markdown-test-file "inline.text"
1252 (should (looking-at "\*\*"))
1253 ;; Check face of char before leading asterisk
1254 (markdown-test-range-has-face 26 26 nil
)
1255 ;; Check face of bold range
1256 (markdown-test-range-has-face 27 35 markdown-bold-face
)
1257 ;; Check face of point past leading asterisk
1258 (markdown-test-range-has-face 36 36 nil
)))
1260 (ert-deftest test-markdown-font-lock
/bold-2
()
1261 "Test space after leading asterisks or underscores."
1262 (markdown-test-string
1263 "This is ** not bold**, nor __ is this__ (but they match italics)."
1264 (markdown-test-range-has-face 1 8 nil
)
1265 (markdown-test-range-has-face 9 20 markdown-italic-face
)
1266 (markdown-test-range-has-face 21 27 nil
)
1267 (markdown-test-range-has-face 28 38 markdown-italic-face
)
1268 (markdown-test-range-has-face 39 (point-max) nil
)))
1270 (ert-deftest test-markdown-font-lock
/bold-3
()
1271 "Test escaped asterisk inside bold."
1272 (markdown-test-string
1274 (markdown-test-range-has-face 6 11 markdown-bold-face
)))
1276 (ert-deftest test-markdown-font-lock
/bold-4
()
1277 "Test bold single letter."
1278 (markdown-test-string
1280 (markdown-test-range-has-face 1 5 markdown-bold-face
)))
1282 (ert-deftest test-markdown-font-lock
/bold-after-hr
()
1283 "Test bold after a horizontal rule with asterisks."
1284 (markdown-test-string "* * *\n\n**bold**\n"
1285 (markdown-test-range-has-face 1 5 markdown-header-face
)
1286 (markdown-test-range-has-face 8 15 markdown-bold-face
)))
1288 (ert-deftest test-markdown-font-lock
/code-1
()
1289 "A simple inline code test."
1290 (markdown-test-file "inline.text"
1292 (should (looking-at "`"))
1293 ;; Regular code span
1294 (markdown-test-range-has-face 45 50 markdown-inline-code-face
)
1295 ;; Code containing backticks
1296 (markdown-test-range-has-face 61 89 markdown-inline-code-face
)
1297 ;; Seven backquotes in a row
1298 (markdown-test-range-has-face 119 125 nil
)
1299 ;; Backquotes at beginning or end
1300 (markdown-test-range-has-face 228 239 markdown-inline-code-face
)
1301 (markdown-test-range-has-face 341 351 markdown-inline-code-face
)
1302 ;; Backslash as final character
1303 (markdown-test-range-has-face 460 468 markdown-inline-code-face
)
1304 ;; Escaping of leading backquotes
1305 (markdown-test-range-has-face 586 592 nil
)
1306 (markdown-test-range-has-face 597 603 nil
)
1307 ;; A code span crossing lines
1308 (markdown-test-range-has-face 652 656 nil
)
1309 (markdown-test-range-has-face 657 666 markdown-inline-code-face
)
1310 ;; Three backquotes: same line, across lines, not across blocks
1311 (markdown-test-range-has-face 695 748 nil
)
1312 (markdown-test-range-has-face 749 757 markdown-inline-code-face
)
1313 (markdown-test-range-has-face 758 805 nil
)
1314 (markdown-test-range-has-face 806 814 markdown-inline-code-face
)
1315 (markdown-test-range-has-face 815 891 nil
)
1318 (ert-deftest test-markdown-font-lock
/code-2
()
1319 "Multiple code spans in a row and on different lines."
1320 (markdown-test-string "`foo` `bar` `baz`"
1321 (markdown-test-range-has-face 1 5 markdown-inline-code-face
)
1322 (markdown-test-range-has-face 6 6 nil
)
1323 (markdown-test-range-has-face 7 11 markdown-inline-code-face
)
1324 (markdown-test-range-has-face 12 12 nil
)
1325 (markdown-test-range-has-face 13 17 markdown-inline-code-face
))
1326 (markdown-test-string "`a`\n`b`\n`c`\n"
1327 (markdown-test-range-has-face 1 3 markdown-inline-code-face
)
1328 (markdown-test-range-has-face 4 4 nil
)
1329 (markdown-test-range-has-face 5 7 markdown-inline-code-face
)
1330 (markdown-test-range-has-face 8 8 nil
)
1331 (markdown-test-range-has-face 9 11 markdown-inline-code-face
)
1332 (markdown-test-range-has-face 12 12 nil
))
1333 (markdown-test-string "a`foo`b`bar`c`baz`d"
1334 (markdown-test-range-has-face 1 1 nil
)
1335 (markdown-test-range-has-face 2 6 markdown-inline-code-face
)
1336 (markdown-test-range-has-face 7 7 nil
)
1337 (markdown-test-range-has-face 8 12 markdown-inline-code-face
)
1338 (markdown-test-range-has-face 13 13 nil
)
1339 (markdown-test-range-has-face 14 18 markdown-inline-code-face
)
1340 (markdown-test-range-has-face 19 19 nil
)))
1342 (ert-deftest test-markdown-font-lock
/lists-1
()
1343 "A simple list marker font lock test."
1344 (markdown-test-file "lists.text"
1345 (dolist (loc (list 1063 1283 1659 1830 1919 2150 2393 2484
1346 2762 2853 3097 3188 3700 3903 4009))
1348 (should (looking-at "[*+-]"))
1349 (markdown-test-range-has-face loc loc markdown-list-face
))))
1351 (ert-deftest test-markdown-font-lock
/pre-1
()
1352 "Nested list and pre block font lock test."
1353 (markdown-test-file "nested-list.text"
1354 (dolist (loc (list 4 29 194 224 491 525))
1355 (markdown-test-range-has-face loc loc markdown-list-face
))
1356 (markdown-test-range-has-face 6 25 nil
)
1357 (markdown-test-range-has-face 31 83 nil
)
1358 (markdown-test-range-has-face 85 155 markdown-pre-face
)
1359 (markdown-test-range-has-face 157 189 nil
)
1360 (markdown-test-range-has-face 196 215 nil
)
1361 (markdown-test-range-has-face 226 403 nil
)
1362 (markdown-test-range-has-face 405 482 markdown-pre-face
)
1363 (markdown-test-range-has-face 493 512 nil
)
1364 (markdown-test-range-has-face 527 546 nil
)
1365 (markdown-test-range-has-face 548 581 markdown-pre-face
)))
1367 (ert-deftest test-markdown-font-lock
/pre-2
()
1368 (markdown-test-string "* item\n\nreset baseline\n\n pre block\n"
1369 (markdown-test-range-has-face 2 24 nil
)
1370 (markdown-test-range-has-face 29 37 markdown-pre-face
)))
1372 (ert-deftest test-markdown-font-lock
/pre-3
()
1373 (markdown-test-string "It is interesting to see what happens when one queries
1374 `social upheaval` and `protopalatial era`.
1376 * `social upheaval`: the follwing queries have been tried:
1378 social upheaval subClassOf"
1379 (markdown-test-range-has-face 160 190 nil
)))
1381 (ert-deftest test-markdown-font-lock
/setext-1-letter
()
1382 "An edge case for level-one setext headers."
1383 (markdown-test-string "a\n=\n"
1384 (markdown-test-range-has-face 1 1 markdown-header-face-1
)
1385 (markdown-test-range-has-face 3 3 markdown-header-rule-face
)))
1387 (ert-deftest test-markdown-font-lock
/setext-2-letter
()
1388 "An edge case for level-two setext headers."
1389 (markdown-test-string "b\n-\n"
1390 (markdown-test-range-has-face 1 1 markdown-header-face-2
)
1391 (markdown-test-range-has-face 3 3 markdown-header-rule-face
)))
1393 (ert-deftest test-markdown-font-lock
/inline-links
()
1394 "Test font lock for inline links."
1395 (markdown-test-file "inline.text"
1396 (markdown-test-range-has-face 925 930 markdown-link-face
)
1397 (markdown-test-range-has-face 931 950 markdown-url-face
)
1398 (markdown-test-range-has-face 951 957 markdown-link-title-face
)
1399 (markdown-test-range-has-face 958 958 markdown-url-face
)))
1401 (ert-deftest test-markdown-font-lock
/footnote-markers-links
()
1402 "Test an edge case involving footnote markers and inline reference links."
1403 (markdown-test-string "Harvard[^1] [tuition][]"
1404 (markdown-test-range-has-face 8 11 markdown-footnote-face
)
1405 (markdown-test-range-has-face 13 21 markdown-link-face
)
1406 (markdown-test-range-has-face 22 23 markdown-reference-face
)))
1408 (ert-deftest test-markdown-font-lock
/mmd-metadata
()
1409 "Basic MultMarkdown metadata tests."
1410 (markdown-test-string "Title: peg-multimarkdown User's Guide
1411 Author: Fletcher T. Penney
1412 Base Header Level: 2 "
1413 (markdown-test-range-has-face 1 5 markdown-metadata-key-face
)
1414 (markdown-test-range-has-face 6 6 nil
)
1415 (markdown-test-range-has-face 8 37 markdown-metadata-value-face
)
1416 (markdown-test-range-has-face 41 46 markdown-metadata-key-face
)
1417 (markdown-test-range-has-face 47 47 nil
)
1418 (markdown-test-range-has-face 49 66 markdown-metadata-value-face
)
1419 (markdown-test-range-has-face 70 86 markdown-metadata-key-face
)
1420 (markdown-test-range-has-face 87 87 nil
)
1421 (markdown-test-range-has-face 89 89 markdown-metadata-value-face
)))
1423 (ert-deftest test-markdown-font-lock
/mmd-metadata-after-header
()
1424 "Ensure that similar lines are not matched after the header."
1425 (markdown-test-string "Title: peg-multimarkdown User's Guide
1427 Author: Fletcher T. Penney
1428 Base Header Level: 2 "
1429 (markdown-test-range-has-face 1 5 markdown-metadata-key-face
)
1430 (markdown-test-range-has-face 6 6 nil
)
1431 (markdown-test-range-has-face 8 37 markdown-metadata-value-face
)
1432 (markdown-test-range-has-face 40 67 nil
)
1433 (markdown-test-range-has-face 71 90 nil
)))
1435 (ert-deftest test-markdown-font-lock
/pandoc-metadata
()
1436 "Basic Pandoc metadata tests."
1437 (markdown-test-string "% title
1444 (markdown-test-range-has-face 1 1 markdown-comment-face
)
1445 (markdown-test-range-has-face 3 24 markdown-metadata-value-face
)
1446 (markdown-test-range-has-face 26 26 markdown-comment-face
)
1447 (markdown-test-range-has-face 28 56 markdown-metadata-value-face
)
1448 (markdown-test-range-has-face 58 58 markdown-comment-face
)
1449 (markdown-test-range-has-face 60 63 markdown-metadata-value-face
)
1450 (markdown-test-range-has-face 64 69 nil
)))
1452 (ert-deftest test-markdown-font-lock
/line-break
()
1453 "Basic line break tests."
1454 (markdown-test-string " \nasdf \n"
1455 (markdown-test-range-has-face 1 9 nil
)
1456 (markdown-test-range-has-face 10 11 markdown-line-break-face
)))
1458 ;;; Markdown Parsing Functions:
1460 (ert-deftest test-markdown-parsing
/reference-definition-basic
()
1461 "Test reference definition function."
1462 (markdown-test-file "syntax.text"
1463 ;; Test accuracy of returned text and bounds
1464 (should (equal (markdown-reference-definition "[1]")
1465 (list "http://docutils.sourceforge.net/mirror/setext.html" 1942 1992)))
1466 (should (equal (markdown-reference-definition "[2]")
1467 (list "http://www.aaronsw.com/2002/atx/" 2000 2032)))
1468 ;; Test that match data remains intact
1469 (should (string-equal (match-string 2) "http://www.aaronsw.com/2002/atx/"))
1470 ;; Test anchor-only relative URL
1471 (should (equal (markdown-reference-definition "[bq]")
1472 (list "#blockquote" 7536 7547)))
1473 ;; Example references that appear in pre blocks in the text
1474 (should (not (markdown-reference-definition "[]")))
1475 (should (not (markdown-reference-definition "[id]")))
1476 (should (not (markdown-reference-definition "[foo]")))
1477 (should (not (markdown-reference-definition "[A]")))
1478 (should (not (markdown-reference-definition "[Google]")))
1479 ;; Test that we don't pick up other text in square brackets
1480 (should (not (markdown-reference-definition "[blockquoting]")))
1481 (should (not (markdown-reference-definition "[square brackets]")))
1482 ;; Test case insensitivity
1483 (should (equal (markdown-reference-definition "[SRC]")
1484 (list "/projects/markdown/syntax.text" 1245 1275)))))
1486 (ert-deftest test-markdown-parsing
/get-defined-references
()
1487 "Test `markdown-get-defined-references'."
1488 (markdown-test-file "syntax.text"
1489 (should (equal (markdown-get-defined-references)
1490 '("[src]" "[1]" "[2]" "[3]" "[4]" "[5]" "[6]" "[bq]" "[l]"))))
1491 (markdown-test-file "outline.text"
1492 (should (equal (markdown-get-defined-references) nil
)))
1493 (markdown-test-file "wiki-links.text"
1494 (should (equal (markdown-get-defined-references) nil
))))
1496 ;;; Reference Checking:
1498 (ert-deftest test-markdown-references
/goto-line-button
()
1499 "Create and test a goto line button."
1500 (markdown-test-string "line 1\nline 2\n"
1501 ;; Store the temporary buffer with the text
1502 (let ((target (current-buffer)))
1503 ;; Create a new buffer for inserting
1505 ;; Verify that point is in a different buffer
1506 (should (not (equal (current-buffer) target
)))
1507 ;; Insert and press the button
1508 (insert-button "goto line 2"
1509 :type
'markdown-goto-line-button
1510 'target-buffer target
1512 (should (string-equal (buffer-string) "goto line 2"))
1514 (call-interactively 'push-button
)
1515 ;; Verify that point is on line 2 of target buffer
1516 (should (= (line-number-at-pos) 2))
1517 (should (looking-at "line 2"))
1518 (should (equal (current-buffer) target
))))))
1520 (ert-deftest test-markdown-references
/button-map
()
1521 "Verify that button-buffer-map is used for check references buffer."
1522 (markdown-test-string "[undefined][ref]\n"
1523 (let* ((target (buffer-name))
1524 (check (format "*Undefined references for %s*" target
)))
1525 (markdown-check-refs)
1526 (with-current-buffer (get-buffer check
)
1527 (should (equal (local-key-binding (kbd "TAB")) 'forward-button
))
1528 (should (equal (local-key-binding (kbd "<backtab>")) 'backward-button
))))))
1532 (ert-deftest test-markdown-lists
/levels-1
()
1533 "Test list levels function `markdown-calculate-list-levels'."
1534 (markdown-test-file "nested-list.text"
1535 (let ((values '(((1 .
1) . nil
) ((2 .
13) .
(3)) ((14 .
23) .
(7 3))
1536 ((24 .
26) .
(11 7 3)))))
1537 (loop for
(range . value
) in values
1538 do
(goto-char (point-min))
1539 (forward-line (1- (car range
)))
1540 (dotimes (n (- (cdr range
) (car range
)))
1541 (should (equal (markdown-calculate-list-levels) value
))
1544 (ert-deftest test-markdown-lists
/levels-2
()
1545 "Test list levels function `markdown-calculate-list-levels'."
1546 (markdown-test-file "syntax.text"
1547 (let ((values '(((1 .
13) . nil
) ((14 .
14) .
(0)) ((15 .
17) .
(4 0))
1548 ((18 .
18) .
(0)) ((19 .
24) .
(4 0)) ((25 .
25) .
(0))
1549 ((26 .
29) .
(4 0)) ((30 .
30) .
(0)) ((31 .
33) .
(4 0))
1550 ((34 .
588) . nil
) ((589 .
595) .
(0)) ((596 .
814) . nil
)
1551 ((815 .
820) .
(0)) ((821 .
898) . nil
))))
1552 (loop for
(range . value
) in values
1553 do
(goto-char (point-min))
1554 (forward-line (1- (car range
)))
1555 (dotimes (n (- (cdr range
) (car range
)))
1556 (should (equal (markdown-calculate-list-levels) value
))
1559 (ert-deftest test-markdown-lists
/levels-interior
()
1560 "Test `markdown-calculate-list-levels' from inside a list item."
1561 (markdown-test-file "nested-list.text"
1563 (should (equal (markdown-calculate-list-levels) (list 3)))
1565 (should (equal (markdown-calculate-list-levels) (list 7 3)))
1567 (should (equal (markdown-calculate-list-levels) (list 11 7 3)))))
1569 (ert-deftest test-markdown-lists
/bounds-1
()
1570 "Test list item bounds function `markdown-cur-list-item-bounds'."
1571 (markdown-test-file "lists.text"
1572 (markdown-test-goto-heading "Case 9")
1574 (should (eq (point) 3699))
1575 (markdown-next-list-item 4)
1576 (should (eq (point) 3700))
1577 (should (equal (markdown-cur-list-item-bounds)
1578 (list 3700 3901 0 4 "- ")))
1579 (markdown-next-list-item 4)
1580 (should (eq (point) 3903))
1581 (should (equal (markdown-cur-list-item-bounds)
1582 (list 3903 3937 0 4 "* ")))))
1584 (ert-deftest test-markdown-lists
/bounds-2
()
1585 "Function `markdown-cur-list-item-bounds' should return nil outside of list items."
1586 (markdown-test-string "line one\n\n* item\n"
1587 (should (null (markdown-cur-list-item-bounds)))
1589 (should (null (markdown-cur-list-item-bounds)))
1591 (should (markdown-cur-list-item-bounds))))
1593 (ert-deftest test-markdown-lists
/promotion-and-demotion
()
1594 "Test function `markdown-promote-list-item'."
1595 (markdown-test-file "nested-list.text"
1597 (should (looking-at " - List level 1 item 2
1599 Second paragraph of item 2
1601 Nested pre block in item 2
1602 Four spaces past the marker
1604 Another paragraph of item 2"))
1605 (markdown-demote-list-item)
1606 (should (looking-at " - List level 1 item 2
1608 Second paragraph of item 2
1610 Nested pre block in item 2
1611 Four spaces past the marker
1613 Another paragraph of item 2"))
1614 (markdown-promote-list-item)
1615 (should (looking-at " - List level 1 item 2
1617 Second paragraph of item 2
1619 Nested pre block in item 2
1620 Four spaces past the marker
1622 Another paragraph of item 2"))
1624 (should (looking-at " - List level 3 item 1
1627 (markdown-demote-list-item)
1628 (should (looking-at " - List level 3 item 1
1631 (markdown-promote-list-item)
1632 (should (looking-at " - List level 3 item 1
1634 Nested pre block"))))
1636 ;;; Outline minor mode tests:
1638 (ert-deftest test-markdown-outline
/navigation
()
1639 "Test outline navigation functions."
1640 (markdown-test-file "outline.text"
1641 ;; Navigate to the first visible heading
1642 (outline-next-visible-heading 1)
1643 (should (eq (point) 19))
1644 (should (looking-at "^# A top-level header"))
1645 ;; Navigate forward at the same level
1646 (outline-forward-same-level 1)
1647 (should (eq (point) 377))
1648 (should (looking-at "^=+$"))
1649 ;; Navigate backward by four visible headings
1650 (outline-previous-visible-heading 4)
1651 (should (eq (point) 69))
1652 (should (looking-at "^## A second-level header$"))))
1654 (ert-deftest test-markdown-outline
/visibility-atx
()
1655 "Test outline visibility cycling for ATX-style headers."
1656 (markdown-test-file "outline.text"
1657 (let (last-command this-command
)
1658 ;; Navigate to the second visible heading
1659 (outline-next-visible-heading 2)
1660 (should (eq (point) 69))
1661 (should (looking-at "^## A second-level header$"))
1662 ;; Cycle visibility of this subtree
1663 (setq this-command
'markdown-cycle
)
1665 (setq last-command
'markdown-cycle
)
1666 (should (eq (point) 69))
1667 (should (looking-at "^## A second-level header$"))
1668 ;; Test that the entire subtree is invisible
1669 (markdown-test-range-has-property 93 349 'invisible
'outline
)
1670 ;; Cycle visibility of this subtree again
1672 (should (eq (point) 69))
1673 (should (looking-at "^## A second-level header$"))
1674 ;; Test that text is visible
1675 (markdown-test-range-has-property 95 121 'invisible nil
)
1676 ;; Test that subheadings are visible
1677 (markdown-test-range-has-property 123 141 'invisible nil
)
1678 ;; Cycle visibility of this subtree again
1680 (should (eq (point) 69))
1681 (should (looking-at "^## A second-level header$"))
1682 ;; Verify that entire subtree is visible
1683 (markdown-test-range-has-property 93 349 'invisible nil
))))
1685 (ert-deftest test-markdown-outline
/visibility-setext
()
1686 "Test outline visibility cycling for setext-style headers."
1687 (markdown-test-file "outline.text"
1688 ;; Navigate to the sixth visible heading
1689 (outline-next-visible-heading 7)
1690 (outline-previous-visible-heading 1)
1691 (should (looking-at markdown-regex-header
))
1692 (should (string-equal (match-string-no-properties 1) "An underline-style header"))
1693 (should (string-equal (match-string-no-properties 2) "========================="))
1694 ;; Cycle visibility subtree, test that it's invisible
1696 (markdown-test-range-has-property 404 515 'invisible
'outline
)
1697 ;; Cycle visibility subtree, test that text and headers are visible
1699 (markdown-test-range-has-property 404 417 'invisible nil
)
1700 (markdown-test-range-has-property 420 451 'invisible nil
)))
1704 (ert-deftest test-markdown-movement
/defun
()
1705 "Test defun navigation."
1706 (markdown-test-file "outline.text"
1707 ;; end-of-defun should go to point-max
1709 (should (= (point) (point-max)))
1710 ;; end-of-defun should stop just before the next header
1711 (goto-char (point-min))
1713 (should (looking-at "\n# A top-level header"))
1715 (should (looking-at "\n## A second-level header"))
1717 (should (looking-at "\n### Third level ###"))
1719 (should (looking-at "\n### Third level number two ###"))
1720 ;; beginning-of-defun should move to the start of the previous header
1721 (beginning-of-defun)
1722 (should (looking-at "### Third level ###"))
1723 (beginning-of-defun)
1724 (should (looking-at "## A second-level header"))
1725 (beginning-of-defun)
1726 (should (looking-at "# A top-level header"))
1727 (beginning-of-defun)
1728 ;; beginning-of-defun should move up to point-min
1729 (should (= (point) (point-min)))))
1731 (ert-deftest test-markdown-movement
/block
()
1732 "Test block movement."
1733 (markdown-test-file "outline.text"
1734 (markdown-end-of-block)
1735 (should (looking-at "\n# A top-level header"))
1736 (markdown-end-of-block)
1737 (should (looking-at "\nfollowed by some body text"))
1738 (markdown-end-of-block)
1739 (should (looking-at "\n## A second-level header"))
1740 (markdown-end-of-block)
1741 (should (looking-at "\nfollowed by some body text"))
1742 (markdown-end-of-block)
1743 (should (looking-at "\n### Third level ###"))
1744 (markdown-end-of-block)
1745 (should (looking-at "\n\\* A list item"))
1746 (markdown-end-of-block)
1747 (should (looking-at "\n### Third level number two ###"))
1748 (markdown-end-of-block)
1749 (should (looking-at "\n### Level two again"))
1750 (markdown-end-of-block)
1751 (should (looking-at "\nfollowed by some body text"))
1753 (markdown-test-goto-heading "Level two")
1754 (markdown-end-of-block)
1755 (should (looking-at "\nbar"))
1756 (markdown-end-of-block)
1757 (should (= (point) (point-max)))
1758 (markdown-beginning-of-block)
1759 (should (looking-at "bar"))
1760 (markdown-beginning-of-block)
1761 (should (looking-at "## Level two"))
1762 (markdown-beginning-of-block)
1763 (should (looking-at "foo"))
1764 (markdown-beginning-of-block)
1765 (should (looking-at "# Level one"))
1766 (markdown-beginning-of-block)
1767 (should (looking-at "* With"))
1768 (markdown-beginning-of-block)
1769 (should (looking-at "And a level two underline header"))
1771 (goto-char (point-min))
1772 (markdown-test-goto-heading "A top-level header")
1774 (markdown-beginning-of-block)
1775 (should (= (point) (point-min)))))
1777 (ert-deftest test-markdown-movement
/reference-definition
()
1778 "Test jumping to reference definitions."
1779 ;; Jumping to explicit reference definition
1780 (markdown-test-string "[a][ref]\n\n[ref]: gopher://localhost/\n"
1781 (markdown-reference-goto-definition)
1782 (should (= (point) 18)))
1783 ;; Jumping to implicit reference definition
1784 (markdown-test-string "[a][]\n\n[a]: ftp://localhost/\n"
1785 (markdown-reference-goto-definition)
1786 (should (= (point) 13)))
1787 ;; Creating non-existent reference definition
1788 (markdown-test-string "[a][]\n"
1789 (markdown-reference-goto-definition)
1790 (should (= (point) 13))
1791 (should (string-equal (buffer-string) "[a][]\n\n[a]: "))))
1793 ;;; Wiki link tests:
1795 (ert-deftest test-markdown-wiki-link
/aliasing
()
1796 "Test filename extraction for aliased wiki links."
1797 (markdown-test-file "wiki-links.text"
1798 ;; Confirm location of first wiki link
1799 (should (eq (markdown-next-link) 8))
1800 ;; Confirm location of second wiki link
1801 (should (eq (markdown-next-link) 73))
1802 ;; Test predicate function
1803 (should (markdown-wiki-link-p))
1804 ;; Test alias-first filename extraction
1805 (setq markdown-wiki-link-alias-first t
)
1806 (should (string-equal (markdown-wiki-link-link) "second"))
1807 ;; Test alias-second filename extraction
1808 (setq markdown-wiki-link-alias-first nil
)
1809 (should (string-equal (markdown-wiki-link-link) "first"))))
1811 (ert-deftest test-markdown-wiki-link
/navigation
()
1812 "Test wiki link navigation."
1813 (markdown-test-file "wiki-links.text"
1814 ;; Advance to first link
1815 (should (eq (markdown-next-link) 8))
1816 ;; Advance to second link
1817 (should (eq (markdown-next-link) 73))
1818 ;; Avance to final link
1819 (should (eq (markdown-next-link) 155))
1820 ;; Return nil and don't advance point
1821 (should (eq (markdown-next-link) nil
))
1822 (should (eq (point) 155))
1823 ;; Move back to second link
1824 (should (eq (markdown-previous-link) 73))
1825 ;; Move back to first link
1826 (should (eq (markdown-previous-link) 8))
1827 ;; Return nil and don't move point
1828 (should (eq (markdown-previous-link) nil
))
1829 (should (eq (point) 8))))
1831 (ert-deftest test-markdown-wiki-link
/font-lock
()
1832 "Test font lock faces for wiki links."
1833 (markdown-test-temp-file "wiki-links.text"
1834 (let* ((fn (concat (file-name-directory buffer-file-name
)
1836 ;; Create inline.text in the same temp directory, refontify
1837 (write-region "" nil fn nil
1)
1838 (markdown-fontify-buffer-wiki-links)
1839 ;; Confirm location of first wiki link
1840 (should (eq (markdown-next-link) 8))
1841 ;; First wiki link doesn't have a corresponding file
1842 (markdown-test-range-has-property 8 20 'font-lock-face markdown-missing-link-face
)
1843 ;; Second wiki link doesn't have a corresponding file
1844 (should (eq (markdown-next-link) 73))
1845 (markdown-test-range-has-property 73 88 'font-lock-face markdown-missing-link-face
)
1846 ;; Move to third wiki link, and create the missing file
1847 (should (eq (markdown-next-link) 155))
1848 (should (string-equal (markdown-wiki-link-link) "inline"))
1849 (markdown-test-range-has-property 155 164 'font-lock-face markdown-link-face
)
1850 ;; Remove temporary files
1856 (ert-deftest test-markdown-filling
/blockquote
()
1857 "Test filling of blockquotes.
1858 See `adaptive-fill-first-line-regexp'."
1859 (markdown-test-string "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
1861 (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."))))
1863 (ert-deftest test-markdown-filling
/list-item-plus
()
1864 "Test filling of list items with plus sign markers.
1865 See `adaptive-fill-regexp'."
1866 (markdown-test-string " + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
1868 (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."))))
1870 (ert-deftest test-markdown-filling
/list-item-plus-in-blockquote
()
1871 "Test filling of list items with plus sign markers inside blockquote.
1872 See `adaptive-fill-regexp'."
1873 (markdown-test-string "> + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
1875 (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."))))
1877 (ert-deftest test-markdown-filling
/line-break
()
1878 "Test filling of paragraphs with hard line breaks.
1879 See `paragraph-separate'."
1880 (markdown-test-string "Lorem ipsum dolor sit amet, \nconsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
1881 (let ((fill-column 70))
1883 (should (string-equal (buffer-string) "Lorem ipsum dolor sit amet, \nconsectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua.")))))
1887 (ert-deftest test-markdown-hook
/xhtml-standalone
()
1888 "Test `markdown-xhtml-standalone-regexp' and `markdown-output-standalone-p'."
1889 (should (string-match markdown-xhtml-standalone-regexp
1890 "<?xml version='1.0' encoding='UTF-8'?>"))
1891 (should (string-match markdown-xhtml-standalone-regexp
1893 (should (string-match markdown-xhtml-standalone-regexp
1895 (should-not (string-match markdown-xhtml-standalone-regexp
1897 (should-not (string-match markdown-xhtml-standalone-regexp
1898 "<div id=\"name\">")))
1902 (ert-deftest test-markdown-hook
/before-export
()
1903 "Test hook run before export XHTML."
1904 (markdown-test-temp-file "lists.text"
1905 (let* ((before-hook-run nil
)
1906 (ofile (concat buffer-file-name
".html"))
1907 (func (lambda (fname)
1908 (setq before-hook-run t
)
1909 (should (string-equal fname ofile
)))))
1910 ;; Register function
1911 (add-hook 'markdown-before-export-hooks func
)
1913 (markdown-export ofile
)
1914 (should (eq before-hook-run t
))
1916 (remove-hook 'markdown-before-export-hooks func
)
1917 (kill-buffer (get-file-buffer ofile
))
1918 (delete-file ofile
))))
1920 (ert-deftest test-markdown-hook
/after-export
()
1921 "Test hook run after export XHTML."
1922 (markdown-test-temp-file "lists.text"
1923 (let* ((after-hook-run nil
)
1924 (ofile (concat buffer-file-name
".html"))
1925 (func (lambda (fname)
1926 (setq after-hook-run t
)
1927 (should (string-equal fname ofile
)))))
1928 ;; Register function
1929 (add-hook 'markdown-after-export-hooks func
)
1931 (markdown-export ofile
)
1932 (should (eq after-hook-run t
))
1934 (remove-hook 'markdown-after-export-hooks func
)
1935 (kill-buffer (get-file-buffer ofile
))
1936 (delete-file ofile
))))
1940 (ert-deftest test-markdown-gfm
/pre-1
()
1941 "GFM pre block font lock test."
1942 (markdown-test-file-gfm "gfm.text"
1943 (markdown-test-range-has-face 2626 2637 nil
)
1944 (markdown-test-range-has-face 2639 2641 markdown-pre-face
)
1945 (markdown-test-range-has-face 2642 2645 markdown-language-keyword-face
)
1946 (markdown-test-range-has-face 2647 2728 markdown-pre-face
)
1947 (markdown-test-range-has-face 2730 2732 markdown-pre-face
)))
1949 (ert-deftest test-markdown-gfm
/italic-1
()
1950 "GFM italic font lock test."
1951 (markdown-test-file-gfm "gfm.text"
1952 (markdown-test-range-has-face 1483 1488 markdown-italic-face
)
1953 (markdown-test-range-has-face 1729 1790 nil
)))
1955 (provide 'markdown-test
)
1957 ;;; markdown-test.el ends here