1 ;;;; markdown-test.el --- Tests for markdown-mode
3 ;; Copyright (C) 2013-2015 Jason R. Blevins <jrblevin@sdf.org>
4 ;; Copyright (C) 2013 Makoto Motohashi <mkt.motohashi@gmail.com>
5 ;; Copyright (C) 2015 Google, Inc. (Contributor: Samuel Freilich <sfreilich@google.com>)
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program; if not, write to the Free Software
21 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; This file contains the `markdown-mode' test suite. To run the tests:
28 ;; M-x load-file RET markdown-test.el RET
29 ;; M-x markdown-test RET
33 (require 'markdown-mode
)
37 (defconst markdown-test-dir
38 (expand-file-name (file-name-directory
39 (or load-file-name buffer-file-name
))))
41 (defconst markdown-test-font-lock-function
42 (if (and noninteractive
(fboundp 'font-lock-ensure
))
43 #'font-lock-ensure
#'font-lock-fontify-buffer
))
45 (defmacro markdown-test-string-mode
(mode string
&rest body
)
46 "Run BODY in a temporary buffer containing STRING in MODE."
48 `(let ((win (selected-window)))
51 (set-window-buffer win
(current-buffer) t
)
54 (setq-default indent-tabs-mode nil
)
56 (goto-char (point-min))
57 (funcall markdown-test-font-lock-function
)
58 (prog1 ,@body
(kill-buffer))))))
60 (defmacro markdown-test-file-mode
(mode file
&rest body
)
61 "Open FILE from `markdown-test-dir' in MODE and execute BODY."
63 `(let ((fn (concat markdown-test-dir
,file
)))
64 (save-window-excursion
66 (insert-file-contents fn
)
68 (goto-char (point-min))
69 (funcall markdown-test-font-lock-function
)
72 (defmacro markdown-test-string
(string &rest body
)
73 "Run body in a temporary buffer containing STRING in `markdown-mode'."
75 `(markdown-test-string-mode 'markdown-mode
,string
,@body
))
76 (def-edebug-spec markdown-test-string
(form body
))
78 (defmacro markdown-test-file
(file &rest body
)
79 "Open FILE from `markdown-test-dir' in `markdown-mode' and execute BODY."
81 `(markdown-test-file-mode 'markdown-mode
,file
,@body
))
82 (def-edebug-spec markdown-test-file
(form body
))
84 (defmacro markdown-test-string-gfm
(string &rest body
)
85 "Run body in a temporary buffer containing STRING in `gfm-mode'."
87 `(markdown-test-string-mode 'gfm-mode
,string
,@body
))
88 (def-edebug-spec markdown-test-string-gfm
(form body
))
90 (defmacro markdown-test-file-gfm
(file &rest body
)
91 "Open FILE from `markdown-test-dir' in `gfm-mode' and execute BODY."
93 `(markdown-test-file-mode 'gfm-mode
,file
,@body
))
94 (def-edebug-spec markdown-test-file-gfm
(form body
))
96 (defmacro markdown-test-temp-file
(file &rest body
)
97 "Open FILE from `markdown-test-dir' visiting temp file and execute body.
98 This file is not saved."
100 `(let ((fn (concat markdown-test-dir
,file
))
101 (tmp (make-temp-file "markdown-test" nil
".text"))
103 (save-window-excursion
106 (setq buf
(find-file tmp
))
107 (insert-file-contents fn
)
109 (goto-char (point-min))
110 (funcall markdown-test-font-lock-function
)
112 (set-buffer-modified-p nil
))
113 (when (buffer-live-p buf
) (kill-buffer buf
))
114 (delete-file tmp
)))))
115 (def-edebug-spec markdown-test-temp-file
(form body
))
117 (defun markdown-test-report-property-range (begin end prop
)
118 "Report buffer substring and property PROP from BEGIN to END."
119 (message "Buffer substring: %s" (buffer-substring begin
(1+ end
)))
120 (message "Properties in range are as follows:")
121 (dolist (loc (number-sequence begin end
))
122 (message "%d: %s" loc
(get-char-property loc prop
))))
124 (defun markdown-test-range-has-property (begin end prop value
)
125 "Verify that range BEGIN to END has PROP equal to or containing VALUE."
129 (dolist (loc (number-sequence begin end
))
130 (setq vals
(get-char-property loc prop
))
131 (if (and vals
(listp vals
))
132 (unless (memq value vals
)
134 (unless (eq vals value
)
135 (throw 'fail loc
))))))
137 (message "Testing range (%d,%d) for property %s equal to %s."
138 begin end prop value
)
139 (message "Expected value (%s) not found in property (%s) at location %d" value prop fail-loc
)
140 (markdown-test-report-property-range begin end prop
))
141 (should-not fail-loc
)))
143 (defun markdown-test-range-property-equals (begin end prop value
)
144 "Verify that range BEGIN to END has property PROP equal to VALUE."
147 (dolist (loc (number-sequence begin end
))
148 (unless (eq (get-char-property loc prop
) value
)
149 (throw 'fail loc
))))))
151 (message "Testing range (%d,%d) for property %s equal to %s."
152 begin end prop value
)
153 (message "Expected value (%s) not found in property (%s) at location %d" value prop fail-loc
)
154 (markdown-test-report-property-range begin end prop
))
155 (should-not fail-loc
)))
157 (defun markdown-test-range-has-face (begin end face
)
158 "Verify that the range from BEGIN to END has face FACE."
159 (markdown-test-range-has-property begin end
'face face
))
161 (defun markdown-test-range-face-equals (begin end face
)
162 "Verify that the range from BEGIN to END has face equal to FACE."
163 (markdown-test-range-property-equals begin end
'face face
))
165 (defun markdown-test-goto-heading (title)
166 "Move the point to section with TITLE."
167 (let ((regexp (format "\\(^#+ %s\\( #+\\)?\\|^%s\n[=-]+\n\\)" title title
)))
168 (if (re-search-forward regexp nil t
)
169 (goto-char (match-end 0)))))
171 (defun markdown-test ()
172 "Run all defined tests for `markdown-mode'."
178 (ert-deftest test-markdown-example
/string
()
179 "An example string test using the `ert' framework."
180 (markdown-test-string "foo *bar* baz"
183 (should (looking-at "bar"))))
185 (ert-deftest test-markdown-example
/file
()
186 "An example file test using the `ert' framework."
187 (markdown-test-file "inline.text"
189 (should (looking-at "\*"))))
191 ;;; Basic mode tests:
193 (ert-deftest test-markdown-mode
/variables
()
194 "Test `markdown-mode' variables."
195 (markdown-test-file "inline.text"
196 (should (= tab-width
4))
197 (should (eq font-lock-multiline t
))
198 (should (eq major-mode
'markdown-mode
))))
200 ;;; Element insertion tests:
202 (ert-deftest test-markdown-insertion
/blank-line-before-1
()
203 "Test function `markdown-ensure-blank-line-before' at beginning of line."
204 (markdown-test-file "syntax.text"
205 (search-forward "as plain text")
206 (should (= (point) 1556))
208 (should (= (point) 1505))
209 (should (looking-back "A Markdown-formatted\n" nil
))
210 (should (not (markdown-prev-line-blank-p)))
211 (markdown-ensure-blank-line-before)
212 (should (looking-back "A Markdown-formatted\n\n" nil
))
213 (should (markdown-prev-line-blank-p))))
215 (ert-deftest test-markdown-insertion
/blank-line-before-2
()
216 "Test function `markdown-ensure-blank-line-before' in middle of line."
217 (markdown-test-file "syntax.text"
218 (search-forward "as plain text")
219 (should (= (point) 1556))
220 (should (looking-back "as plain text" nil
))
221 (should (not (markdown-prev-line-blank-p)))
222 (markdown-ensure-blank-line-before)
223 (should (looking-back "as plain text\n\n" nil
))
224 (should (markdown-prev-line-blank-p))))
226 (ert-deftest test-markdown-insertion
/blank-line-before-3
()
227 "Test function `markdown-ensure-blank-line-before' with blank line before."
228 (markdown-test-file "syntax.text"
229 (search-forward "web.\n\nMarkdown is not a replacement for HTML")
231 (should (= (point) 2704))
232 (should (looking-back "web.\n\n" nil
))
233 (should (markdown-prev-line-blank-p))
234 (markdown-ensure-blank-line-before)
235 (should (= (point) 2704))
236 (should (looking-back "web.\n\n" nil
))
237 (should (markdown-prev-line-blank-p))))
239 (ert-deftest test-markdown-insertion
/blank-line-before-4
()
240 "Test function `markdown-ensure-blank-line-before' at beginning of buffer."
241 (markdown-test-string "first line"
244 (should (= (point-max) 11))
245 (markdown-ensure-blank-line-before)
246 (should (= (point-max) 11))
247 (should (string-equal (buffer-substring (point-min) (point-max))
250 (markdown-ensure-blank-line-before)
251 (should (string-equal (buffer-substring (point-min) (point-max))
254 (ert-deftest test-markdown-insertion
/blank-line-after-1
()
255 "Test function `markdown-ensure-blank-line-after' at end of line."
256 (markdown-test-file "syntax.text"
257 (search-forward "as plain text")
258 (should (= (point) 1556))
260 (should (= (point) 1573))
261 (should (looking-at "\nlike it's been"))
262 (should (not (markdown-next-line-blank-p)))
263 (markdown-ensure-blank-line-after)
264 (should (looking-at "\n\nlike it's been"))
265 (should (markdown-next-line-blank-p))))
267 (ert-deftest test-markdown-insertion
/blank-line-after-2
()
268 "Test function `markdown-ensure-blank-line-after' in middle of line."
269 (markdown-test-file "syntax.text"
270 (search-forward "as plain text")
271 (should (= (point) 1556))
272 (should (looking-at ", without looking"))
273 (should (not (markdown-next-line-blank-p)))
274 (markdown-ensure-blank-line-after)
275 (should (looking-at "\n\n, without looking"))
276 (should (markdown-next-line-blank-p))))
278 (ert-deftest test-markdown-insertion
/blank-line-after-3
()
279 "Test function `markdown-ensure-blank-line-after' with blank line after."
280 (markdown-test-file "syntax.text"
281 (search-forward "*writing* for the web.")
282 (should (= (point) 2702))
283 (should (looking-at "\n\nMarkdown is not a replacement for HTML"))
284 (should (markdown-next-line-blank-p))
285 (markdown-ensure-blank-line-after)
286 (should (= (point) 2702))
287 (should (looking-at "\n\nMarkdown is not a replacement for HTML"))
288 (should (markdown-next-line-blank-p))))
290 (ert-deftest test-markdown-insertion
/blank-line-after-4
()
291 "Test function `markdown-ensure-blank-line-after' at end of buffer."
292 (markdown-test-string "last line"
295 (should (= (point-max) 10))
296 (markdown-ensure-blank-line-after)
297 (should (= (point-max) 10))
298 (should (string-equal (buffer-substring (point-min) (point-max))
301 (markdown-ensure-blank-line-after)
302 (should (string-equal (buffer-substring (point-min) (point-max))
305 (ert-deftest test-markdown-insertion
/point-after-unwrap
()
306 "Test new point position calculations after unwrap operations."
307 (markdown-test-string "line **one**\n"
308 (let ((prefix (cons 6 8)) (suffix (cons 11 13)))
310 (should (eq (markdown-point-after-unwrap 6 prefix suffix
) 6))
311 (should (eq (markdown-point-after-unwrap 7 prefix suffix
) 6))
313 (should (eq (markdown-point-after-unwrap 8 prefix suffix
) 6))
314 (should (eq (markdown-point-after-unwrap 9 prefix suffix
) 7))
315 (should (eq (markdown-point-after-unwrap 10 prefix suffix
) 8))
317 (should (eq (markdown-point-after-unwrap 11 prefix suffix
) 9))
318 (should (eq (markdown-point-after-unwrap 12 prefix suffix
) 9))
320 (should (eq (markdown-point-after-unwrap 13 prefix suffix
) 9))))
321 (markdown-test-string "line _one_\n"
322 (let ((prefix (cons 6 7)) (suffix (cons 10 11)))
324 (should (eq (markdown-point-after-unwrap 6 prefix suffix
) 6))
326 (should (eq (markdown-point-after-unwrap 7 prefix suffix
) 6))
327 (should (eq (markdown-point-after-unwrap 8 prefix suffix
) 7))
328 (should (eq (markdown-point-after-unwrap 9 prefix suffix
) 8))
330 (should (eq (markdown-point-after-unwrap 10 prefix suffix
) 9))
332 (should (eq (markdown-point-after-unwrap 10 prefix suffix
) 9)))))
334 (ert-deftest test-markdown-insertion
/unwrap-thing-at-point-italic
()
335 "Test function `markdown-unwrap-thing-at-point' on italics."
336 (markdown-test-file "syntax.text"
339 (should (thing-at-point-looking-at markdown-regex-italic
))
340 (should (equal (markdown-unwrap-thing-at-point
341 markdown-regex-italic
1 3)
343 (should (= (point) 2859))
344 ;; Unwrap *publishing*
346 (should (thing-at-point-looking-at markdown-regex-italic
))
347 (should (equal (markdown-unwrap-thing-at-point
348 markdown-regex-italic
1 3)
350 (should (= (point) 3063))
353 (should (thing-at-point-looking-at markdown-regex-italic
))
354 (should (equal (markdown-unwrap-thing-at-point
355 markdown-regex-italic
1 3)
357 (should (= (point) 3100))))
359 (ert-deftest test-markdown-insertion
/unwrap-things-in-region-italic
()
360 "Test function `markdown-unwrap-things-in-region' on italics."
361 (markdown-test-file "syntax.text"
362 (should (equal (markdown-unwrap-things-in-region
363 2704 3207 markdown-regex-italic
1 3)
366 (ert-deftest test-markdown-insertion
/unwrap-things-in-region-bound
()
367 "Ensure that `markdown-unwrap-things-in-region' respects end bound"
368 (markdown-test-string "**a** **b** **c** **d** **e** **f**"
369 ;; Set region to unrwap a, b, c, and d only. If endpoint is not
370 ;; respected (i.e, not adjusted for character removal), the
371 ;; function will unwrap e and f also.
372 (should (equal (markdown-unwrap-things-in-region
373 1 24 markdown-regex-bold
2 4)
375 (should (string-equal (buffer-string) "a b c d **e** **f**"))))
377 (ert-deftest test-markdown-insertion
/unwrap-things-in-region-links
()
378 "Test function `markdown-unwrap-things-in-region' on inline links."
379 (markdown-test-string "a [link](http://jblevins.org/) or [two](/).\n"
380 (should (equal (markdown-unwrap-things-in-region
381 (point-min) (point-max) markdown-regex-link-inline
0 3)
383 (should (string-equal (buffer-string) "a link or two.\n"))))
385 (ert-deftest test-markdown-insertion
/toggle-bold
()
386 "Test toggling functionality of `markdown-insert-bold'."
387 (markdown-test-string "one **two** three"
389 (markdown-insert-bold)
390 (should (string-equal (buffer-string) "one two three"))
391 (should (= (point) 8))
393 (markdown-insert-bold)
394 (should (= (point) 16))
395 (should (string-equal (buffer-string) "one two **three**"))))
397 (ert-deftest test-markdown-insertion
/toggle-italic
()
398 "Test toggling functionality of `markdown-insert-italic'."
399 (markdown-test-string "one *two* three"
401 (markdown-insert-italic)
402 (should (string-equal (buffer-string) "one two three"))
403 (should (= (point) 8))
405 (markdown-insert-italic)
406 (should (string-equal (buffer-string) "one two *three*"))
407 (should (= (point) 15))))
409 (ert-deftest test-markdown-insertion
/toggle-code
()
410 "Test toggling functionality of `markdown-insert-code'."
411 (markdown-test-string "one `two` three"
413 (markdown-insert-code)
414 (should (string-equal (buffer-string) "one two three"))
415 (should (= (point) 8))
417 (markdown-insert-code)
418 (should (string-equal (buffer-string) "one two `three`"))
419 (should (= (point) 15))))
421 (ert-deftest test-markdown-insertion
/toggle-kbd
()
422 "Test toggling functionality of `markdown-insert-code'."
423 (markdown-test-string "test <kbd>C-c C-s k</kbd> toggle"
425 (markdown-insert-kbd)
426 (should (string-equal (buffer-string) "test C-c C-s k toggle"))
427 (should (= (point) 6))
429 (markdown-insert-kbd)
430 (should (string-equal (buffer-string) "<kbd>test</kbd> C-c C-s k toggle"))
431 (should (= (point) 6))))
433 (ert-deftest test-markdown-insertion
/toggle-wiki-link-alias-first
()
434 "Test toggling of `markdown-insert-wiki-link' with alias first.
435 Test point position upon removal and insertion."
436 (let ((markdown-wiki-link-alias-first t
))
437 (markdown-test-string "[[text|page]]"
438 (goto-char 5) ; point in interior of alias text, at 'x'
439 (call-interactively 'markdown-insert-wiki-link
)
440 (should (= (point) 3)) ; leave point at, at 'x'
441 (should (string-equal (buffer-string) "text"))
442 (call-interactively 'markdown-insert-wiki-link
)
443 (should (= (point) 5)) ; leave point at, at 'x'
444 (should (string-equal (buffer-string) "[[text]]")))
445 (markdown-test-string "[[text|page]]"
446 (goto-char 10) ; point in interior of link text, at 'g'
447 (call-interactively 'markdown-insert-wiki-link
)
448 (should (= (point) 5)) ; leave point at end of alias text
449 (should (string-equal (buffer-string) "text"))
450 (call-interactively 'markdown-insert-wiki-link
)
451 (should (= (point) 7)) ; leave point at end of alias text
452 (should (string-equal (buffer-string) "[[text]]")))))
454 (ert-deftest test-markdown-insertion
/toggle-wiki-link-alias-last
()
455 "Test toggling of `markdown-insert-wiki-link' with alias last.
456 Test point position upon removal and insertion."
457 (let ((markdown-wiki-link-alias-first nil
))
458 (markdown-test-string "[[page|text]]"
459 (goto-char 10) ; point in interior of alias text, at 'x'
460 (call-interactively 'markdown-insert-wiki-link
)
461 (goto-char 3) ; leave point at, at 'x'
462 (should (string-equal (buffer-string) "text"))
463 (call-interactively 'markdown-insert-wiki-link
)
464 (should (= (point) 5)) ; leave point at, at 'x'
465 (should (string-equal (buffer-string) "[[text]]")))
466 (markdown-test-string "[[page|text]]"
467 (goto-char 3) ; point in interior of link text, at 'g'
468 (call-interactively 'markdown-insert-wiki-link
)
469 (should (= (point) 1)) ; leave point at beginning of alias text
470 (should (string-equal (buffer-string) "text"))
471 (call-interactively 'markdown-insert-wiki-link
)
472 (should (= (point) 3)) ; leave point at beginning of alias text
473 (should (string-equal (buffer-string) "[[text]]")))))
475 (ert-deftest test-markdown-insertion
/bold-region
()
476 "Test region functionality of `markdown-insert-bold'."
477 (markdown-test-string "one two three"
478 (push-mark (point) t t
)
480 (markdown-insert-bold)
481 (should (string-equal (buffer-string) "**one two** three"))
482 (should (= (point) 10))))
484 (ert-deftest test-markdown-insertion
/italic-region
()
485 "Test region functionality of `markdown-insert-italic'."
486 (markdown-test-string "one two three"
487 (transient-mark-mode)
488 (push-mark (point) t t
)
490 (markdown-insert-italic)
491 (should (string-equal (buffer-string) "*one two* three"))
492 (should (= (point) 9))))
494 (ert-deftest test-markdown-insertion
/code-region
()
495 "Test region functionality of `markdown-insert-code'."
496 (markdown-test-string "one two three"
497 (transient-mark-mode)
498 (push-mark (point) t t
)
500 (markdown-insert-code)
501 (should (string-equal (buffer-string) "`one two` three"))
502 (should (= (point) 9))))
504 (ert-deftest test-markdown-insertion
/kbd-region
()
505 "Test region functionality of `markdown-insert-kbd'."
506 (markdown-test-string "one two three"
507 (transient-mark-mode)
508 (push-mark (point) t t
)
510 (markdown-insert-kbd)
511 (should (string-equal (buffer-string) "<kbd>one two</kbd> three"))
512 (should (= (point) 13))))
514 (ert-deftest test-markdown-insertion
/atx-line
()
515 "Test ATX header insertion without region."
516 (markdown-test-string "line one\nline two\n"
518 (markdown-insert-header-atx-1)
519 (should (= (point) 11))
520 (should (string-equal (buffer-substring (point-min) (point-max))
521 "# line one #\n\nline two\n"))
523 (markdown-insert-header-atx-2)
524 (should (= (point) 26))
525 (should (string-equal (buffer-substring (point-min) (point-max))
526 "# line one #\n\n## line two ##\n\n"))))
528 (ert-deftest test-markdown-insertion
/atx-region
()
529 "Test ATX header insertion with region."
530 (markdown-test-string "line one\nline two\n"
531 (transient-mark-mode)
533 (push-mark (point) t t
)
535 (should (string-equal (buffer-substring (region-beginning) (region-end))
537 (markdown-insert-header-atx-4)
538 (should (= (point) 16))
539 (should (string-equal (buffer-substring (point-min) (point-max))
540 "line \n\n#### one ####\n\nline two\n"))))
542 (ert-deftest test-markdown-insertion
/atx-blank
()
543 "Test ATX header insertion on blank line."
544 (markdown-test-string "line one\n\nline two\n"
546 (markdown-insert-header-atx-3)
547 (should (string-equal (buffer-substring (point-min) (point-max))
548 "line one\n\n### ###\n\nline two\n"))
549 (should (= (point) 15))
550 (should (looking-at " ###\n"))))
552 (ert-deftest test-markdown-insertion
/atx-region-whitespace
()
553 "Test ATX header insertion using a region with whitespace."
554 (markdown-test-string " line one\n\nline two\n \n"
555 (transient-mark-mode)
556 (push-mark (point) t t
)
557 (goto-char (point-max))
558 (markdown-insert-header-atx-2)
559 (should (string-equal (buffer-substring (point-min) (point-max))
560 "## line one line two ##"))
561 (should (= (point) 21))
562 (should (looking-at " ##"))))
564 (ert-deftest test-markdown-insertion
/atx-line-whitespace
()
565 "Test ATX header insertion using current line with whitespace."
566 (markdown-test-string " line one \n\nline two\n"
567 (goto-char (line-end-position))
568 (markdown-insert-header-atx-3)
569 (should (string-equal (buffer-substring (point-min) (point-max))
570 "### line one ###\n\nline two\n"))
571 (should (= (point) 13))
572 (should (looking-at " ###\n"))))
574 (ert-deftest test-markdown-insertion
/atx-replace-atx
()
575 "Test ATX header insertion when replacing an existing ATX header."
576 (markdown-test-string "## replace ##\n"
577 (markdown-insert-header-atx-4)
578 (should (string-equal (buffer-string) "#### replace ####\n\n"))
579 (should (looking-at " ####\n"))))
581 (ert-deftest test-markdown-insertion
/atx-replace-setext-1
()
582 "Test ATX header insertion when replacing an existing setext header."
583 (markdown-test-string "replace\n=======\n"
584 (markdown-insert-header-atx-2)
585 (should (string-equal (buffer-string) "## replace ##\n\n"))
586 (should (looking-at " ##\n"))))
588 (ert-deftest test-markdown-insertion
/atx-replace-setext-2
()
589 "Test ATX header insertion when replacing an existing setext header."
590 (markdown-test-string "replace\n-------\n"
591 (markdown-insert-header-atx-5)
592 (should (string-equal (buffer-string) "##### replace #####\n\n"))
593 (should (looking-at " #####\n"))))
595 (ert-deftest test-markdown-insertion
/atx-asymmetric-point
()
596 "Test point after ATX header insertion with `markdown-asymmetric-header'."
597 (markdown-test-string
599 (let ((markdown-asymmetric-header t
))
600 (markdown-insert-header-atx-5)
601 (should (= (point) 11))
602 (should (string-equal (buffer-string) "##### Test")))))
604 (ert-deftest test-markdown-insertion
/setext-line
()
605 "Test setext header insertion without region."
606 (markdown-test-string "line one\nline two\n"
608 (markdown-insert-header-setext-1)
609 (should (string-equal (buffer-substring (point-min) (point-max))
610 "line one\n========\n\nline two\n"))
612 (markdown-insert-header-setext-2)
613 (should (string-equal (buffer-substring (point-min) (point-max))
614 "line one\n========\n\nline two\n--------\n\n"))))
616 (ert-deftest test-markdown-insertion
/setext-region
()
617 "Test setext header insertion with region."
618 (markdown-test-string "line one\nline two\n"
619 (transient-mark-mode)
621 (push-mark (point) t t
)
623 (should (string-equal (buffer-substring (region-beginning) (region-end))
625 (markdown-insert-header-setext-1)
626 (should (string-equal (buffer-substring (point-min) (point-max))
627 "line \n\none\n===\n\nline two\n"))))
629 (ert-deftest test-markdown-insertion
/setext-blank
()
630 "Test setext header insertion on blank line."
631 (markdown-test-string "line one\n\nline two\n"
633 (markdown-insert-header 2 "foo" t
)
634 (should (string-equal (buffer-substring (point-min) (point-max))
635 "line one\n\nfoo\n---\n\nline two\n"))
636 (should (= (point) 14))
637 (should (looking-at "\n---"))))
639 (ert-deftest test-markdown-insertion
/setext-region-whitespace
()
640 "Test setext header insertion using a region with whitespace."
641 (markdown-test-string " line one\n\nline two\n \n"
642 (transient-mark-mode)
643 (push-mark (point) t t
)
644 (goto-char (point-max))
645 (markdown-insert-header-setext-1)
646 (should (string-equal (buffer-substring (point-min) (point-max))
647 "line one line two\n================="))
648 (should (= (point) 18))
649 (should (looking-at "\n===="))))
651 (ert-deftest test-markdown-insertion
/setext-line-whitespace
()
652 "Test setext header insertion using current line with whitespace."
653 (markdown-test-string " line one \n\nline two\n"
654 (goto-char (line-end-position))
655 (markdown-insert-header-setext-2)
656 (should (string-equal (buffer-substring (point-min) (point-max))
657 "line one\n--------\n\nline two\n"))
658 (should (= (point) 9))
659 (should (looking-at "\n---"))))
661 (ert-deftest test-markdown-insertion
/setext-replace-atx
()
662 "Test setext header insertion when replacing an existing ATX header."
663 (markdown-test-string "## replace ##\n"
664 (markdown-insert-header-setext-1)
665 (should (string-equal (buffer-string) "replace\n=======\n\n"))
666 (should (looking-at "\n==="))))
668 (ert-deftest test-markdown-insertion
/setext-replace-setext-1
()
669 "Test setext header insertion when replacing an existing setext title."
670 (markdown-test-string "replace\n=======\n"
671 (markdown-insert-header-setext-2)
672 (should (string-equal (buffer-string) "replace\n-------\n\n"))
673 (should (looking-at "\n---"))))
675 (ert-deftest test-markdown-insertion
/setext-replace-setext-2
()
676 "Test setext header insertion when replacing an existing setext section."
677 (markdown-test-string "replace\n-------\n"
678 (markdown-insert-header-setext-1)
679 (should (string-equal (buffer-string) "replace\n=======\n\n"))
680 (should (looking-at "\n==="))))
682 (ert-deftest test-markdown-insertion
/header-dwim
()
683 "Test 'do what I mean' header insertion."
684 (markdown-test-file "outline.text"
685 (call-interactively 'markdown-insert-header-dwim
)
686 (should (looking-at " #$"))
688 (call-interactively 'markdown-insert-header-dwim
)
690 (should (looking-at "^# #$"))
692 (call-interactively 'markdown-insert-header-dwim
)
694 (should (looking-at "^### ###$"))))
696 (ert-deftest test-markdown-insertion
/header-dwim-prefix
()
697 "Test 'do what I mean' header insertion with prefix arguments."
698 (let ((tests (list '(nil .
"## abc ##")
702 '(4 .
"#### abc ####")
703 '(5 .
"##### abc #####")
704 '(6 .
"###### abc ######")
706 '((16) .
"### abc ###"))))
708 (markdown-test-string "## atx\n\nabc"
709 (goto-char (point-max))
710 (let ((current-prefix-arg (car test
)))
711 (call-interactively 'markdown-insert-header-dwim
)
712 (should (string-equal
713 (buffer-substring (line-beginning-position) (line-end-position))
716 (ert-deftest test-markdown-insertion
/header-setext-dwim-prefix
()
717 "Test 'do what I mean' header insertion with prefix arguments."
718 (let ((tests (list '(nil .
"abc\n---")
722 '(4 .
"#### abc ####")
723 '(5 .
"##### abc #####")
724 '(6 .
"###### abc ######")
726 '((16) .
"### abc ###"))))
728 (markdown-test-string "atx\n---\n\nabc"
729 (goto-char (point-max))
730 (let ((current-prefix-arg (car test
)))
731 (call-interactively 'markdown-insert-header-setext-dwim
)
732 (should (string-equal
733 (buffer-substring (line-beginning-position) (line-end-position 2))
736 (ert-deftest test-markdown-insertion
/header-setext-dwim
()
737 "Test 'do what I mean' header insertion with setext headers."
738 (markdown-test-string
739 "asdfasfasfdsadfasdfasdf\n======="
741 (call-interactively 'markdown-insert-header-dwim
)
742 (should (string-equal
744 "asdfasfasfdsadfasdfasdf\n======================="))))
746 (ert-deftest test-markdown-insertion
/remove-header
()
747 "Test ATX and setext header."
748 (markdown-test-string
749 "# atx1\n\n## atx2 ##\n\nsetext1\n=======\n\nsetext2\n-------\n"
750 (should (equal (markdown-remove-header) (cons 1 5)))
752 (should (not (markdown-remove-header)))
754 (should (equal (markdown-remove-header) (cons 7 11)))
756 (should (not (markdown-remove-header)))
758 (should (equal (markdown-remove-header) (cons 13 20)))
760 (should (not (markdown-remove-header)))
762 (should (equal (markdown-remove-header) (cons 22 29)))
763 (should (string-equal (buffer-string)
764 "atx1\n\natx2\n\nsetext1\n\nsetext2\n"))))
766 (ert-deftest test-markdown-insertion
/italic-unwrap-region
()
767 "A test of inserting italics with italic text in the region."
768 (markdown-test-string "*foo* bar *baz*"
769 (transient-mark-mode)
770 (push-mark (point) t t
)
772 (markdown-insert-italic)
773 (should (string-equal (buffer-string) "*foo bar baz*"))))
775 (ert-deftest test-markdown-insertion
/bold-unwrap-region
()
776 "A test of inserting bold with italic text in the region."
777 (markdown-test-string "*foo* **bar** *baz*"
778 (transient-mark-mode)
779 (push-mark (point) t t
)
781 (markdown-insert-bold)
782 (should (string-equal (buffer-string) "***foo* bar *baz***"))))
784 (ert-deftest test-markdown-insertion
/code-unwrap-region
()
785 "A test of inserting code with code already in the region."
786 (markdown-test-string "`foo` *bar* `baz`"
787 (transient-mark-mode)
788 (push-mark (point) t t
)
790 (markdown-insert-code)
791 (should (string-equal (buffer-string) "`foo *bar* baz`"))))
793 (ert-deftest test-markdown-insertion
/hr-order
()
794 "Test inserting horizontal rules."
795 (dotimes (n (length markdown-hr-strings
))
796 (markdown-test-string ""
797 (let ((current-prefix-arg n
))
798 (call-interactively 'markdown-insert-hr
))
799 (should (string-equal (buffer-string) (nth (1- n
) markdown-hr-strings
))))))
801 (ert-deftest test-markdown-insertion
/hr-prefix
()
802 "Test inserting horizontal rule with C-u prefix."
803 (markdown-test-string ""
804 (let ((current-prefix-arg '(4)))
805 (call-interactively 'markdown-insert-hr
))
806 (should (string-equal (buffer-string) (car (last markdown-hr-strings
))))))
808 (ert-deftest test-markdown-insertion
/hr-bob
()
809 "Test inserting horizontal rule at beginning of buffer."
810 (markdown-test-string "one line\n"
811 (call-interactively 'markdown-insert-hr
)
812 (should (string-equal (buffer-string)
813 (concat (car markdown-hr-strings
)
814 "\n\none line\n")))))
816 (ert-deftest test-markdown-insertion
/hr-eob
()
817 "Test inserting horizontal rule at end of buffer."
818 (markdown-test-string "one line\n"
820 (call-interactively 'markdown-insert-hr
)
821 (should (string-equal (buffer-string)
822 (concat "one line\n\n" (car markdown-hr-strings
))))))
824 (ert-deftest test-markdown-insertion
/hr-mob
()
825 "Test inserting horizontal rule in middle of buffer."
826 (markdown-test-string "one line\n"
828 (let ((markdown-hr-strings '("----------")))
829 (call-interactively 'markdown-insert-hr
)
830 (should (string-equal (buffer-string)
831 (concat "one\n\n" (car markdown-hr-strings
)
834 (ert-deftest test-markdown-insertion
/pre-region-1
()
835 "Test `markdown-pre-region'."
836 ;; Simple test as non-interactive command
837 (markdown-test-string "line one\nline two\n"
838 (markdown-pre-region (line-beginning-position) (line-end-position))
839 (should (string-equal (buffer-string) " line one\n\nline two\n")))
840 ;; Test removal of whitespace before and after region
841 (markdown-test-string "line one abc\nline two\n"
842 (markdown-pre-region 6 9)
843 (should (string-equal (buffer-string) "line\n\n one\n\nabc\nline two\n")))
844 ;; Simple test as interactive command
845 (markdown-test-string "line one\nline two\n"
846 (push-mark (point) t t
)
848 (call-interactively 'markdown-pre-region
)
849 (should (string-equal (buffer-string) " line one\n line two\n\n"))))
851 (ert-deftest test-markdown-insertion
/blockquote-region-1
()
852 "Test `markdown-blockquote-region'."
853 ;; Simple test as non-interactive command
854 (markdown-test-string "line one\nline two\n"
855 (markdown-blockquote-region (line-beginning-position) (line-end-position))
856 (should (string-equal (buffer-string) "> line one\n\nline two\n")))
857 ;; Test removal of whitespace before and after region
858 (markdown-test-string "line one abc\nline two\n"
859 (markdown-blockquote-region 6 9)
860 (should (string-equal (buffer-string) "line\n\n> one\n\nabc\nline two\n")))
861 ;; Simple test as interactive command
862 (markdown-test-string "line one\nline two\n"
863 (push-mark (point) t t
)
865 (call-interactively 'markdown-blockquote-region
)
866 (should (string-equal (buffer-string) "> line one\n> line two\n\n"))))
868 (ert-deftest test-markdown-insertion
/pre-nested-lists
()
869 "Test `markdown-pre-indentation' and `markdown-insert-pre' with nested list."
870 (markdown-test-string "* item\n * item\n"
871 ;; before the first item
872 (should (string-equal (markdown-pre-indentation (point)) " "))
873 (markdown-insert-pre)
875 (should (markdown-prev-line-blank-p))
876 (should (looking-at "^ $"))
877 (should (markdown-next-line-blank-p))
878 ;; before the second item
880 (should (string-equal (markdown-pre-indentation (point)) " "))
881 (markdown-insert-pre)
883 (should (markdown-prev-line-blank-p))
884 (should (looking-at "^ $"))
885 (should (markdown-next-line-blank-p))
886 ;; after the second item
888 (should (string-equal (markdown-pre-indentation (point)) " "))
889 (markdown-insert-pre)
891 (should (markdown-prev-line-blank-p))
892 (should (looking-at "^ $"))
893 (should (markdown-next-line-blank-p))))
895 (ert-deftest test-markdown-insertion
/pre-faux-list
()
896 "Test `markdown-pre-indentation' following a list-marker in a pre block."
897 (markdown-test-string " * pre block, not a list item\n"
898 (should (string-equal (markdown-pre-indentation (point-max)) " "))))
900 (ert-deftest test-markdown-insertion
/blockquote-nested-lists
()
901 "Test blockquote insertion in a nested list context."
902 (markdown-test-string "* item\n * item\n"
903 ;; before the first item
904 (should (string-equal (markdown-blockquote-indentation (point)) ""))
905 (markdown-insert-blockquote)
907 (should (markdown-prev-line-blank-p))
908 (should (looking-at "^> $"))
909 (should (markdown-next-line-blank-p))
910 ;; before the second item
912 (should (string-equal (markdown-blockquote-indentation (point)) " "))
913 (markdown-insert-blockquote)
915 (should (markdown-prev-line-blank-p))
916 (should (looking-at "^ > $"))
917 (should (markdown-next-line-blank-p))
918 ;; after the second item
920 (should (string-equal (markdown-blockquote-indentation (point)) " "))
921 (markdown-insert-blockquote)
923 (should (markdown-prev-line-blank-p))
924 (should (looking-at "^ > $"))
925 (should (markdown-next-line-blank-p))))
927 (ert-deftest test-markdown-insertion
/empty-italic
()
928 "Test `markdown-insert-italic' with no word at point and no region."
929 (markdown-test-string ""
930 (call-interactively 'markdown-insert-italic
)
931 (should (string-equal (buffer-string) "**"))
932 (should (= (point) 2))))
934 (ert-deftest test-markdown-insertion
/empty-bold
()
935 "Test `markdown-insert-bold' with no word at point and no region."
936 (markdown-test-string ""
937 (call-interactively 'markdown-insert-bold
)
938 (should (string-equal (buffer-string) "****"))
939 (should (= (point) 3))))
941 (ert-deftest test-markdown-insertion
/uri
()
942 "Test `markdown-insert-uri'."
943 (markdown-test-string "http://jblevins.org/projects/markdown-mode/"
944 (call-interactively 'markdown-insert-uri
)
945 (should (string-equal (buffer-string) "<http://jblevins.org/projects/markdown-mode/>"))
946 (should (= (point) 2))
947 (call-interactively 'markdown-insert-uri
)
948 (should (string-equal (buffer-string) "http://jblevins.org/projects/markdown-mode/"))
949 (should (= (point) 1))
951 (call-interactively 'markdown-insert-uri
)
952 (should (string-equal (buffer-string) "<>"))
953 (should (= (point) 2))))
955 (ert-deftest test-markdown-insertion
/list-item
()
956 "Test `markdown-insert-list-item' on several lists."
958 (markdown-test-string "abc"
959 (goto-char (point-max))
960 (call-interactively 'markdown-insert-list-item
)
961 (should (string-equal (buffer-string) "abc\n * "))
962 (should (= (point) 9)))
963 ;; Following a list item, on the same line
964 (markdown-test-string " * foo"
965 (goto-char (point-max))
966 (call-interactively 'markdown-insert-list-item
)
967 (should (string-equal (buffer-string) " * foo\n * ")))
968 ;; Following a list item, on the next line
969 (markdown-test-string "- foo\n"
970 (goto-char (point-max))
971 (call-interactively 'markdown-insert-list-item
)
972 (should (string-equal (buffer-string) "- foo\n- ")))
973 ;; Following a list item, after a blank line
974 (markdown-test-string "- foo\n\n"
975 (goto-char (point-max))
976 (call-interactively 'markdown-insert-list-item
)
977 (should (string-equal (buffer-string) "- foo\n\n- ")))
978 ;; Preceding a list item
979 (markdown-test-string "- foo\n"
980 (goto-char (point-min))
981 (call-interactively 'markdown-insert-list-item
)
982 (should (string-equal (buffer-string) "- \n- foo\n")))
983 ;; Preceding a list item and a blank line
984 (markdown-test-string "\n\n- foo\n"
985 (goto-char (point-min))
986 (call-interactively 'markdown-insert-list-item
)
987 (should (string-equal (buffer-string) "- \n\n- foo\n")))
988 ;; In the middle of a list item
989 (markdown-test-string "- foo bar\n"
991 (call-interactively 'markdown-insert-list-item
)
992 (should (string-equal (buffer-string) "- foo\n- bar\n")))
993 ;; Before a list marker, but not at beginning of line
994 (markdown-test-string " - foo\n"
996 (call-interactively 'markdown-insert-list-item
)
997 (should (string-equal (buffer-string) " - \n - foo\n")))
998 ;; Following an ordered list item
999 (markdown-test-string "6. foo"
1000 (goto-char (point-max))
1001 (call-interactively 'markdown-insert-list-item
)
1002 (should (string-equal (buffer-string) "6. foo\n7. ")))
1003 ;; Following a fancy list item, on the next line
1004 (markdown-test-string "#. foo"
1005 (goto-char (point-max))
1006 (call-interactively 'markdown-insert-list-item
)
1007 (should (string-equal (buffer-string) "#. foo\n#. ")))
1008 ;; Following a nested ordered list item
1009 (markdown-test-string "6. foo\n 1. bar"
1010 (goto-char (point-max))
1011 (call-interactively 'markdown-insert-list-item
)
1012 (should (string-equal (buffer-string) "6. foo\n 1. bar\n 2. ")))
1013 ;; Preceding an ordered list item
1014 (markdown-test-string "\n1. foo\n2. bar"
1015 (goto-char (point-min))
1016 (call-interactively 'markdown-insert-list-item
)
1017 (should (string-equal (buffer-string) "1. \n1. foo\n2. bar")))
1018 ;; Preserve previous spacing in ordered list
1019 (markdown-test-string "1. foo"
1020 (goto-char (point-max))
1021 (call-interactively 'markdown-insert-list-item
)
1022 (should (string-equal (buffer-string) "1. foo\n2. ")))
1023 ;; Adjust spacing for number width changes (e.g., 9 -> 10)
1024 (markdown-test-string "9. foo"
1025 (goto-char (point-max))
1026 (call-interactively 'markdown-insert-list-item
)
1027 (should (string-equal (buffer-string) "9. foo\n10. ")))
1028 ;; Don't adjust spacing for number width changes if no extra whitespace
1029 (markdown-test-string "99. foo"
1030 (goto-char (point-max))
1031 (call-interactively 'markdown-insert-list-item
)
1032 (should (string-equal (buffer-string) "99. foo\n100. ")))
1033 ;; Don't adjust spacing if tabs are used as whitespace
1034 (markdown-test-string "9.\tfoo"
1035 (goto-char (point-max))
1036 (call-interactively 'markdown-insert-list-item
)
1037 (should (string-equal (buffer-string) "9.\tfoo\n10.\t"))))
1039 (ert-deftest test-markdown-insertion
/nested-list-marker
()
1040 "Test marker detection for `markdown-insert-list-item'."
1041 (markdown-test-string
1042 "1. A\n * AA\n 1. AAA"
1043 (goto-char (point-max))
1044 (let ((current-prefix-arg '(4)))
1045 (call-interactively 'markdown-insert-list-item
))
1046 (should (eq (point) 36))
1047 (should (looking-back "\* "))
1048 (should (string-equal
1050 "1. A\n * AA\n 1. AAA\n * "))
1051 (let ((current-prefix-arg '(4)))
1052 (call-interactively 'markdown-insert-list-item
))
1053 (should (eq (point) 40))
1054 (should (looking-back "2\. "))
1055 (should (string-equal
1057 "1. A\n * AA\n 1. AAA\n * \n2. "))
1058 (let ((current-prefix-arg '(4)))
1059 (call-interactively 'markdown-insert-list-item
))
1060 (should (eq (point) 44))
1061 (should (looking-back "3\. "))
1062 (should (string-equal
1064 "1. A\n * AA\n 1. AAA\n * \n2. \n3. "))))
1066 (ert-deftest test-markdown-insertion
/reference-link
()
1067 "Basic tests for `markdown-insert-reference-link'."
1068 ;; Test optional parameters (leave point after link)
1069 (markdown-test-string ""
1070 (markdown-insert-reference-link "abc" "1")
1071 (should (string-equal (buffer-string) "[abc][1]"))
1072 (should (= (point) 9)))
1073 ;; Full link without title (leave point after link)
1074 (markdown-test-string ""
1075 (markdown-insert-reference-link "link" "label" "http://jblevins.org/")
1076 (should (string-equal (buffer-string) "[link][label]\n\n[label]: http://jblevins.org/\n"))
1077 (should (= (point) 14)))
1078 ;; Full link without label or title (leave point after link)
1079 (markdown-test-string ""
1080 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
1081 (should (string-equal (buffer-string) "[link][]\n\n[link]: http://jblevins.org/\n"))
1082 (should (= (point) 9)))
1083 ;; Link only with no label, URL, or title (leave point after link)
1084 (markdown-test-string ""
1085 (markdown-insert-reference-link "link" "")
1086 (should (string-equal (buffer-string) "[link][]"))
1087 (should (= (point) 9))))
1089 (ert-deftest test-markdown-insertion
/reference-link-end
()
1090 "Basic reference link insertion test for 'end location."
1091 (let ((markdown-reference-location 'end
))
1092 (markdown-test-string "first para\n\nsecond para\n"
1094 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
1095 (should (= (point) 19))
1096 (goto-char (point-min))
1098 (should (looking-at "\\[link\\]: http://jblevins.org/")))))
1100 (ert-deftest test-markdown-insertion
/reference-link-immediately
()
1101 "Basic reference link insertion test for 'immediately location."
1102 (let ((markdown-reference-location 'immediately
))
1103 (markdown-test-string "first para\n\nsecond para\n"
1105 (markdown-insert-reference-link "link" "" "http://jblevins.org/")
1106 (should (= (point) 19))
1107 (goto-char (point-min))
1109 (should (looking-at "\\[link\\]: http://jblevins.org/")))))
1111 (ert-deftest test-markdown-insertion
/reference-link-header
()
1112 "Basic reference link and definition insertion test for 'header location."
1113 (let ((markdown-reference-location 'header
))
1114 (markdown-test-string "par one\n\npar two\n\n### header\n"
1116 (markdown-insert-reference-link "link" "")
1117 (markdown-insert-reference-definition "link")
1118 (should (= (point) 35))
1119 (should (looking-back "\\[link\\]: " nil
)))))
1121 (ert-deftest test-markdown-insertion
/inline-to-reference-link
()
1122 "Inline link to reference link conversion."
1123 (markdown-test-string "[text](http://jblevins.org/ \"title\")"
1124 (execute-kbd-macro (read-kbd-macro "M-x markdown-insert-reference-link-dwim RET 1 RET"))
1125 (should (string-equal (buffer-string) "[text][1]\n\n[1]: http://jblevins.org/ \"title\"\n")))
1126 (markdown-test-string "[text](http://jblevins.org/)"
1127 (execute-kbd-macro (read-kbd-macro "M-x markdown-insert-reference-link-dwim RET 1 RET"))
1128 (should (string-equal (buffer-string) "[text][1]\n\n[1]: http://jblevins.org/\n"))))
1130 (ert-deftest test-markdown-insertion
/inline-to-reference-link-2
()
1131 "Inline link to reference link conversion with existing reference links.
1132 Regression test: adding a new reference link with
1133 `markdown-insert-reference-link-dwim' should not throw an 'args
1134 out of range' error when the existing reference label is a single
1136 (markdown-test-string "[text](http://jblevins.org/ \"title\")\n\n[1]: https://www.gnu.org"
1137 (execute-kbd-macro (read-kbd-macro "M-x markdown-insert-reference-link-dwim RET 2 RET"))))
1139 (ert-deftest test-markdown-insertion
/inline-link-empty
()
1140 "Test `markdown-insert-inline-link-dwim' for empty markup insertion.
1141 Point should be left inside square brackets."
1142 (markdown-test-string "abc "
1144 (call-interactively 'markdown-insert-inline-link-dwim
)
1145 (should (string-equal (buffer-string) "abc []()"))
1146 (should (= (point) 6))))
1148 (ert-deftest test-markdown-insertion
/inline-link-word-at-point
()
1149 "Test `markdown-insert-inline-link-dwim' with word at point.
1150 Point should be left inside parentheses."
1151 (markdown-test-string "abc def ghi"
1153 (call-interactively 'markdown-insert-inline-link-dwim
)
1154 (should (string-equal (buffer-string) "abc [def]() ghi"))
1155 (should (= (point) 11))))
1157 (ert-deftest test-markdown-insertion
/inline-link-angle-url-at-point
()
1158 "Test `markdown-insert-inline-link-dwim' with angle URL at point.
1159 Point should be left inside square brackets."
1160 (markdown-test-string "<https://www.gnu.org/>"
1162 (call-interactively 'markdown-insert-inline-link-dwim
)
1163 (should (string-equal (buffer-string) "[](https://www.gnu.org/)"))
1164 (should (= (point) 2))))
1166 (ert-deftest test-markdown-insertion
/inline-link-plain-url-at-point
()
1167 "Test `markdown-insert-inline-link-dwim' with plain URL at point.
1168 Point should be left inside square brackets."
1169 (markdown-test-string "https://www.gnu.org/"
1171 (call-interactively 'markdown-insert-inline-link-dwim
)
1172 (should (string-equal (buffer-string) "[](https://www.gnu.org/)"))
1173 (should (= (point) 2))))
1175 (ert-deftest test-markdown-insertion
/inline-link-reference-link-at-point
()
1176 "Test `markdown-insert-inline-link-dwim' with reference link at point."
1177 (markdown-test-string ""
1178 (markdown-insert-reference-link "link" "label" "http://jblevins.org/")
1179 (call-interactively 'markdown-insert-inline-link-dwim
)
1180 (should (string-equal (buffer-substring 1 29) "[link](http://jblevins.org/)"))
1181 (should (= (point) 29))))
1183 (ert-deftest test-markdown-insertion
/inline-link-active-region
()
1184 "Test `markdown-insert-inline-link-dwim' with active region.
1185 Point should be left inside parentheses."
1186 (markdown-test-string "abc def ghi"
1187 (let ((tmm-orig transient-mark-mode
))
1188 (transient-mark-mode 1)
1189 (push-mark (point) t t
)
1191 (call-interactively 'markdown-insert-inline-link-dwim
)
1192 (should (string-equal (buffer-string) "[abc def]() ghi"))
1193 (should (= (point) 11))
1194 (transient-mark-mode tmm-orig
))))
1198 (ert-deftest test-markdown-footnote
/basic-end
()
1199 "Basic footnote insertion and deletion tests for 'end location."
1200 (let ((markdown-footnote-location 'end
))
1201 (markdown-test-string "first line\nsecond line\n"
1202 ;; new buffer with no footnotes
1203 (should (= markdown-footnote-counter
0))
1204 ;; footnote insertion
1206 (markdown-insert-footnote)
1207 (should (= (point) 35))
1208 (should (= markdown-footnote-counter
1))
1209 (should (looking-back "\\[^1\\]: " nil
))
1210 ;; kill with point in footnote definition
1211 (insert "footnote text")
1213 (markdown-footnote-kill))
1214 (should (= (point) 24))
1216 (should (string-equal (buffer-string) "first line\nsecond line\n"))
1217 ;; insertion, counter should increment
1218 (goto-char (point-min))
1220 (markdown-insert-footnote)
1221 (should (= (point) 35))
1222 (should (= markdown-footnote-counter
2))
1223 (should (looking-back "\\[^2\\]: " nil
))
1224 (insert "footnote text")
1226 (markdown-footnote-return)
1227 (should (= (point) 15))
1228 (should (looking-back "\\[^2\\]" nil
))
1229 ;; kill with point at marker
1231 (markdown-footnote-kill))
1232 (should (= (point) 11))
1234 (should (string-equal (buffer-string) "first line\nsecond line\n")))))
1236 (ert-deftest test-markdown-footnote
/basic-immediately
()
1237 "Basic footnote insertion and deletion tests for 'immediately location."
1238 (let ((markdown-footnote-location 'immediately
))
1239 (markdown-test-string "first paragraph\n\nsecond paragraph\n"
1240 ;; new buffer with no footnotes
1241 (should (= markdown-footnote-counter
0))
1242 ;; footnote insertion
1244 (markdown-insert-footnote)
1245 (should (= (point) 28))
1246 (should (= markdown-footnote-counter
1))
1247 (should (looking-back "\\[^1\\]: " nil
))
1248 ;; kill with point in footnote definition
1249 (insert "footnote text")
1251 (markdown-footnote-kill))
1252 (should (= (point) 18))
1254 (should (string-equal (buffer-string)
1255 "first paragraph\n\nsecond paragraph\n")))))
1257 (ert-deftest test-markdown-footnote
/basic-header
()
1258 "Basic footnote insertion and deletion tests for 'header location."
1259 (let ((markdown-footnote-location 'header
))
1260 (markdown-test-string "par one\n\npar two\n\n### header\n"
1261 ;; new buffer with no footnotes
1262 (should (= markdown-footnote-counter
0))
1263 ;; footnote insertion
1265 (markdown-insert-footnote)
1266 (should (= (point) 29))
1267 (should (= markdown-footnote-counter
1))
1268 (should (looking-back "\\[^1\\]: " nil
))
1269 ;; kill with point in footnote definition
1270 (insert "footnote text")
1272 (markdown-footnote-kill))
1273 (should (= (point) 19))
1275 (should (string-equal (buffer-string)
1276 "par one\n\npar two\n\n### header\n"))
1277 ;; insertion, counter should increment
1278 (goto-char (point-min))
1280 (markdown-insert-footnote)
1281 (should (= (point) 29))
1282 (should (= markdown-footnote-counter
2))
1283 (should (looking-back "\\[^2\\]: " nil
))
1284 (insert "footnote text")
1286 (markdown-footnote-return)
1287 (should (= (point) 12))
1288 (should (looking-back "\\[^2\\]" nil
))
1289 ;; kill with point at marker
1291 (markdown-footnote-kill))
1292 (should (= (point) 8))
1294 (should (string-equal (buffer-string)
1295 "par one\n\npar two\n\n### header\n")))))
1297 (ert-deftest test-markdown-footnote
/kill-empty-text
()
1298 "Test killing a footnote with marker but no text."
1299 (markdown-test-string "no text[^1]\n\n[^1]: \n"
1301 (markdown-footnote-goto-text)
1302 (should (looking-back "\\[^1\\]: " nil
))
1304 (markdown-footnote-kill))
1305 (should (string-equal (buffer-string) "no text\n"))))
1307 (ert-deftest test-markdown-footnote
/kill-empty-after
()
1308 "Test killing an empty footnote after one with text (previously killed the
1309 footnote with text above)."
1310 (markdown-test-string "[^with-text][^no-text]\n\n[^with-text]: Text\n[^no-text]:"
1313 (should (looking-at "\\[\\^no-text\\]:$"))
1314 (markdown-footnote-kill)
1315 (should (string-equal (current-kill 0) "")))))
1317 (ert-deftest test-markdown-footnote
/kill-hanging-paras
()
1318 "Test killing a footnote where block text starts after the label (previously
1319 killed the footnote above)."
1320 (markdown-test-string "[^1][^2]\n\n[^1]: Foo\n\n[^2]:\n Text\n\n More text\n\n\nNot indented"
1323 (should (looking-at "\\[\\^2\\]:$"))
1324 (markdown-footnote-kill)
1325 ;; We want to include the leading space on hanging footnote paragraphs,
1326 ;; even if a hanging paragraph is the first item in the footnote.
1327 (should (string-equal (current-kill 0) "Text\n\n More text\n")))))
1329 (ert-deftest test-markdown-footnote
/text-positions-buffer-top
()
1330 "Test markdown-footnote-text-positions on footnote adjacent to buffer top
1331 (was infinite loop)."
1332 (markdown-test-string "[^label]: text\n more text"
1333 (should (equal (markdown-footnote-text-positions) (list "^label" 1 29)))))
1335 (ert-deftest test-markdown-footnote
/text-positions-buffer-top-one-line
()
1336 "Test markdown-footnote-text-positions on one-line footnote adjacent to
1337 buffer top (failed to find positions)."
1338 (markdown-test-string "[^label]: text\n"
1339 (should (equal (markdown-footnote-text-positions) (list "^label" 1 16)))))
1341 (ert-deftest test-markdown-footnote
/text-positions-buffer-top-not-footnote
()
1342 "Test markdown-footnote-text-positions on plain paragraph adjacent to buffer
1343 top (was infinite loop)."
1344 (markdown-test-string "text\n more text\n"
1345 (should (eq (markdown-footnote-text-positions) nil
))))
1347 (ert-deftest test-markdown-footnote
/text-positions-buffer-bottom
()
1348 "Test markdown-footnote-text-positions on footnote adjacent to buffer bottom
1349 (was infinite loop)."
1350 (markdown-test-string "\n[^label]: text\n more text"
1352 (should (equal (markdown-footnote-text-positions) (list "^label" 2 30)))))
1354 (ert-deftest test-markdown-footnote
/kill-adjacent-footnote
()
1355 "Test killing a footnote adjacent to other one-line footnotes (previously
1356 killed the wrong one)."
1357 (markdown-test-string "Text[^1] with[^2] footnotes[^3]\n\n[^1]: foo\n[^2]: bar\n[^3]: baz"
1360 (should (looking-at "\\[\\^2\\]: bar"))
1361 (markdown-footnote-kill)
1362 (should (string-equal (current-kill 0) "bar\n")))))
1364 (ert-deftest test-markdown-footnote
/kill-adjacent-markers
()
1365 "Test killing a footnote where the labels are adjacent (previously, the wrong
1366 footnote would be killed because the attempt to jump to the marker would jump to
1367 the opening bracket of [^2], and then subsequent functions would kill [^2])."
1368 (markdown-test-string "Text with footnotes[^1][^2]\n\n[^1]: foo\n\n[^2]: bar\n"
1371 (should (looking-at "\\[\\^1\\]: foo"))
1372 (markdown-footnote-kill)
1373 (should (string-equal (current-kill 0) "foo\n")))))
1375 (when (version< emacs-version
"24.2")
1376 ;; fix segfault on 24.1 with the normal implementation of this function. isn't
1377 ;; exactly correct, but should make tests work the same
1378 (defadvice kill-buffer-and-window
(around markdown-test-fix-segfault activate
)
1380 (select-window (previous-window))))
1382 (ert-deftest test-markdown-footnote-reference
/jump
()
1383 "Test `markdown-jump' for footnotes and reference links."
1384 (markdown-test-string
1385 "body[^1], [link 1][ref],
1390 [ref]: https://duckduckgo.com/"
1391 (goto-char 5) ; start of [^1]
1392 (markdown-jump) ; markdown-footnote-goto-text
1393 (should (looking-at "footnote"))
1394 (markdown-jump) ; markdown-footnote-return
1395 (should (= (point) 9)) ; just after [^1]
1396 (markdown-next-link) ; beginning of [link 1][]
1398 (should (looking-at "https://duckduckgo.com/"))
1399 (should (equal (markdown-reference-find-links "ref")
1400 (list (list "link 2" 26 2) (list "link 1" 11 1))))
1401 (markdown-jump) ; opens a reference link buffer
1402 (should (string= (buffer-string) "Links using reference ref:\n\nlink 1 (line 1)\nlink 2 (line 2)\n"))
1403 (should (looking-at "link 1")) ; in reference link popop buffer
1404 (execute-kbd-macro (read-kbd-macro "RET")) ; jump to "link 1"
1405 (should (looking-at "\\[link 1\\]")) ; back in main buffer
1406 (should (= (point) 11))))
1408 ;;; Element removal tests:
1410 (ert-deftest test-markdown-kill
/simple
()
1411 "Simple tests for `markdown-kill-thing-at-point'."
1412 (let ((kill-ring nil
)
1413 (tests (list '("`foo`" .
"foo")
1414 '("## foo ##" .
"foo")
1416 '("foo\n---" .
"foo")
1417 '("foo\n===" .
"foo")
1418 '("* * * * *" .
"* * * * *")
1419 '("[foo](http://bar.com/)" .
"foo")
1420 '("![foo](http://bar.com/)" .
"foo")
1421 '("[foo][bar]" .
"foo")
1422 '("![foo][bar]" .
"foo")
1423 '("<http://foo.com/>" .
"http://foo.com/")
1424 '("<foo@bar.com>" .
"foo@bar.com")
1425 '("**foo**" .
"foo")
1426 '("__foo__" .
"foo")
1429 '(" [foo]: http://bar.com/" .
"http://bar.com/")
1430 '(" [foo]: http://bar.com/ \"title\"" .
"http://bar.com/")
1431 '("foo[^bar]\n\n[^bar]: baz" .
"baz")
1432 '("[^bar]: baz" .
"baz")
1433 '(" * foo\n bar" .
" * foo\n bar"))))
1434 (dolist (test tests
)
1435 ;; Load test string (the car), move to end of first line, kill
1436 ;; thing at point, and then verify that the kill ring contains cdr.
1437 (markdown-test-string (car test
)
1439 (call-interactively 'markdown-kill-thing-at-point
)
1440 (should (string-equal (current-kill 0) (cdr test
)))))))
1442 (ert-deftest test-markdown-kill
/footnote-text
()
1443 "Test killing a footnote with point at footnote text."
1444 (markdown-test-string "some text[^1]\n\n[^1]: footnote\n"
1446 (markdown-footnote-goto-text)
1448 (markdown-footnote-kill))
1449 (should (string-equal (buffer-string) "some text\n"))))
1451 (ert-deftest test-markdown-kill
/code
()
1452 "Test killing with code regex.."
1453 (let ((kill-ring nil
))
1454 (markdown-test-string "Lorem `ipsum` dolor `sit` `amet`."
1455 (goto-char 22) ; position point at s in `sit`
1456 (call-interactively 'markdown-kill-thing-at-point
)
1457 (should (string-equal (current-kill 0) "sit")))))
1461 (ert-deftest test-markdown-complete
/atx-header-incomplete
()
1462 "Test `markdown-incomplete-atx-p'."
1463 (markdown-test-string "### ###"
1464 (should (looking-at markdown-regex-header-atx
))
1465 (should-not (markdown-incomplete-atx-p)))
1466 (markdown-test-string "###abc###"
1467 (should-not (looking-at markdown-regex-header-atx
)))
1468 (markdown-test-string "### ###"
1469 (should (looking-at markdown-regex-header-atx
))
1470 (should (markdown-incomplete-atx-p))))
1472 (ert-deftest test-markdown-complete
/atx-header
()
1473 "Test `markdown-complete' for atx headers."
1474 (markdown-test-string "##### test"
1475 (call-interactively 'markdown-complete
)
1476 (should (string-equal (buffer-string) "##### test #####"))))
1478 (ert-deftest test-markdown-complete
/setext-header-incomplete
()
1479 "Test `markdown-incomplete-setext-p'."
1480 (markdown-test-string "abc\n===\n"
1481 (should (looking-at markdown-regex-header-setext
))
1482 (should-not (markdown-incomplete-setext-p)))
1483 (markdown-test-string "abc\n==\n"
1484 (should (looking-at markdown-regex-header-setext
))
1485 (should (markdown-incomplete-setext-p)))
1486 (markdown-test-string "abc\n====\n"
1487 (should (looking-at markdown-regex-header-setext
))
1488 (should (markdown-incomplete-setext-p))))
1490 (ert-deftest test-markdown-complete
/setext-header
()
1491 "Test `markdown-complete' for setext headers."
1492 (markdown-test-string "test \n=="
1493 (call-interactively 'markdown-complete
)
1494 (should (string-equal (buffer-string) "test\n===="))))
1496 (ert-deftest test-markdown-complete
/hr-incomplete
()
1497 "Test `markdown-incomplete-hr-p'."
1498 (dolist (i (number-sequence 0 (1- (length markdown-hr-strings
))))
1499 (markdown-test-string (nth i markdown-hr-strings
)
1500 (should (looking-at markdown-regex-hr
))
1501 (should-not (markdown-incomplete-hr-p))
1502 (should-error (call-interactively 'markdown-complete
)))))
1504 (ert-deftest test-markdown-complete
/hr
()
1505 "Test completion via `markdown-complete' for horizontal rules."
1506 (markdown-test-string "- - - - -"
1507 (call-interactively 'markdown-complete
)
1508 (should (string-equal (buffer-string) (car markdown-hr-strings
)))))
1510 (ert-deftest test-markdown-complete
/buffer-setext-2
()
1511 "Test `markdown-complete-buffer' for level two setext heading."
1512 ;; Ensure markdown-complete-buffer doesn't mistake this for a horizontal rule
1513 (markdown-test-string "Subheading\n--\n"
1514 (call-interactively 'markdown-complete-buffer
)
1515 (should (string-equal (buffer-string) "Subheading\n----------\n\n")))
1516 (markdown-test-string "Abc\n--\n\nDef\n--\n"
1517 (call-interactively 'markdown-complete-buffer
)
1518 (should (string-equal (buffer-string) "Abc\n---\n\nDef\n---\n\n"))))
1520 ;;; Promotion and demotion tests:
1522 (ert-deftest test-markdown-promote
/atx-header
()
1523 "Test `markdown-promote' for atx headers."
1524 (markdown-test-string "###### test ######"
1526 (should (string-equal (buffer-string) "##### test #####"))
1528 (should (string-equal (buffer-string) "#### test ####"))
1530 (should (string-equal (buffer-string) "### test ###"))
1532 (should (string-equal (buffer-string) "## test ##"))
1534 (should (string-equal (buffer-string) "# test #"))))
1536 (ert-deftest test-markdown-demote
/atx-header
()
1537 "Test `markdown-demote' for atx headers."
1538 (markdown-test-string "# test #"
1540 (should (string-equal (buffer-string) "## test ##"))
1542 (should (string-equal (buffer-string) "### test ###"))
1544 (should (string-equal (buffer-string) "#### test ####"))
1546 (should (string-equal (buffer-string) "##### test #####"))
1548 (should (string-equal (buffer-string) "###### test ######"))))
1550 (ert-deftest test-markdown-promote
/setext-header
()
1551 "Test `markdown-promote' for setext headers."
1552 (markdown-test-string "test\n----"
1554 (should (string-equal (buffer-string) "test\n===="))))
1556 (ert-deftest test-markdown-demote
/setext-header
()
1557 "Test `markdown-demote' for setext headers."
1558 (markdown-test-string "test\n===="
1560 (should (string-equal (buffer-string) "test\n----"))
1562 (should (string-equal (buffer-string) "### test ###"))
1564 (should (string-equal (buffer-string) "#### test ####"))
1566 (should (string-equal (buffer-string) "##### test #####"))
1568 (should (string-equal (buffer-string) "###### test ######"))))
1570 (ert-deftest test-markdown-promote
/hr
()
1571 "Test `markdown-promote' for horizontal rules."
1572 (markdown-test-string (car (reverse markdown-hr-strings
))
1573 (dolist (n (number-sequence 4 0 -
1))
1575 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))))
1577 (ert-deftest test-markdown-demote
/hr
()
1578 "Test `markdown-demote' for horizontal rules."
1579 (markdown-test-string (car markdown-hr-strings
)
1580 (dolist (n (number-sequence 1 5))
1582 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))))
1584 (ert-deftest test-markdown-promote
/bold
()
1585 "Test `markdown-promote' for bold markup."
1586 (markdown-test-string "__bold__"
1587 (call-interactively 'markdown-promote
)
1588 (should (string-equal (buffer-string) "**bold**"))))
1590 (ert-deftest test-markdown-demote
/bold
()
1591 "Test `markdown-demote' for bold markup."
1592 (markdown-test-string "**bold**"
1593 (call-interactively 'markdown-promote
)
1594 (should (string-equal (buffer-string) "__bold__"))))
1596 (ert-deftest test-markdown-promote
/italic
()
1597 "Test `markdown-promote' for italic markup."
1598 (markdown-test-string "_italic_"
1599 (call-interactively 'markdown-promote
)
1600 (should (string-equal (buffer-string) "*italic*"))))
1602 (ert-deftest test-markdown-demote
/italic
()
1603 "Test `markdown-demote' for italic markup."
1604 (markdown-test-string "*italic*"
1605 (call-interactively 'markdown-promote
)
1606 (should (string-equal (buffer-string) "_italic_"))))
1608 ;;; Subtree editing tests:
1610 (ert-deftest test-markdown-subtree
/promote
()
1611 "Test `markdown-promote-subtree'."
1612 (markdown-test-string "# h1 #\n\n## h2 ##\n\n### h3 ###\n\n## h2 ##\n\n# h1 #\n"
1613 ;; The first h1 should get promoted away.
1614 ;; The second h1 should not be promoted.
1615 (markdown-promote-subtree)
1616 (should (string-equal (buffer-string) "h1\n\n# h2 #\n\n## h3 ##\n\n# h2 #\n\n# h1 #\n"))
1617 ;; Second call should do nothing since point is no longer at a heading.
1618 (markdown-promote-subtree)
1619 (should (string-equal (buffer-string) "h1\n\n# h2 #\n\n## h3 ##\n\n# h2 #\n\n# h1 #\n"))
1620 ;; Move to h2 and promote again.
1622 (markdown-promote-subtree)
1623 (should (string-equal (buffer-string) "h1\n\nh2\n\n# h3 #\n\n# h2 #\n\n# h1 #\n"))))
1625 (ert-deftest test-markdown-subtree
/demote
()
1626 "Test `markdown-demote-subtree'."
1627 (markdown-test-string "# h1 #\n\n## h2 ##\n\n### h3 ###\n\n## h2 ##\n\n# h1 #\n"
1628 ;; The second h1 should not be demoted
1629 (markdown-demote-subtree)
1630 (should (string-equal (buffer-string) "## h1 ##\n\n### h2 ###\n\n#### h3 ####\n\n### h2 ###\n\n# h1 #\n"))
1631 (markdown-demote-subtree)
1632 (should (string-equal (buffer-string) "### h1 ###\n\n#### h2 ####\n\n##### h3 #####\n\n#### h2 ####\n\n# h1 #\n"))
1633 (markdown-demote-subtree)
1634 (should (string-equal (buffer-string) "#### h1 ####\n\n##### h2 #####\n\n###### h3 ######\n\n##### h2 #####\n\n# h1 #\n"))
1635 ;; Stop demoting at level six
1636 (markdown-demote-subtree)
1637 (should (string-equal (buffer-string) "##### h1 #####\n\n###### h2 ######\n\n###### h3 ######\n\n###### h2 ######\n\n# h1 #\n"))
1638 (markdown-demote-subtree)
1639 (should (string-equal (buffer-string) "###### h1 ######\n\n###### h2 ######\n\n###### h3 ######\n\n###### h2 ######\n\n# h1 #\n"))))
1641 (ert-deftest test-markdown-subtree
/move-up
()
1642 "Test `markdown-move-subtree-up'."
1643 ;; Note that prior to Emacs 24.5, this does not work for the last subtree in
1644 ;; the buffer due to Emacs bug #19102:
1645 ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19102
1646 ;; https://github.com/emacs-mirror/emacs/commit/b3910f
1647 ;; That also corrects the type of the "Cannot move pase superior level" error
1648 ;; from 'error to 'user-error.
1649 (markdown-test-string "# 1 #\n\n## 1.1 ##\n\n### 1.1.1 ###\n\n## 1.2 ##\n\n### 1.2.1 ###\n\n# 2 #\n# Extra\n"
1650 (re-search-forward "^# 2")
1651 (markdown-move-subtree-up)
1652 (should (string-equal (buffer-string) "# 2 #\n# 1 #\n\n## 1.1 ##\n\n### 1.1.1 ###\n\n## 1.2 ##\n\n### 1.2.1 ###\n\n# Extra\n"))
1653 ;; Second attempt should fail, leaving buffer unchanged.
1654 ;; (This way of asserting the contents of the error
1655 ;; message is a bit convoluted and more fragile than
1656 ;; ideal. But prior to Emacs 24.5, the type of this
1657 ;; error is just 'error, and a bare "should-error" is
1658 ;; really overly broad.)
1659 (should (string-equal
1660 "Cannot move past superior level"
1661 (cl-second (should-error (markdown-move-subtree-up)))))))
1663 (ert-deftest test-markdown-subtree
/move-down
()
1664 "Test `markdown-move-subtree-down'."
1665 (markdown-test-string "# 1 #\n\n## 1.1 ##\n\n### 1.1.1 ###\n\n## 1.2 ##\n\n### 1.2.1 ###\n\n# 2 #\n"
1666 (re-search-forward "^## 1\.1")
1667 (markdown-move-subtree-down)
1668 (should (string-equal (buffer-string) "# 1 #\n\n## 1.2 ##\n\n### 1.2.1 ###\n\n## 1.1 ##\n\n### 1.1.1 ###\n\n# 2 #\n"))))
1670 ;(ert-deftest test-markdown-subtree/move-down ()
1674 (ert-deftest test-markdown-cycle
/atx-header
()
1675 "Test `markdown-demote' cycling for atx headers."
1676 (markdown-test-string "##### test"
1677 (call-interactively 'markdown-demote
)
1678 (should (string-equal (buffer-string) "###### test ######"))
1679 (call-interactively 'markdown-demote
)
1680 (should (string-equal (buffer-string) "# test #"))
1681 (call-interactively 'markdown-demote
)
1682 (should (string-equal (buffer-string) "## test ##"))))
1684 (ert-deftest test-markdown-cycle
/setext-header
()
1685 "Test `markdown-demote' cycling for setext headers."
1686 (markdown-test-string "test\n===="
1687 (call-interactively 'markdown-demote
)
1688 (should (string-equal (buffer-string) "test\n----"))
1689 (call-interactively 'markdown-demote
)
1690 (should (string-equal (buffer-string) "### test ###"))
1691 (call-interactively 'markdown-demote
)
1692 (should (string-equal (buffer-string) "#### test ####"))
1693 (call-interactively 'markdown-demote
)
1694 (should (string-equal (buffer-string) "##### test #####"))
1695 (call-interactively 'markdown-demote
)
1696 (should (string-equal (buffer-string) "###### test ######"))
1697 (call-interactively 'markdown-demote
)
1698 (should (string-equal (buffer-string) "# test #"))))
1700 (ert-deftest test-markdown-cycle
/hr
()
1701 "Test cycling of horizontal rules."
1702 ;; Cycle using markdown-demote
1703 (markdown-test-string (car markdown-hr-strings
)
1704 (dolist (n (number-sequence 1 5))
1705 (call-interactively 'markdown-demote
)
1706 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))
1707 (call-interactively 'markdown-demote
)
1708 (should (string-equal (buffer-string) (car markdown-hr-strings
))))
1709 ;; Cycle using markdown-promote
1710 (markdown-test-string (car (reverse markdown-hr-strings
))
1711 (dolist (n (number-sequence 4 0 -
1))
1712 (call-interactively 'markdown-promote
)
1713 (should (string-equal (buffer-string) (nth n markdown-hr-strings
))))
1714 (call-interactively 'markdown-promote
)
1715 (should (string-equal (buffer-string) (car (reverse markdown-hr-strings
))))))
1717 (ert-deftest test-markdown-cycle
/bold
()
1718 "Test cycling of bold markup."
1719 (markdown-test-string "**bold**"
1720 (call-interactively 'markdown-demote
)
1721 (should (string-equal (buffer-string) "__bold__"))
1722 (call-interactively 'markdown-demote
)
1723 (should (string-equal (buffer-string) "**bold**"))))
1725 (ert-deftest test-markdown-cycle
/italic
()
1726 "Test cycling of italic markup."
1727 (markdown-test-string "*italic*"
1728 (call-interactively 'markdown-demote
)
1729 (should (string-equal (buffer-string) "_italic_"))
1730 (call-interactively 'markdown-demote
)
1731 (should (string-equal (buffer-string) "*italic*"))))
1733 ;;; Indentation tests:
1735 (ert-deftest test-markdown-indentation
/calc-indents
()
1736 "Test `markdown-calc-indents' a nested list context."
1737 (markdown-test-file "nested-list.text"
1738 (goto-char (point-max))
1739 (let ((indents (markdown-calc-indents)))
1740 (should (= (car indents
) 17)) ; indentation of previous line first
1741 (should (equal (sort indents
'<)
1743 0 ; beginning of line
1744 3 ; first-level list marker
1745 7 ; second-level list marker
1746 11 ; third-level list marker
1747 13 ; previous list item text
1748 16 ; pre-block indentation
1749 17 ; indentation of previous line
1750 21 ; previous line plus tab-width
1753 (ert-deftest test-markdown-indentation
/indent-region
()
1754 "Test `markdown-indent-region'."
1755 ;; Basic test with multiple lines
1756 (markdown-test-string "abc\ndef\nghi\n"
1757 (markdown-indent-region (point-min) (point-max) nil
)
1758 (should (string-equal (buffer-string) " abc\n def\n ghi\n")))
1759 ;; Following a list item
1760 (markdown-test-string " * abc\ndef\n"
1762 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
1763 (should (string-equal (buffer-string) " * abc\n def\n"))
1764 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
1765 (should (string-equal (buffer-string) " * abc\n def\n"))))
1767 (ert-deftest test-markdown-indentation
/indent-list-hanging
()
1768 "Test `markdown-indent-line' with hanging list item."
1769 (markdown-test-string
1771 - nested list with long lines which need to be
1773 (goto-char (point-max))
1774 (markdown-enter-key)
1775 (should (eq (point) 78))))
1777 (ert-deftest test-markdown-indentation
/indent-list-single
()
1778 "Test `markdown-indent-line' with single list item."
1779 (markdown-test-string
1782 (markdown-enter-key)
1783 (should (string-equal (buffer-string) " * item 1\n * "))
1784 (should (eq (point) 16))
1785 (markdown-enter-key)
1786 (should (string-equal (buffer-string) " * item 1\n\n"))
1787 (should (eq (point) 13))))
1789 (ert-deftest test-markdown-indentation
/indent-nested-list
()
1790 "Test `markdown-enter-key' with a nested list item."
1791 (markdown-test-string
1792 "* foo\n* bar\n * baz"
1793 (goto-char (point-max))
1794 (markdown-enter-key)
1795 (should (string-equal (buffer-string) "* foo\n* bar\n * baz\n * "))
1796 (should (eq (point) 25))
1797 (markdown-enter-key)
1798 (should (string-equal (buffer-string) "* foo\n* bar\n * baz\n\n"))
1799 (should (eq (point) 22))))
1801 (ert-deftest test-markdown-indentation
/indent-pre
()
1802 "Test `markdown-indent-line' with a pre block."
1803 (markdown-test-string
1804 "I'm gonna write a code block:
1806 my first line of code"
1807 (goto-char (point-max))
1808 (markdown-enter-key)
1809 (should (eq (point) 62))
1810 (should (looking-back "^ "))))
1812 ;;; Font lock tests:
1814 (ert-deftest test-markdown-font-lock
/italics-1
()
1815 "A simple italics test."
1816 (markdown-test-file "inline.text"
1818 (should (looking-at "\*"))
1819 ;; Check face of char before leading asterisk
1820 (markdown-test-range-has-face 8 8 nil
)
1821 ;; Check face of italic range
1822 (markdown-test-range-has-face 9 9 markdown-markup-face
)
1823 (markdown-test-range-has-face 10 16 markdown-italic-face
)
1824 (markdown-test-range-has-face 17 17 markdown-markup-face
)
1825 ;; Check face of point past leading asterisk
1826 (markdown-test-range-has-face 18 18 nil
)))
1828 (ert-deftest test-markdown-font-lock
/italics-2
()
1829 "Test space after leading asterisk or underscore."
1830 (markdown-test-string
1831 "This is * not italic*, nor _ is this_."
1832 (markdown-test-range-has-face (point-min) (point-max) nil
)))
1834 (ert-deftest test-markdown-font-lock
/italics-3
()
1835 "Test that slash inside asterisks is not italic."
1836 (markdown-test-string
1838 (markdown-test-range-has-face (point-min) (point-max) nil
)))
1840 (ert-deftest test-markdown-font-lock
/italics-4
()
1841 "Test that escaped asterisk inside italics is not bold."
1842 (markdown-test-string
1844 (markdown-test-range-has-face 1 7 nil
)
1845 (markdown-test-range-has-face 8 8 markdown-markup-face
)
1846 (markdown-test-range-has-face 9 11 markdown-italic-face
)
1847 (markdown-test-range-has-face 12 12 markdown-markup-face
)))
1849 (ert-deftest test-markdown-font-lock
/italics-5
()
1850 "Test italic single letter."
1851 (markdown-test-string
1853 (markdown-test-range-has-face 1 1 markdown-markup-face
)
1854 (markdown-test-range-has-face 2 2 markdown-italic-face
)
1855 (markdown-test-range-has-face 3 3 markdown-markup-face
)))
1857 (ert-deftest test-markdown-font-lock
/italics-6
()
1858 "Test multiline italics across list items."
1859 (markdown-test-string
1860 "* something about function foo_bar
1861 * something else about foo_bar"
1862 (markdown-test-range-has-face 31 34 nil
)
1863 (markdown-test-range-has-face 38 62 nil
))
1864 (markdown-test-string
1865 "* something about function
1867 * something else about
1869 (markdown-test-range-has-face 30 36 nil
)
1870 (markdown-test-range-has-face 63 69 nil
))
1871 (markdown-test-string
1874 (markdown-test-range-has-face 4 7 nil
)
1875 (markdown-test-range-has-face 11 14 nil
)))
1877 (ert-deftest test-markdown-font-lock
/italics-7
()
1878 "Underscores in URLs should not trigger italics."
1879 :expected-result
:failed
1880 (markdown-test-string
1881 "<http://jblevins.org/research/centroid/cd_z_path.m>"
1882 (markdown-test-range-face-equals 2 50 markdown-link-face
))
1883 (markdown-test-string
1884 "[1]: http://jblevins.org/research/centroid/cd_z_path.m"
1885 (markdown-test-range-face-equals 6 54 markdown-url-face
))
1886 (markdown-test-string
1887 "[cd\\_z\\_path.m](http://jblevins.org/research/centroid/cd_z_path.m)"
1888 (markdown-test-range-face-equals 17 65 markdown-url-face
)))
1890 (ert-deftest test-markdown-font-lock
/italics-after-hr
()
1891 "Test italics after a horizontal rule with asterisks."
1892 (markdown-test-string "* * *\n\n*italic*\n"
1893 (markdown-test-range-has-face 1 5 markdown-header-delimiter-face
)
1894 (markdown-test-range-has-face 8 8 markdown-markup-face
)
1895 (markdown-test-range-has-face 9 14 markdown-italic-face
)
1896 (markdown-test-range-has-face 15 15 markdown-markup-face
)))
1898 (ert-deftest test-markdown-font-lock
/italics-in-heading
()
1899 "Test italic overlay in a heading."
1900 (markdown-test-string
1901 "# *Italics* in a Heading"
1902 (markdown-test-range-has-face 3 3 markdown-markup-face
)
1903 (markdown-test-range-has-face 4 10 markdown-italic-face
)
1904 (markdown-test-range-has-face 11 11 markdown-markup-face
)))
1906 (ert-deftest test-markdown-font-lock
/italics-link
()
1907 "Test italic overlay in an inline link."
1908 (markdown-test-string
1909 "*[italic link](http://www.link.com/)*"
1910 (markdown-test-range-has-face 1 1 markdown-markup-face
)
1911 (markdown-test-range-has-face 2 36 markdown-italic-face
)
1912 (markdown-test-range-has-face 37 37 markdown-markup-face
))
1913 (markdown-test-string
1914 "[*italic link*](http://www.link.com/)"
1915 (markdown-test-range-has-face 2 2 markdown-markup-face
)
1916 (markdown-test-range-has-face 3 13 markdown-italic-face
)
1917 (markdown-test-range-has-face 14 14 markdown-markup-face
)))
1919 (ert-deftest test-markdown-font-lock
/italics-in-blockquote
()
1920 "Test italics overlay in a blockquote."
1921 (markdown-test-string
1922 "> *italics* inside a blockquote"
1923 (markdown-test-range-has-face 3 3 markdown-markup-face
)
1924 (markdown-test-range-has-face 4 10 markdown-italic-face
)
1925 (markdown-test-range-has-face 11 11 markdown-markup-face
)))
1927 (ert-deftest test-markdown-font-lock
/italics-in-pre
()
1928 "Test italics overlay in a blockquote."
1929 (markdown-test-string
1930 " *italics* inside a pre block"
1931 (markdown-test-range-has-face (point-min) (1- (point-max))
1932 markdown-pre-face
)))
1934 (ert-deftest test-markdown-font-lock
/italics-and-code
()
1935 "Test seeming italics mixed with code."
1936 (markdown-test-string
1937 "define `var_1` and `var_2` inline code"
1938 (markdown-test-range-has-face 9 13 markdown-inline-code-face
)
1939 (markdown-test-range-has-face 21 25 markdown-inline-code-face
))
1940 (markdown-test-string
1942 (markdown-test-range-has-face 2 6 markdown-inline-code-face
)
1943 (markdown-test-range-has-face 8 17 nil
))
1944 (markdown-test-string
1946 (markdown-test-range-has-face 1 10 nil
)
1947 (markdown-test-range-has-face 12 16 markdown-inline-code-face
)))
1949 (ert-deftest test-markdown-font-lock
/italics-and-code
()
1950 "Test seeming italics mixed with code."
1951 (markdown-test-string
1952 "[lg]: twilight_sm.png\n[sm]: twilight_lg.png"
1953 (markdown-test-range-has-face 7 21 markdown-url-face
)
1954 (markdown-test-range-has-face 22 22 nil
)
1955 (markdown-test-range-has-face 29 43 markdown-url-face
)
1956 (markdown-test-range-has-face 28 28 nil
)))
1958 (ert-deftest test-markdown-font-lock
/bold-1
()
1959 "A simple bold test."
1960 (markdown-test-file "inline.text"
1962 (should (looking-at "\*\*"))
1963 ;; Check face of char before leading asterisk
1964 (markdown-test-range-has-face 26 26 nil
)
1965 ;; Check face of opening asterisks
1966 (markdown-test-range-has-face 27 28 markdown-markup-face
)
1967 ;; Check face of bold range
1968 (markdown-test-range-has-face 29 33 markdown-bold-face
)
1969 ;; Check face of closing asterisks
1970 (markdown-test-range-has-face 34 35 markdown-markup-face
)
1971 ;; Check face of point past leading asterisk
1972 (markdown-test-range-has-face 36 36 nil
)))
1974 (ert-deftest test-markdown-font-lock
/bold-2
()
1975 "Test space after leading asterisks or underscores."
1976 (markdown-test-string
1977 "This is ** not bold**, nor __ is this__ (but they match italics)."
1978 (markdown-test-range-has-face 1 8 nil
)
1979 (markdown-test-range-has-face 9 9 markdown-markup-face
)
1980 (markdown-test-range-has-face 10 19 markdown-italic-face
)
1981 (markdown-test-range-has-face 20 20 markdown-markup-face
)
1982 (markdown-test-range-has-face 21 27 nil
)
1983 (markdown-test-range-has-face 28 28 markdown-markup-face
)
1984 (markdown-test-range-has-face 29 37 markdown-italic-face
)
1985 (markdown-test-range-has-face 38 38 markdown-markup-face
)
1986 (markdown-test-range-has-face 39 (point-max) nil
)))
1988 (ert-deftest test-markdown-font-lock
/bold-3
()
1989 "Test escaped asterisk inside bold."
1990 (markdown-test-string
1992 (markdown-test-range-has-face 1 5 nil
)
1993 (markdown-test-range-has-face 6 7 markdown-markup-face
)
1994 (markdown-test-range-has-face 8 9 markdown-bold-face
)
1995 (markdown-test-range-has-face 10 11 markdown-markup-face
)))
1997 (ert-deftest test-markdown-font-lock
/bold-4
()
1998 "Test bold single letter."
1999 (markdown-test-string
2001 (markdown-test-range-has-face 1 2 markdown-markup-face
)
2002 (markdown-test-range-has-face 3 3 markdown-bold-face
)
2003 (markdown-test-range-has-face 4 5 markdown-markup-face
)))
2005 (ert-deftest test-markdown-font-lock
/bold-after-hr
()
2006 "Test bold after a horizontal rule with asterisks."
2007 (markdown-test-string "* * *\n\n**bold**\n"
2008 (markdown-test-range-has-face 1 5 markdown-header-delimiter-face
)
2009 (markdown-test-range-has-face 8 9 markdown-markup-face
)
2010 (markdown-test-range-has-face 10 13 markdown-bold-face
)
2011 (markdown-test-range-has-face 14 15 markdown-markup-face
)))
2013 (ert-deftest test-markdown-font-lock
/bold-link
()
2014 "Test bold overlay in an inline link."
2015 (markdown-test-string
2016 "**[bold link](http://www.link.com/)**"
2017 (markdown-test-range-has-face 1 2 markdown-markup-face
)
2018 (markdown-test-range-has-face 3 35 markdown-bold-face
)
2019 (markdown-test-range-has-face 36 37 markdown-markup-face
))
2020 (markdown-test-string
2021 "[**bold link**](http://www.link.com/)"
2022 (markdown-test-range-has-face 2 3 markdown-markup-face
)
2023 (markdown-test-range-has-face 4 12 markdown-bold-face
)
2024 (markdown-test-range-has-face 13 14 markdown-markup-face
)))
2026 (ert-deftest test-markdown-font-lock
/bold-in-blockquote
()
2027 "Test bold overlay in a blockquote."
2028 (markdown-test-string
2029 "> **bold** inside a blockquote"
2030 (markdown-test-range-has-face 3 4 markdown-markup-face
)
2031 (markdown-test-range-has-face 5 8 markdown-bold-face
)
2032 (markdown-test-range-has-face 9 10 markdown-markup-face
)))
2034 (ert-deftest test-markdown-font-lock
/bold-in-pre
()
2035 "Test bold overlay in a blockquote."
2036 (markdown-test-string
2037 " **bold** inside a pre block"
2038 (markdown-test-range-has-face (point-min) (1- (point-max))
2039 markdown-pre-face
)))
2041 (ert-deftest test-markdown-font-lock
/no-bold-in-code
()
2042 "Bold markers in inline code should not trigger bold."
2043 (markdown-test-string
2044 "`def __init__(self):`"
2045 (markdown-test-range-has-face 8 11 markdown-inline-code-face
))
2046 (markdown-test-string
2047 "`**foo` bar `baz**`"
2048 (markdown-test-range-face-equals 2 6 markdown-inline-code-face
)
2049 (markdown-test-range-face-equals 9 11 nil
)
2050 (markdown-test-range-face-equals 14 18 markdown-inline-code-face
)))
2052 (ert-deftest test-markdown-font-lock
/code-1
()
2053 "A simple inline code test."
2054 (markdown-test-file "inline.text"
2056 (should (looking-at "`"))
2057 ;; Regular code span
2058 (markdown-test-range-has-face 45 45 markdown-markup-face
)
2059 (markdown-test-range-has-face 46 49 markdown-inline-code-face
)
2060 (markdown-test-range-has-face 50 50 markdown-markup-face
)
2061 ;; Code containing backticks
2062 (markdown-test-range-has-face 61 62 markdown-markup-face
)
2063 (markdown-test-range-has-face 63 87 markdown-inline-code-face
)
2064 (markdown-test-range-has-face 88 89 markdown-markup-face
)
2065 ;; Seven backquotes in a row
2066 (markdown-test-range-has-face 119 125 nil
)
2067 ;; Backquotes at beginning or end
2068 (markdown-test-range-has-face 228 229 markdown-markup-face
)
2069 (markdown-test-range-has-face 230 237 markdown-inline-code-face
)
2070 (markdown-test-range-has-face 238 239 markdown-markup-face
)
2071 (markdown-test-range-has-face 341 342 markdown-markup-face
)
2072 (markdown-test-range-has-face 343 349 markdown-inline-code-face
)
2073 (markdown-test-range-has-face 350 351 markdown-markup-face
)
2074 ;; Backslash as final character
2075 (markdown-test-range-has-face 460 460 markdown-markup-face
)
2076 (markdown-test-range-has-face 461 467 markdown-inline-code-face
)
2077 (markdown-test-range-has-face 468 468 markdown-markup-face
)
2078 ;; Escaping of leading backquotes
2079 (markdown-test-range-has-face 586 592 nil
)
2080 (markdown-test-range-has-face 597 603 nil
)
2081 ;; A code span crossing lines
2082 (markdown-test-range-has-face 652 656 nil
)
2083 (markdown-test-range-has-face 657 657 markdown-markup-face
)
2084 (markdown-test-range-has-face 658 665 markdown-inline-code-face
)
2085 (markdown-test-range-has-face 666 666 markdown-markup-face
)
2086 ;; Three backquotes: same line, across lines, not across blocks
2087 (markdown-test-range-has-face 695 748 nil
)
2088 (markdown-test-range-has-face 749 750 markdown-markup-face
)
2089 (markdown-test-range-has-face 751 755 markdown-inline-code-face
)
2090 (markdown-test-range-has-face 756 757 markdown-markup-face
)
2091 (markdown-test-range-has-face 758 805 nil
)
2092 (markdown-test-range-has-face 806 807 markdown-markup-face
)
2093 (markdown-test-range-has-face 808 812 markdown-inline-code-face
)
2094 (markdown-test-range-has-face 813 814 markdown-markup-face
)
2095 (markdown-test-range-has-face 815 891 nil
)
2098 (ert-deftest test-markdown-font-lock
/code-2
()
2099 "Multiple code spans in a row and on different lines."
2100 (markdown-test-string "`foo` `bar` `baz`"
2101 (markdown-test-range-has-face 1 1 markdown-markup-face
)
2102 (markdown-test-range-has-face 2 4 markdown-inline-code-face
)
2103 (markdown-test-range-has-face 5 5 markdown-markup-face
)
2104 (markdown-test-range-has-face 6 6 nil
)
2105 (markdown-test-range-has-face 7 7 markdown-markup-face
)
2106 (markdown-test-range-has-face 8 10 markdown-inline-code-face
)
2107 (markdown-test-range-has-face 11 11 markdown-markup-face
)
2108 (markdown-test-range-has-face 12 12 nil
)
2109 (markdown-test-range-has-face 13 13 markdown-markup-face
)
2110 (markdown-test-range-has-face 14 16 markdown-inline-code-face
)
2111 (markdown-test-range-has-face 17 17 markdown-markup-face
))
2112 (markdown-test-string "`a`\n`b`\n`c`\n"
2113 (markdown-test-range-has-face 1 1 markdown-markup-face
)
2114 (markdown-test-range-has-face 2 2 markdown-inline-code-face
)
2115 (markdown-test-range-has-face 3 3 markdown-markup-face
)
2116 (markdown-test-range-has-face 4 4 nil
)
2117 (markdown-test-range-has-face 5 5 markdown-markup-face
)
2118 (markdown-test-range-has-face 6 6 markdown-inline-code-face
)
2119 (markdown-test-range-has-face 7 7 markdown-markup-face
)
2120 (markdown-test-range-has-face 8 8 nil
)
2121 (markdown-test-range-has-face 9 9 markdown-markup-face
)
2122 (markdown-test-range-has-face 10 10 markdown-inline-code-face
)
2123 (markdown-test-range-has-face 11 11 markdown-markup-face
)
2124 (markdown-test-range-has-face 12 12 nil
))
2125 (markdown-test-string "a`foo`b`bar`c`baz`d"
2126 (markdown-test-range-has-face 1 1 nil
)
2127 (markdown-test-range-has-face 2 2 markdown-markup-face
)
2128 (markdown-test-range-has-face 3 5 markdown-inline-code-face
)
2129 (markdown-test-range-has-face 6 6 markdown-markup-face
)
2130 (markdown-test-range-has-face 7 7 nil
)
2131 (markdown-test-range-has-face 8 8 markdown-markup-face
)
2132 (markdown-test-range-has-face 9 11 markdown-inline-code-face
)
2133 (markdown-test-range-has-face 12 12 markdown-markup-face
)
2134 (markdown-test-range-has-face 13 13 nil
)
2135 (markdown-test-range-has-face 14 14 markdown-markup-face
)
2136 (markdown-test-range-has-face 15 17 markdown-inline-code-face
)
2137 (markdown-test-range-has-face 18 18 markdown-markup-face
)
2138 (markdown-test-range-has-face 19 19 nil
)))
2140 (ert-deftest test-markdown-font-lock
/code-3
()
2141 "Backslashes don't escape backticks inside of inline code strings."
2142 (markdown-test-string
2144 (markdown-test-range-has-face 1 1 markdown-markup-face
)
2145 (markdown-test-range-has-face 2 5 markdown-inline-code-face
)
2146 (markdown-test-range-has-face 6 6 markdown-markup-face
)
2147 (markdown-test-range-has-face 7 10 nil
)))
2149 (ert-deftest test-markdown-font-lock
/code-link-precedence
()
2150 "Test that inline code takes precedence over inline links.
2151 Test currently fails because this case isn't handled properly."
2152 :expected-result
:failed
2153 (markdown-test-string
2154 "[not a `link](/foo`)"
2155 (markdown-test-range-has-face 1 7 nil
)
2156 (markdown-test-range-has-face 8 8 markdown-markup-face
)
2157 (markdown-test-range-has-face 9 18 markdown-inline-code-face
)
2158 (markdown-test-range-has-face 19 19 markdown-markup-face
)
2159 (markdown-test-range-has-face 20 20 nil
)))
2161 (ert-deftest test-markdown-font-lock
/kbd
()
2162 "Test font lock for <kbd> tags."
2163 (markdown-test-string "<kbd>C-c <</kbd>"
2164 (markdown-test-range-has-face 1 5 markdown-markup-face
)
2165 (markdown-test-range-has-face 6 10 markdown-inline-code-face
)
2166 (markdown-test-range-has-face 11 16 markdown-markup-face
))
2167 (markdown-test-string "To quit Emacs, press <kbd>C-x C-c</kbd>."
2168 (markdown-test-range-has-face 1 21 nil
)
2169 (markdown-test-range-has-face 22 26 markdown-markup-face
)
2170 (markdown-test-range-has-face 27 33 markdown-inline-code-face
)
2171 (markdown-test-range-has-face 34 39 markdown-markup-face
)
2172 (markdown-test-range-has-face 40 40 nil
)))
2174 (ert-deftest test-markdown-font-lock
/lists-1
()
2175 "A simple list marker font lock test."
2176 (markdown-test-file "lists.text"
2177 (dolist (loc (list 1063 1283 1659 1830 1919 2150 2393 2484
2178 2762 2853 3097 3188 3700 3903 4009))
2180 (should (looking-at "[*+-]"))
2181 (markdown-test-range-has-face loc loc markdown-list-face
))))
2183 (ert-deftest test-markdown-font-lock
/definition-list
()
2184 "A simple definition list marker font lock test."
2185 (markdown-test-file "definition-list.text"
2186 (markdown-test-range-has-face 7 7 'markdown-list-face
)
2187 (markdown-test-range-has-face 29 52 'markdown-pre-face
)
2188 (markdown-test-range-has-face 55 55 'markdown-list-face
)))
2190 (ert-deftest test-markdown-font-lock
/pre-1
()
2191 "Nested list and pre block font lock test."
2192 (markdown-test-file "nested-list.text"
2193 (dolist (loc (list 4 29 194 224 491 525))
2194 (markdown-test-range-has-face loc loc markdown-list-face
))
2195 (markdown-test-range-has-face 6 25 nil
)
2196 (markdown-test-range-has-face 31 83 nil
)
2197 (markdown-test-range-has-face 85 154 markdown-pre-face
)
2198 (markdown-test-range-has-face 157 189 nil
)
2199 (markdown-test-range-has-face 196 215 nil
)
2200 (markdown-test-range-has-face 226 403 nil
)
2201 (markdown-test-range-has-face 405 481 markdown-pre-face
)
2202 (markdown-test-range-has-face 493 512 nil
)
2203 (markdown-test-range-has-face 527 546 nil
)
2204 (markdown-test-range-has-face 548 580 markdown-pre-face
)))
2206 (ert-deftest test-markdown-font-lock
/pre-2
()
2207 (markdown-test-string "* item\n\nreset baseline\n\n pre block\n"
2208 (markdown-test-range-has-face 1 1 markdown-list-face
)
2209 (markdown-test-range-has-face 2 23 nil
)
2210 (markdown-test-range-has-face 29 37 markdown-pre-face
)))
2212 (ert-deftest test-markdown-font-lock
/pre-3
()
2213 (markdown-test-string "It is interesting to see what happens when one queries
2214 `social upheaval` and `protopalatial era`.
2216 * `social upheaval`: the follwing queries have been tried:
2218 social upheaval subClassOf"
2219 (markdown-test-range-has-face 160 190 nil
)))
2221 (ert-deftest test-markdown-font-lock
/pre-4
()
2222 "Pre blocks must be preceded by a blank line"
2223 (markdown-test-string "Paragraph
2224 for (var i = 0; i < 10; i++) {
2227 (markdown-test-range-has-face (point-min) (point-max) nil
)))
2229 (ert-deftest test-markdown-font-lock
/fenced-1
()
2230 "Test fenced code blocks containing four-space indents."
2231 (markdown-test-string "Fenced code block
2241 (markdown-test-range-has-face 1 19 nil
)
2242 (markdown-test-range-has-face 20 22 markdown-markup-face
)
2243 (markdown-test-range-has-face 24 60 markdown-pre-face
)
2244 (markdown-test-range-has-face 61 63 markdown-markup-face
)))
2246 (ert-deftest test-markdown-font-lock
/gfm-fenced-1
()
2247 "Test GFM-style fenced code blocks (1)."
2248 (markdown-test-string "```ruby
2250 markdown = Redcarpet.new('Hello World!')
2251 puts markdown.to_html
2253 (markdown-test-range-has-face 1 3 markdown-markup-face
) ; ```
2254 (markdown-test-range-has-face 4 7 markdown-language-keyword-face
) ; ruby
2255 (markdown-test-range-has-face 9 90 markdown-pre-face
) ; code
2256 (markdown-test-range-has-face 92 94 markdown-markup-face
))) ; ```
2258 (ert-deftest test-markdown-font-lock
/gfm-fenced-2
()
2259 "Test GFM-style fenced code blocks (2)."
2260 (markdown-test-string "```{r sum}\n2+2\n```"
2261 (markdown-test-range-has-face 1 3 markdown-markup-face
) ; ```
2262 (markdown-test-range-has-face 4 4 markdown-markup-face
) ; {
2263 (markdown-test-range-has-face 5 5 markdown-language-keyword-face
) ; r
2264 (markdown-test-range-has-face 7 9 markdown-language-info-face
) ; sum
2265 (markdown-test-range-has-face 10 10 markdown-markup-face
) ; }
2266 (markdown-test-range-has-face 12 14 markdown-pre-face
) ; 2+2
2267 (markdown-test-range-has-face 16 18 markdown-markup-face
))) ; ```
2269 (ert-deftest test-markdown-font-lock
/gfm-fenced-3
()
2270 "GFM-style code blocks need not be preceded by a blank line."
2271 (markdown-test-string "Paragraph
2273 for (var i = 0; i < 10; i++) {
2277 (markdown-test-range-has-face 1 10 nil
) ; Paragraph
2278 (markdown-test-range-has-face 11 13 markdown-markup-face
) ; ```
2279 (markdown-test-range-has-face 14 15 markdown-language-keyword-face
) ; js
2280 (markdown-test-range-has-face 17 68 markdown-pre-face
)
2281 (markdown-test-range-has-face 70 72 markdown-markup-face
)))
2283 (ert-deftest test-markdown-font-lock
/gfm-fenced-4
()
2284 "Test GFM-style fenced code blocks (2)."
2285 (markdown-test-string "```scalaFiddle libraries=\"Java8 Time-0.1.0\"\nimport java.time._\n\nval hour = LocalTime.now().getHour()\n\nprintln(hour)\n```"
2286 (markdown-test-range-has-face 1 3 markdown-markup-face
) ; ```
2287 (markdown-test-range-has-face 4 14 markdown-language-keyword-face
) ; scalaFiddle
2288 (markdown-test-range-has-face 16 43 markdown-language-info-face
) ; libraries="Java8 Time-0.1.0"
2289 (markdown-test-range-has-face 45 115 markdown-pre-face
) ; [code]
2290 (markdown-test-range-has-face 117 119 markdown-markup-face
))) ; ```
2292 (ert-deftest test-markdown-font-lock
/atx-no-spaces
()
2293 "Test font-lock for atx headers with no spaces."
2294 (markdown-test-string "##abc##"
2295 (markdown-test-range-has-face 1 7 nil
))
2296 (markdown-test-string "##"
2297 (markdown-test-range-has-face 1 2 nil
))
2298 (markdown-test-string "###"
2299 (markdown-test-range-has-face 1 3 nil
)))
2301 (ert-deftest test-markdown-font-lock
/setext-1-letter
()
2302 "An edge case for level-one setext headers."
2303 (markdown-test-string "a\n=\n"
2304 (markdown-test-range-has-face 1 1 markdown-header-face-1
)
2305 (markdown-test-range-has-face 3 3 markdown-header-rule-face
)))
2307 (ert-deftest test-markdown-font-lock
/setext-2-letter
()
2308 "An edge case for level-two setext headers."
2309 (markdown-test-string "b\n-\n"
2310 (markdown-test-range-has-face 1 1 markdown-header-face-2
)
2311 (markdown-test-range-has-face 3 3 markdown-header-rule-face
)))
2313 (ert-deftest test-markdown-font-lock
/inline-links
()
2314 "Test font lock for inline links."
2315 (markdown-test-file "inline.text"
2316 (markdown-test-range-has-face 925 925 markdown-markup-face
)
2317 (markdown-test-range-has-face 926 929 markdown-link-face
)
2318 (markdown-test-range-has-face 930 931 markdown-markup-face
)
2319 (markdown-test-range-has-face 932 949 markdown-url-face
)
2320 (markdown-test-range-has-face 951 957 markdown-link-title-face
)
2321 (markdown-test-range-has-face 958 958 markdown-markup-face
)))
2323 (ert-deftest test-markdown-font-lock
/pre-comment
()
2324 "Test comments inside of a pre block."
2325 (markdown-test-string " <!-- pre, not comment -->"
2326 (markdown-test-range-has-face (point-min) (1- (point-max)) markdown-pre-face
)))
2328 (ert-deftest test-markdown-font-lock
/inline-code-comment
()
2329 "Test comments inside of a pre block."
2330 (markdown-test-string "`<h1> <!-- HTML comment inside inline code -->`"
2331 (markdown-test-range-has-face (1+ (point-min)) (- (point-max) 2) markdown-inline-code-face
)))
2333 (ert-deftest test-markdown-font-lock
/comment-hanging-indent
()
2334 "Test comments with hanging indentation."
2335 (markdown-test-string "<!-- This comment has\n hanging indentation -->"
2336 (markdown-test-range-has-face (point-min) (1- (point-max)) markdown-comment-face
)))
2338 (ert-deftest test-markdown-font-lock
/comment-multiple
()
2339 "Test multiple single-line comments in arow."
2340 (markdown-test-string "<!-- This is a comment -->\n<!-- And so is this -->"
2341 (markdown-test-range-has-face
2342 (point-at-bol) (1- (point-at-eol)) markdown-comment-face
)
2344 (markdown-test-range-has-face
2345 (point-at-bol) (1- (point-at-eol)) markdown-comment-face
)))
2347 (ert-deftest test-markdown-font-lock
/comment-list-items
()
2348 "Test comment with list inside."
2349 (markdown-test-string
2354 (markdown-test-range-face-equals (point-min) (1- (point-max))
2355 markdown-comment-face
)))
2357 (ert-deftest test-markdown-font-lock
/comment-angle-bracket
()
2358 "Regression test for GH-117."
2359 (markdown-test-string "<!-- > test -->"
2360 (markdown-test-range-face-equals (point-min) (1- (point-max))
2361 markdown-comment-face
)))
2363 (ert-deftest test-markdown-font-lock
/footnote-markers-links
()
2364 "Test an edge case involving footnote markers and inline reference links."
2365 (markdown-test-string "Harvard[^1] [tuition][]"
2366 (markdown-test-range-has-face 1 7 nil
)
2367 (markdown-test-range-has-face 8 8 markdown-markup-face
)
2368 (markdown-test-range-has-face 10 10 markdown-footnote-face
)
2369 (markdown-test-range-has-face 11 11 markdown-markup-face
)
2370 (markdown-test-range-has-face 12 12 nil
)
2371 (markdown-test-range-has-face 13 13 markdown-markup-face
)
2372 (markdown-test-range-has-face 14 20 markdown-link-face
)
2373 (markdown-test-range-has-face 21 21 markdown-markup-face
)
2374 (markdown-test-range-has-face 22 23 markdown-markup-face
)))
2376 (ert-deftest test-markdown-font-lock
/mmd-metadata
()
2377 "Basic MultMarkdown metadata tests."
2378 (markdown-test-string "Title: peg-multimarkdown User's Guide
2379 Author: Fletcher T. Penney
2380 Base Header Level: 2"
2381 (markdown-test-range-has-face 1 5 markdown-metadata-key-face
)
2382 (markdown-test-range-has-face 6 6 markdown-markup-face
)
2383 (markdown-test-range-has-face 8 37 markdown-metadata-value-face
)
2384 (markdown-test-range-has-face 39 44 markdown-metadata-key-face
)
2385 (markdown-test-range-has-face 46 46 markdown-markup-face
)
2386 (markdown-test-range-has-face 47 64 markdown-metadata-value-face
)
2387 (markdown-test-range-has-face 66 82 markdown-metadata-key-face
)
2388 (markdown-test-range-has-face 83 83 markdown-markup-face
)
2389 (markdown-test-range-has-face 85 85 markdown-metadata-value-face
))
2390 ;; Avoid triggering when a title contains a colon (e.g., Markdown: Syntax)
2391 (markdown-test-file "syntax.text"
2392 (markdown-test-range-has-face 1 16 markdown-header-face-1
)))
2394 (ert-deftest test-markdown-font-lock
/mmd-metadata-after-header
()
2395 "Ensure that similar lines are not matched after the header."
2396 (markdown-test-string "Title: peg-multimarkdown User's Guide
2398 Author: Fletcher T. Penney
2399 Base Header Level: 2"
2400 (markdown-test-range-has-face 1 5 markdown-metadata-key-face
)
2401 (markdown-test-range-has-face 6 6 markdown-markup-face
)
2402 (markdown-test-range-has-face 8 37 markdown-metadata-value-face
)
2403 (markdown-test-range-has-face 40 65 nil
)
2404 (markdown-test-range-has-face 67 86 nil
)))
2406 (ert-deftest test-markdown-font-lock
/pandoc-metadata
()
2407 "Basic Pandoc metadata tests."
2408 (markdown-test-string "% title
2415 (markdown-test-range-has-face 1 1 markdown-markup-face
)
2416 (markdown-test-range-has-face 3 24 markdown-metadata-value-face
)
2417 (markdown-test-range-has-face 26 26 markdown-markup-face
)
2418 (markdown-test-range-has-face 28 56 markdown-metadata-value-face
)
2419 (markdown-test-range-has-face 58 58 markdown-markup-face
)
2420 (markdown-test-range-has-face 60 63 markdown-metadata-value-face
)
2421 (markdown-test-range-has-face 64 69 nil
)))
2423 (ert-deftest test-markdown-font-lock
/yaml-metadata
()
2424 "Basic YAML metadata tests."
2425 (markdown-test-string
2428 date: 2015-08-13 11:35:25 EST
2431 (markdown-test-range-has-face 1 3 markdown-markup-face
)
2432 (markdown-test-range-has-face 5 10 markdown-metadata-key-face
)
2433 (markdown-test-range-has-face 11 11 markdown-markup-face
)
2434 (markdown-test-range-has-face 13 16 markdown-metadata-value-face
)
2435 (markdown-test-range-has-face 18 21 markdown-metadata-key-face
)
2436 (markdown-test-range-has-face 22 22 markdown-markup-face
)
2437 (markdown-test-range-has-face 24 46 markdown-metadata-value-face
)
2438 (markdown-test-range-has-face 48 50 markdown-markup-face
)))
2440 (ert-deftest test-markdown-font-lock
/toml-metadata
()
2441 "Basic TOML metadata tests."
2442 (markdown-test-string
2445 date = 2015-08-13 11:35:25 EST
2448 (markdown-test-range-has-face 1 3 markdown-markup-face
)
2449 (markdown-test-range-has-face 5 10 markdown-metadata-key-face
)
2450 (markdown-test-range-has-face 12 12 markdown-markup-face
)
2451 (markdown-test-range-has-face 14 17 markdown-metadata-value-face
)
2452 (markdown-test-range-has-face 19 22 markdown-metadata-key-face
)
2453 (markdown-test-range-has-face 24 24 markdown-markup-face
)
2454 (markdown-test-range-has-face 26 48 markdown-metadata-value-face
)
2455 (markdown-test-range-has-face 50 52 markdown-markup-face
)))
2457 (ert-deftest test-markdown-font-lock
/pandoc-yaml-metadata
()
2458 "Basic yaml metadata tests, with pandoc syntax."
2459 (let ((markdown-use-pandoc-style-yaml-metadata t
))
2460 (markdown-test-string
2465 date: 2015-08-13 11:35:25 EST
2472 date: 2015-08-13 11:35:25 EST
2475 But this is merely a code block
2480 date: 2015-08-13 11:35:25 EST
2485 (markdown-test-range-has-face 12 14 markdown-markup-face
)
2486 (markdown-test-range-has-face 16 21 markdown-metadata-key-face
)
2487 (markdown-test-range-has-face 22 22 markdown-markup-face
)
2488 (markdown-test-range-has-face 24 27 markdown-metadata-value-face
)
2489 (markdown-test-range-has-face 29 32 markdown-metadata-key-face
)
2490 (markdown-test-range-has-face 33 33 markdown-markup-face
)
2491 (markdown-test-range-has-face 35 57 markdown-metadata-value-face
)
2492 (markdown-test-range-has-face 59 61 markdown-markup-face
)
2494 (markdown-test-range-has-face 75 77 markdown-markup-face
)
2495 (markdown-test-range-has-face 79 84 markdown-metadata-key-face
)
2496 (markdown-test-range-has-face 85 85 markdown-markup-face
)
2497 (markdown-test-range-has-face 87 90 markdown-metadata-value-face
)
2498 (markdown-test-range-has-face 92 95 markdown-metadata-key-face
)
2499 (markdown-test-range-has-face 96 96 markdown-markup-face
)
2500 (markdown-test-range-has-face 98 120 markdown-metadata-value-face
)
2501 (markdown-test-range-has-face 122 124 markdown-markup-face
)
2503 (markdown-test-range-has-face 160 162 markdown-markup-face
)
2504 (markdown-test-range-has-face 164 213 markdown-pre-face
)
2505 (markdown-test-range-has-face 215 217 markdown-markup-face
))))
2507 (ert-deftest test-markdown-font-lock
/line-break
()
2508 "Basic line break tests."
2509 (markdown-test-string " \nasdf \n"
2510 (markdown-test-range-has-face 1 9 nil
)
2511 (markdown-test-range-has-face 10 11 markdown-line-break-face
)))
2513 (ert-deftest test-markdown-font-lock
/blockquote-bold
()
2514 "Test font lock for bold inside of a blockquote."
2515 (markdown-test-string
2517 (markdown-test-range-has-face 2 10 markdown-blockquote-face
)
2518 (markdown-test-range-has-face 5 8 markdown-bold-face
)))
2520 (ert-deftest test-markdown-font-lock
/blockquote-italic
()
2521 "Test font lock for italic inside of a blockquote."
2522 (markdown-test-string
2524 (markdown-test-range-has-face 2 10 markdown-blockquote-face
)
2525 (markdown-test-range-has-face 4 9 markdown-italic-face
)))
2527 (ert-deftest test-markdown-font-lock
/blockquote-link
()
2528 "Test font lock for links inside of a blockquote.
2529 This test will fail until font lock for inline links inside
2530 blockquotes is implemented (at present, the blockquote face
2532 :expected-result
:failed
2533 (markdown-test-string
2535 (markdown-test-range-has-face 1 13 markdown-blockquote-face
)
2536 (markdown-test-range-has-face 3 8 markdown-link-face
)
2537 (markdown-test-range-has-face 9 13 markdown-url-face
)))
2539 (ert-deftest test-markdown-font-lock
/blockquote-comment
()
2540 "Test font lock for comments inside of a blockquote."
2541 (markdown-test-string
2542 "> <!-- comment -->"
2543 (markdown-test-range-has-face 1 1 markdown-markup-face
)
2544 (markdown-test-range-has-face 3 18 markdown-comment-face
)))
2546 (ert-deftest test-markdown-font-lock
/pre-override
()
2547 "Test that font lock for pre blocks overrides everything else."
2548 (markdown-test-string
2554 (markdown-test-range-has-face 1 73 markdown-pre-face
)))
2556 (ert-deftest test-markdown-font-lock
/gfm-code-block-font-lock
()
2557 "GFM code block font lock test. Now in base markdown-mode as well!"
2558 (markdown-test-file "gfm.text"
2559 (markdown-test-range-has-face 2639 2641 markdown-markup-face
) ; ```
2560 (markdown-test-range-has-face 2642 2645 markdown-language-keyword-face
) ; lang
2561 (markdown-test-range-has-face 2647 2728 markdown-pre-face
) ; code
2562 (markdown-test-range-has-face 2730 2732 markdown-markup-face
))) ; ```
2564 (ert-deftest test-markdown-font-lock
/reference-definition
()
2565 "Reference definitions should not include ]."
2566 (markdown-test-string "[1]: http://daringfireball.net/ \"title\""
2567 (markdown-test-range-has-face 2 2 markdown-reference-face
) ; 1
2568 (markdown-test-range-has-face 6 31 markdown-url-face
) ; URL
2569 (markdown-test-range-has-face 34 38 markdown-link-title-face
)) ; title
2570 (markdown-test-string "[foo][1] and [bar][2]: not a reference definition"
2571 (markdown-test-range-has-face 2 4 markdown-link-face
) ; foo
2572 (markdown-test-range-has-face 7 7 markdown-reference-face
) ; 1
2573 (markdown-test-range-has-face 9 13 nil
) ; [ ]and[ ]
2574 (markdown-test-range-has-face 15 17 markdown-link-face
) ; bar
2575 (markdown-test-range-has-face 20 20 markdown-reference-face
) ; 2
2576 (markdown-test-range-has-face 22 49 nil
))) ; [ ]and[ ]
2578 ;;; Markdown Parsing Functions:
2580 (ert-deftest test-markdown-parsing
/extend-region-function
()
2581 "Test `markdown-syntax-propertize-extend-region'.
2582 Should return a cons (NEW-START . NEW-END) or nil if no
2583 adjustment should be made. Function is called repeatedly until it
2587 (should (equal (markdown-syntax-propertize-extend-region 1 17)
2589 (should (equal (markdown-syntax-propertize-extend-region 2 17)
2591 (should (equal (markdown-syntax-propertize-extend-region 1 91)
2593 (should (equal (markdown-syntax-propertize-extend-region 93 157)
2595 (should (equal (markdown-syntax-propertize-extend-region 496 502)
2597 (should (equal (markdown-syntax-propertize-extend-region 486 510)
2599 ;; Region that begins and ends with \n\n should not be extended
2600 (should (equal (markdown-syntax-propertize-extend-region 157 355)
2603 (defun markdown-test-check-match-limits (prop num begin end
&optional pos
)
2604 (let* ((posn (or pos
(point)))
2605 (props (get-text-property posn prop
)))
2607 (set-match-data props
)
2608 (and (match-beginning num
) (match-end num
)
2609 (= (match-beginning num
) begin
)
2610 (= (match-end num
) end
)))))
2612 (ert-deftest test-markdown-parsing
/syntax-with-adjacent-code-blocks
()
2613 "Test `markdown-syntax-propertize-fenced-code-blocks' with adjacent blocks."
2614 (markdown-test-string
2618 echo \"Hello, world!\"
2624 echo \"Hello, world v2!\"
2627 (let ((start-top-1 (make-marker)) (end-top-1 (make-marker))
2628 (start-lang-1 (make-marker)) (end-lang-1 (make-marker))
2629 (start-mid-1 (make-marker)) (end-mid-1 (make-marker))
2630 (start-bottom-1 (make-marker)) (end-bottom-1 (make-marker))
2631 (between (make-marker))
2632 (start-top-2 (make-marker)) (end-top-2 (make-marker))
2633 (start-lang-2 (make-marker)) (end-lang-2 (make-marker))
2634 (start-mid-2 (make-marker)) (end-mid-2 (make-marker))
2635 (start-bottom-2 (make-marker)) (end-bottom-2 (make-marker)))
2637 (set-marker start-top-1
1)
2638 (set-marker end-top-1
4)
2639 (set-marker start-lang-1
5)
2640 (set-marker end-lang-1
10)
2641 (set-marker start-mid-1
11)
2642 (set-marker end-mid-1
43)
2643 (set-marker start-bottom-1
43)
2644 (set-marker end-bottom-1
46)
2646 (should (markdown-test-check-match-limits
2647 'markdown-tilde-fence-begin
1 (marker-position start-top-1
)
2648 (marker-position end-top-1
) (marker-position start-top-1
)))
2649 ;; check top language specifier
2650 (should (markdown-test-check-match-limits
2651 'markdown-tilde-fence-begin
3 (marker-position start-lang-1
)
2652 (marker-position end-lang-1
) (marker-position start-lang-1
)))
2653 ;; check text in between
2654 (should (markdown-test-check-match-limits
2655 'markdown-fenced-code
0 (marker-position start-mid-1
)
2656 (marker-position end-mid-1
) (marker-position start-mid-1
)))
2657 ;; check bottom tildes
2658 (should (markdown-test-check-match-limits
2659 'markdown-tilde-fence-end
1 (marker-position start-bottom-1
)
2660 (marker-position end-bottom-1
) (marker-position start-bottom-1
)))
2661 ;; Point between code blocks
2662 (set-marker between
47)
2663 (should (equal (get-text-property between
'markdown-fenced-code
)
2665 ;; Second code block
2666 (set-marker start-top-2
48)
2667 (set-marker end-top-2
51)
2668 (set-marker start-lang-2
52)
2669 (set-marker end-lang-2
57)
2670 (set-marker start-mid-2
58)
2671 (set-marker end-mid-2
93)
2672 (set-marker start-bottom-2
93)
2673 (set-marker end-bottom-2
96)
2674 (should (markdown-test-check-match-limits
2675 'markdown-tilde-fence-begin
1 (marker-position start-top-2
)
2676 (marker-position end-top-2
) (marker-position start-top-2
)))
2677 (should (markdown-test-check-match-limits
2678 'markdown-tilde-fence-begin
3 (marker-position start-lang-2
)
2679 (marker-position end-lang-2
) (marker-position start-lang-2
)))
2680 (should (markdown-test-check-match-limits
2681 'markdown-fenced-code
0 (marker-position start-mid-2
)
2682 (marker-position end-mid-2
) (marker-position start-mid-2
)))
2683 (should (markdown-test-check-match-limits
2684 'markdown-tilde-fence-end
1 (marker-position start-bottom-2
)
2685 (marker-position end-bottom-2
) (marker-position start-bottom-2
)))
2686 ;; ;; Move point between code blocks and insert a character
2689 ;; Re-propertize region after change
2690 (let ((range (markdown-syntax-propertize-extend-region (1- between
) (point-max))))
2691 (markdown-syntax-propertize (car range
) (cdr range
)))
2692 ;; Re-check first code block
2693 (should (markdown-test-check-match-limits
2694 'markdown-tilde-fence-begin
1 (marker-position start-top-1
)
2695 (marker-position end-top-1
) (marker-position start-top-1
)))
2696 (should (markdown-test-check-match-limits
2697 'markdown-tilde-fence-begin
3 (marker-position start-lang-1
)
2698 (marker-position end-lang-1
) (marker-position start-lang-1
)))
2699 (should (markdown-test-check-match-limits
2700 'markdown-fenced-code
0 (marker-position start-mid-1
)
2701 (marker-position end-mid-1
) (marker-position start-mid-1
)))
2702 (should (markdown-test-check-match-limits
2703 'markdown-tilde-fence-end
1 (marker-position start-bottom-1
)
2704 (marker-position end-bottom-1
) (marker-position start-bottom-1
)))
2705 ;; Re-check point between code blocks
2706 (should (equal (get-text-property between
'markdown-fenced-code
)
2708 ;; Re-check second code block
2709 (should (markdown-test-check-match-limits
2710 'markdown-tilde-fence-begin
1 (marker-position start-top-2
)
2711 (marker-position end-top-2
) (marker-position start-top-2
)))
2712 (should (markdown-test-check-match-limits
2713 'markdown-tilde-fence-begin
3 (marker-position start-lang-2
)
2714 (marker-position end-lang-2
) (marker-position start-lang-2
)))
2715 (should (markdown-test-check-match-limits
2716 'markdown-fenced-code
0 (marker-position start-mid-2
)
2717 (marker-position end-mid-2
) (marker-position start-mid-2
)))
2718 (should (markdown-test-check-match-limits
2719 'markdown-tilde-fence-end
1 (marker-position start-bottom-2
)
2720 (marker-position end-bottom-2
)
2721 (marker-position start-bottom-2
))))))
2723 (ert-deftest test-markdown-parsing
/propertize-fenced-in-between
()
2724 "Test whether `markdown-syntax-propertize-fenced-block-constructs' handles the
2725 case when it can't propertize both the start and end of a fenced block within a
2726 single pass (the end of the block is past the END argument)."
2727 (markdown-test-string
2731 echo \"Hello, world!\"
2734 (set-text-properties (point-min) (point-max) nil
)
2735 ;; syntax-propertize up to right after hashbang
2736 (markdown-syntax-propertize-fenced-block-constructs (point-min) 21)
2737 ;; ~~~ shell should be propertized, but nothing else
2739 (should (markdown-test-check-match-limits
2740 'markdown-tilde-fence-begin
1 1 4 1))
2742 (should (markdown-test-check-match-limits
2743 'markdown-tilde-fence-begin
3 5 10 5))
2744 ;; middle should not be propertized
2745 (should-not (get-text-property 11 'markdown-fenced-code
))
2746 ;; neither should end
2747 (should-not (get-text-property 43 'markdown-tilde-fence-end
))
2748 (markdown-syntax-propertize-fenced-block-constructs 21 (point-max))
2749 ;; everything should be propertized now
2751 (should (markdown-test-check-match-limits
2752 'markdown-tilde-fence-begin
1 1 4 1))
2753 (should (markdown-test-check-match-limits
2754 'markdown-tilde-fence-begin
3 5 10 5))
2756 (should (markdown-test-check-match-limits 'markdown-fenced-code
0 10 43 10))
2757 ;; check ending tildes
2758 (should (markdown-test-check-match-limits
2759 'markdown-tilde-fence-end
1 43 46 43))))
2761 (ert-deftest test-markdown-parsing
/get-code-block-at-pos
()
2762 "Test whether `markdown-code-block-at-pos' works in all situations. All
2767 4. yaml metadata block"
2768 (let ((markdown-use-pandoc-style-yaml-metadata t
))
2769 (markdown-test-string
2786 more preformatted code
2792 ;; start/mid/end at tilde block
2793 (should (equal (markdown-code-block-at-pos 2) (list 2 30)))
2794 (should (equal (markdown-code-block-at-pos 11) (list 2 30)))
2795 (should (equal (markdown-code-block-at-pos 27) (list 2 30)))
2796 ;; yaml metadata block
2797 (should (equal (markdown-code-block-at-pos 32) (list 32 44)))
2798 (should (equal (markdown-code-block-at-pos 36) (list 32 44)))
2799 (should (equal (markdown-code-block-at-pos 41) (list 32 44)))
2801 (should (equal (markdown-code-block-at-pos 46) (list 46 80)))
2802 (should (equal (markdown-code-block-at-pos 58) (list 46 80)))
2803 (should (equal (markdown-code-block-at-pos 77) (list 46 80)))
2805 (should (equal (markdown-code-block-at-pos 82) (list 82 138)))
2806 (should (equal (markdown-code-block-at-pos 99) (list 82 138)))
2807 (should (equal (markdown-code-block-at-pos 137) (list 82 138)))
2808 ;; pandoc yaml metadata block (should work if yaml above works)
2809 (should (equal (markdown-code-block-at-pos 140) (list 140 160)))
2810 (should (equal (markdown-code-block-at-pos 142) (list 140 160)))
2811 (should (equal (markdown-code-block-at-pos 144) (list 140 160)))
2812 (should (equal (markdown-code-block-at-pos 157) (list 140 160)))
2813 (should (equal (markdown-code-block-at-pos 159) (list 140 160))))))
2815 (ert-deftest test-markdown-parsing
/syntax-get-fenced-blocks
()
2816 "Test whether *-get-fenced-block-* functions work in the case where a block is
2817 only partially propertized."
2819 (markdown-test-string
2822 (should (equal (markdown-syntax-propertize-extend-region
2823 (point-min) (point-max))
2826 (set-match-data (markdown-text-property-at-point
2827 'markdown-tilde-fence-begin
))
2828 (should (equal (markdown-get-fenced-block-from-start
2829 'markdown-tilde-fence-begin
)
2831 (markdown-test-string
2835 (set-match-data (markdown-text-property-at-point
2836 'markdown-tilde-fence-begin
))
2837 (should (equal (markdown-get-fenced-block-from-start
2838 'markdown-tilde-fence-begin
)
2840 (should (equal (markdown-code-block-at-point) (list 1 8)))
2842 ;; markdown-code-block-at-point-p should not modify match data
2843 (set-match-data (list 1 2 3 4))
2844 (should (markdown-code-block-at-point-p))
2845 (should (equal (match-data) (list 1 2 3 4)))
2848 (set-match-data (markdown-text-property-at-point
2849 'markdown-tilde-fence-end
))
2850 (should (equal (markdown-get-fenced-block-from-end
2851 'markdown-tilde-fence-end
)
2853 (should (equal (markdown-code-block-at-point) (list 1 8))))
2854 (markdown-test-string
2859 (set-match-data (markdown-text-property-at-point
2860 'markdown-tilde-fence-begin
))
2861 (should (equal (markdown-get-fenced-block-from-start
2862 'markdown-tilde-fence-begin
)
2864 (should (equal (markdown-code-block-at-point) (list 1 9)))
2866 (set-match-data (markdown-text-property-at-point 'markdown-fenced-code
))
2867 (should (equal (markdown-get-fenced-block-from-middle
2868 'markdown-fenced-code
)
2870 (should (equal (markdown-code-block-at-point) (list 1 9)))
2872 (set-match-data (markdown-text-property-at-point
2873 'markdown-tilde-fence-end
))
2874 (should (equal (markdown-get-fenced-block-from-end
2875 'markdown-tilde-fence-end
)
2877 (should (equal (markdown-code-block-at-point) (list 1 9))))))
2879 (ert-deftest test-markdown-parsing
/reference-definition-basic
()
2880 "Test reference definition function."
2881 (markdown-test-file "syntax.text"
2882 ;; Test accuracy of returned text and bounds
2883 (should (equal (markdown-reference-definition "1")
2884 (list "http://docutils.sourceforge.net/mirror/setext.html" 1942 1992)))
2885 (should (equal (markdown-reference-definition "2")
2886 (list "http://www.aaronsw.com/2002/atx/" 2000 2032)))
2887 ;; Test that match data remains intact
2888 (should (string-equal (match-string 5) "http://www.aaronsw.com/2002/atx/"))
2889 ;; Test anchor-only relative URL
2890 (should (equal (markdown-reference-definition "bq")
2891 (list "#blockquote" 7536 7547)))
2892 ;; Example references that appear in pre blocks in the text
2893 (should (not (markdown-reference-definition "")))
2894 (should (not (markdown-reference-definition "id")))
2895 (should (not (markdown-reference-definition "foo")))
2896 (should (not (markdown-reference-definition "A")))
2897 (should (not (markdown-reference-definition "Google")))
2898 ;; Test that we don't pick up other text in square brackets
2899 (should (not (markdown-reference-definition "blockquoting")))
2900 (should (not (markdown-reference-definition "square brackets")))
2901 ;; Test case insensitivity
2902 (should (equal (markdown-reference-definition "SRC")
2903 (list "/projects/markdown/syntax.text" 1245 1275)))))
2905 (ert-deftest test-markdown-parsing
/get-defined-references
()
2906 "Test `markdown-get-defined-references'."
2907 (markdown-test-file "syntax.text"
2908 (should (equal (markdown-get-defined-references)
2909 '("src" "1" "2" "3" "4" "5" "6" "bq" "l"))))
2910 (markdown-test-file "outline.text"
2911 (should (equal (markdown-get-defined-references) nil
)))
2912 (markdown-test-file "wiki-links.text"
2913 (should (equal (markdown-get-defined-references) nil
))))
2915 (defun markdown-test-test-region (beg end
)
2916 (goto-char (1- beg
))
2917 (should-not (markdown-inline-code-at-point-p))
2918 (goto-char (1+ end
))
2919 (should-not (markdown-inline-code-at-point-p))
2920 (dolist (loc (number-sequence beg end
))
2922 (should (markdown-inline-code-at-point))
2923 (should (equal (match-beginning 0) beg
))
2924 (should (equal (match-end 0) end
))))
2926 (ert-deftest test-markdown-parsing
/inline-code-at-point
()
2927 "Test `markdown-inline-code-at-point'."
2928 (markdown-test-file "inline.text"
2929 (markdown-test-test-region 45 51) ; Regular code span
2930 (markdown-test-test-region 61 90) ; Code containing backticks
2931 (markdown-test-test-region 228 240) ; Backquotes at beginning
2932 (markdown-test-test-region 341 352) ; Backquotes at end
2933 (markdown-test-test-region 460 469) ; Backslash as final character
2934 (markdown-test-test-region 657 667) ; A code span crossing lines
2935 (markdown-test-test-region 749 758) ; Three backquotes on same line
2936 (markdown-test-test-region 806 815) ; Three backquotes across lines
2939 (ert-deftest test-markdown-parsing
/inline-code-at-point-one-space
()
2940 "Test `markdown-inline-code-at-point' with multiple code spans in a row."
2941 (markdown-test-string "`foo` `bar` `baz`"
2942 (dolist (loc (number-sequence 1 6))
2944 ;; markdown-inline-code-at-point should set match data
2945 (should (markdown-inline-code-at-point))
2946 (should (equal (match-data) (list 1 6 1 2 2 5 5 6)))
2947 ;; markdown-inline-code-at-point-p should not modify match data
2948 (set-match-data (list 1 2 3 4))
2949 (should (markdown-inline-code-at-point-p))
2950 (should (equal (match-data) (list 1 2 3 4))))
2951 (dolist (loc (number-sequence 7 12))
2953 (should (markdown-inline-code-at-point))
2954 (should (equal (match-data) (list 7 12 7 8 8 11 11 12))))
2955 (dolist (loc (number-sequence 13 18))
2957 (should (markdown-inline-code-at-point))
2958 (should (equal (match-data) (list 13 18 13 14 14 17 17 18))))))
2960 (ert-deftest test-markdown-parsing
/inline-code-at-point-no-space
()
2961 "Test `markdown-inline-code-at-point' with multiple code spans in a row.."
2962 (markdown-test-string "a`foo`b`bar`c`baz`d"
2964 (should-not (markdown-inline-code-at-point-p))
2965 (dolist (loc (number-sequence 2 7)) ; "`foo`b"
2967 (should (markdown-inline-code-at-point))
2968 (should (equal (match-data) (list 2 7 2 3 3 6 6 7))))
2969 (dolist (loc (number-sequence 8 13)) ; "`bar`c"
2971 (should (markdown-inline-code-at-point))
2972 (should (equal (match-data) (list 8 13 8 9 9 12 12 13))))
2973 (dolist (loc (number-sequence 14 19)) ; "`baz`d"
2975 (should (markdown-inline-code-at-point))
2976 (should (equal (match-data) (list 14 19 14 15 15 18 18 19))))))
2978 (ert-deftest test-markdown-parsing
/code-at-point-blank-line
()
2979 "Test `markdown-inline-code-at-point-p' at beginning of block."
2980 (markdown-test-string "----------\n\n## foo\n"
2981 (should-not (markdown-inline-code-at-point-p))
2983 (should-not (markdown-inline-code-at-point-p))
2985 (should-not (markdown-inline-code-at-point-p))))
2987 (ert-deftest test-markdown-parsing
/match-comments
()
2988 "Test `markdown-match-comments'."
2989 (markdown-test-string
2990 "HTML <!-- foo --> comment"
2991 (should (markdown-match-comments (point-max)))
2992 (should (eq (point) 18))
2993 (should (equal (match-data) (list 6 18)))
2994 (should-not (markdown-match-comments (point-max)))))
2996 (ert-deftest test-markdown-parsing
/range-property-any
()
2997 "Test behavior of `markdown-range-property-any'."
3000 (should (markdown-range-property-any
3001 (point-min) (point-at-eol)
3002 'face
(list markdown-markup-face
3003 markdown-italic-face
)))
3004 (should-not (markdown-range-property-any
3005 (point-min) (point-at-eol)
3006 'face
(list markdown-bold-face
)))))
3008 (ert-deftest test-markdown-parsing
/inline-code
()
3009 "Don't cause infinite loop for inline code just after metadata block
3010 Detail: https://github.com/jrblevin/markdown-mode/issues/115"
3011 (markdown-test-string "---
3016 (should (= (markdown-match-code (point-max)) (point-max)))))
3018 ;;; Reference Checking:
3020 (ert-deftest test-markdown-references
/goto-line-button
()
3021 "Create and test a goto line button."
3022 (markdown-test-string "line 1\nline 2\n"
3023 ;; Store the temporary buffer with the text
3024 (let ((target (current-buffer)))
3025 ;; Create a new buffer for inserting
3027 ;; Verify that point is in a different buffer
3028 (should (not (equal (current-buffer) target
)))
3029 ;; Insert and press the button
3030 (insert-button "goto line 2"
3031 :type
'markdown-goto-line-button
3032 'target-buffer target
3034 (should (string-equal (buffer-string) "goto line 2"))
3036 (call-interactively 'push-button
)
3037 ;; Verify that point is on line 2 of target buffer
3038 (should (= (line-number-at-pos) 2))
3039 (should (looking-at "line 2"))
3040 (should (equal (current-buffer) target
))))))
3042 (ert-deftest test-markdown-references
/button-map
()
3043 "Verify that button-buffer-map is used for check references buffer."
3044 (markdown-test-string "[undefined][ref]\n"
3045 (let* ((target (buffer-name))
3046 (check (format "*Undefined references for %s*" target
)))
3047 (markdown-check-refs)
3048 (with-current-buffer (get-buffer check
)
3049 (should (equal (local-key-binding (kbd "TAB")) 'forward-button
))
3050 (should (equal (local-key-binding (kbd "<backtab>")) 'backward-button
))))))
3054 (ert-deftest test-markdown-lists
/levels-1
()
3055 "Test list levels function `markdown-calculate-list-levels'."
3056 (markdown-test-file "nested-list.text"
3057 (let ((values '(((1 .
1) . nil
) ((2 .
13) .
(3)) ((14 .
23) .
(7 3))
3058 ((24 .
26) .
(11 7 3)))))
3059 (cl-loop for
(range . value
) in values
3060 do
(goto-char (point-min))
3061 (forward-line (1- (car range
)))
3062 (dotimes (n (- (cdr range
) (car range
)))
3063 (should (equal (markdown-calculate-list-levels) value
))
3066 (ert-deftest test-markdown-lists
/levels-2
()
3067 "Test list levels function `markdown-calculate-list-levels'."
3068 (markdown-test-file "syntax.text"
3069 (let ((values '(((1 .
13) . nil
) ((14 .
14) .
(0)) ((15 .
17) .
(4 0))
3070 ((18 .
18) .
(0)) ((19 .
24) .
(4 0)) ((25 .
25) .
(0))
3071 ((26 .
29) .
(4 0)) ((30 .
30) .
(0)) ((31 .
33) .
(4 0))
3072 ((34 .
588) . nil
) ((589 .
595) .
(0)) ((596 .
814) . nil
)
3073 ((815 .
820) .
(0)) ((821 .
898) . nil
))))
3074 (cl-loop for
(range . value
) in values
3075 do
(goto-char (point-min))
3076 (forward-line (1- (car range
)))
3077 (dotimes (n (- (cdr range
) (car range
)))
3078 (should (equal (markdown-calculate-list-levels) value
))
3081 (ert-deftest test-markdown-lists
/levels-interior
()
3082 "Test `markdown-calculate-list-levels' from inside a list item."
3083 (markdown-test-file "nested-list.text"
3085 (should (equal (markdown-calculate-list-levels) (list 3)))
3087 (should (equal (markdown-calculate-list-levels) (list 7 3)))
3089 (should (equal (markdown-calculate-list-levels) (list 11 7 3)))))
3091 (ert-deftest test-markdown-lists
/bounds-1
()
3092 "Test list item bounds function `markdown-cur-list-item-bounds'."
3093 (markdown-test-file "lists.text"
3094 (markdown-test-goto-heading "Case 9")
3096 (should (eq (point) 3699))
3097 (markdown-next-list-item 4)
3098 (should (eq (point) 3700))
3099 (should (equal (markdown-cur-list-item-bounds)
3100 (list 3700 3901 0 4 "- ")))
3101 (markdown-next-list-item 4)
3102 (should (eq (point) 3903))
3103 (should (equal (markdown-cur-list-item-bounds)
3104 (list 3903 3937 0 4 "* ")))))
3106 (ert-deftest test-markdown-lists
/bounds-2
()
3107 "Function `markdown-cur-list-item-bounds' should return nil outside of list items."
3108 (markdown-test-string "line one\n\n* item\n"
3109 (should (null (markdown-cur-list-item-bounds)))
3111 (should (null (markdown-cur-list-item-bounds)))
3113 (should (markdown-cur-list-item-bounds))))
3115 (ert-deftest test-markdown-lists
/promotion-and-demotion
()
3116 "Test function `markdown-promote-list-item'."
3117 (markdown-test-file "nested-list.text"
3119 (should (looking-at " - List level 1 item 2
3121 Second paragraph of item 2
3123 Nested pre block in item 2
3124 Four spaces past the marker
3126 Another paragraph of item 2"))
3127 (markdown-demote-list-item)
3128 (should (looking-at " - List level 1 item 2
3130 Second paragraph of item 2
3132 Nested pre block in item 2
3133 Four spaces past the marker
3135 Another paragraph of item 2"))
3136 (markdown-promote-list-item)
3137 (should (looking-at " - List level 1 item 2
3139 Second paragraph of item 2
3141 Nested pre block in item 2
3142 Four spaces past the marker
3144 Another paragraph of item 2"))
3145 (goto-char (point-min))
3147 (should (looking-at " - List level 3 item 1
3150 (markdown-demote-list-item)
3151 (should (looking-at " - List level 3 item 1
3154 (markdown-promote-list-item)
3155 (should (looking-at " - List level 3 item 1
3157 Nested pre block"))))
3159 (ert-deftest test-markdown-lists
/promotion-and-demotion-custom
()
3160 "Test custom variable `markdown-list-indent-width'."
3161 (markdown-test-file "nested-list.text"
3163 (should (looking-at " - List level 1 item 2
3165 Second paragraph of item 2
3167 Nested pre block in item 2
3168 Four spaces past the marker
3170 Another paragraph of item 2"))
3171 (let ((markdown-list-indent-width 2))
3172 (markdown-demote-list-item))
3173 (should (looking-at " - List level 1 item 2
3175 Second paragraph of item 2
3177 Nested pre block in item 2
3178 Four spaces past the marker
3180 Another paragraph of item 2"))))
3182 (ert-deftest test-markdown-lists
/toggle-gfm-checkbox
()
3183 (markdown-test-string " - [X] GFM task list item"
3184 (markdown-toggle-gfm-checkbox)
3185 (should (string-equal (buffer-string) " - [ ] GFM task list item"))
3186 (markdown-toggle-gfm-checkbox)
3187 (should (string-equal (buffer-string) " - [x] GFM task list item"))))
3189 ;;; Outline minor mode tests:
3191 (ert-deftest test-markdown-outline
/navigation
()
3192 "Test outline navigation functions."
3193 (markdown-test-file "outline.text"
3194 ;; Navigate to the first visible heading
3195 (markdown-next-visible-heading 1)
3196 (should (eq (point) 19))
3197 (should (looking-at "^# A top-level header"))
3198 ;; Navigate forward at the same level
3199 (markdown-forward-same-level 1)
3200 (should (eq (point) 377))
3201 (should (looking-at "^=+$"))
3202 ;; Navigate backward by four visible headings
3203 (markdown-previous-visible-heading 4)
3204 (should (eq (point) 69))
3205 (should (looking-at "^## A second-level header$"))
3206 ;; Navigate up the hierarchy (atx)
3207 (call-interactively #'markdown-up-heading
)
3208 (should (looking-at "^# A top-level header"))
3209 (should (eq (mark) 69))
3210 ;; Navigate up the hierarchy (setext)
3212 (call-interactively #'markdown-up-heading
)
3213 (should (looking-at "^An underline-style header$"))
3214 (should (eq (mark) 516))))
3216 (ert-deftest test-markdown-outline
/navigation-with-code
()
3217 "Test outline navigation functions with code blocks."
3218 (markdown-test-file "outline-code.text"
3219 ;; Navigate forward at the same level
3220 (markdown-forward-same-level 1)
3221 (should (eq (point) 159))
3222 (should (looking-at "^# Level one again"))))
3224 (ert-deftest test-markdown-outline
/visibility-atx
()
3225 "Test outline visibility cycling for ATX-style headers."
3226 (markdown-test-file "outline.text"
3227 (let (last-command this-command
)
3228 ;; Navigate to the second visible heading
3229 (markdown-next-visible-heading 2)
3230 (should (eq (point) 69))
3231 (should (looking-at "^## A second-level header$"))
3232 ;; Cycle visibility of this subtree
3233 (setq this-command
'markdown-cycle
)
3235 (setq last-command
'markdown-cycle
)
3236 (should (eq (point) 69))
3237 (should (looking-at "^## A second-level header$"))
3238 ;; Test that the entire subtree is invisible
3239 (markdown-test-range-has-property 93 349 'invisible
'outline
)
3240 ;; Cycle visibility of this subtree again
3242 (should (eq (point) 69))
3243 (should (looking-at "^## A second-level header$"))
3244 ;; Test that text is visible
3245 (markdown-test-range-has-property 95 121 'invisible nil
)
3246 ;; Test that subheadings are visible
3247 (markdown-test-range-has-property 123 141 'invisible nil
)
3248 ;; Cycle visibility of this subtree again
3250 (should (eq (point) 69))
3251 (should (looking-at "^## A second-level header$"))
3252 ;; Verify that entire subtree is visible
3253 (markdown-test-range-has-property 93 349 'invisible nil
))))
3255 (ert-deftest test-markdown-outline
/visibility-setext
()
3256 "Test outline visibility cycling for setext-style headers."
3257 (markdown-test-file "outline.text"
3258 ;; Navigate to the sixth visible heading
3259 (markdown-next-visible-heading 7)
3260 (markdown-previous-visible-heading 1)
3261 (should (looking-at markdown-regex-header
))
3262 (should (string-equal (match-string-no-properties 1) "An underline-style header"))
3263 (should (string-equal (match-string-no-properties 2) "========================="))
3264 ;; Cycle visibility subtree, test that it's invisible
3266 (markdown-test-range-has-property 404 515 'invisible
'outline
)
3267 ;; Cycle visibility subtree, test that text and headers are visible
3269 (markdown-test-range-has-property 404 417 'invisible nil
)
3270 (markdown-test-range-has-property 420 451 'invisible nil
)))
3272 (ert-deftest test-markdown-outline
/visibility-with-code
()
3273 "Test outline visibility cycling with code blocks."
3274 (markdown-test-file "outline-code.text"
3275 (let (last-command this-command
)
3276 ;; Cycle global visibility to "overview" mode
3277 (setq this-command
'markdown-cycle
)
3279 (setq last-command
'markdown-cycle
)
3280 (should (eq (point) (point-min)))
3281 (should (looking-at "^# Level one"))
3282 ;; Test that the code block is invisible
3283 (markdown-test-range-has-property 83 157 'invisible
'outline
)
3284 ;; Check subsequent headings
3285 (outline-next-visible-heading 1)
3286 (should (eq (point) 69))
3287 (should (looking-at "^## Level two"))
3288 (outline-next-visible-heading 1)
3289 (should (eq (point) 159))
3290 (should (looking-at "^# Level one again")))))
3292 (ert-deftest test-markdown-outline
/visibility-with-metadata
()
3293 "Test outline visibility cycling with metadata blocks."
3294 (markdown-test-string
3297 date = 2015-08-13 11:35:25 EST
3300 (let (last-command this-command
)
3301 ;; Cycle global visibility to "overview" mode
3302 (setq this-command
'markdown-cycle
)
3304 ;; Check that text is visible
3305 (markdown-test-range-has-property (point-min) (point-max) 'invisible nil
))))
3307 (ert-deftest test-markdown-outline
/level
()
3308 "Test `markdown-outline-level'."
3309 (markdown-test-file "outline.text"
3310 (markdown-next-heading)
3311 (should (= (markdown-outline-level) 1))
3312 (markdown-forward-same-level 1)
3313 (should (= (markdown-outline-level) 1))
3314 (markdown-next-heading)
3315 (should (= (markdown-outline-level) 2))
3316 (markdown-next-heading)
3317 (should (= (markdown-outline-level) 1))
3318 (markdown-next-heading)
3319 (should (= (markdown-outline-level) 2))))
3323 (ert-deftest test-markdown-movement
/defun
()
3324 "Test defun navigation."
3325 (markdown-test-file "outline.text"
3326 ;; end-of-defun should go to point-max
3328 (should (= (point) (point-max)))
3329 ;; end-of-defun should stop just before the next header
3330 (goto-char (point-min))
3332 (should (looking-at "\n# A top-level header"))
3334 (should (looking-at "\n## A second-level header"))
3336 (should (looking-at "\n### Third level ###"))
3338 (should (looking-at "\n### Third level number two ###"))
3339 ;; beginning-of-defun should move to the start of the previous header
3340 (beginning-of-defun)
3341 (should (looking-at "### Third level ###"))
3342 (beginning-of-defun)
3343 (should (looking-at "## A second-level header"))
3344 (beginning-of-defun)
3345 (should (looking-at "# A top-level header"))
3346 (beginning-of-defun)
3347 ;; beginning-of-defun should move up to point-min
3348 (should (= (point) (point-min)))
3349 ;; (beginning-of-defun -1) should move to the start of the next header
3351 (beginning-of-defun -1)
3352 (should (looking-at "## A second-level header"))
3353 (beginning-of-defun -1)
3354 (should (looking-at "### Third level ###"))
3355 (beginning-of-defun -1)
3356 (should (looking-at "### Third level number two ###"))))
3358 (ert-deftest test-markdown-movement
/block
()
3359 "Test block movement."
3360 (markdown-test-file "outline.text"
3361 (markdown-end-of-block)
3362 (should (looking-at "\n# A top-level header"))
3363 (markdown-end-of-block)
3364 (should (looking-at "\nfollowed by some body text"))
3365 (markdown-end-of-block)
3366 (should (looking-at "\n## A second-level header"))
3367 (markdown-end-of-block)
3368 (should (looking-at "\nfollowed by some body text"))
3369 (markdown-end-of-block)
3370 (should (looking-at "\n### Third level ###"))
3371 (markdown-end-of-block)
3372 (should (looking-at "\n\\* A list item"))
3373 (markdown-end-of-block)
3374 (should (looking-at "\n### Third level number two ###"))
3375 (markdown-end-of-block)
3376 (should (looking-at "\n### Level two again"))
3377 (markdown-end-of-block)
3378 (should (looking-at "\nfollowed by some body text"))
3380 (markdown-test-goto-heading "Level two")
3381 (markdown-end-of-block)
3382 (should (looking-at "\nbar"))
3383 (markdown-end-of-block)
3384 (should (= (point) (point-max)))
3385 (markdown-beginning-of-block)
3386 (should (looking-at "bar"))
3387 (markdown-beginning-of-block)
3388 (should (looking-at "## Level two"))
3389 (markdown-beginning-of-block)
3390 (should (looking-at "foo"))
3391 (markdown-beginning-of-block)
3392 (should (looking-at "# Level one"))
3393 (markdown-beginning-of-block)
3394 (should (looking-at "* With"))
3395 (markdown-beginning-of-block)
3396 (should (looking-at "And a level two underline header"))
3398 (goto-char (point-min))
3399 (markdown-test-goto-heading "A top-level header")
3401 (markdown-beginning-of-block)
3402 (should (= (point) (point-min)))))
3404 (ert-deftest test-markdown-movement
/blockquote-paragraphs
()
3405 "Test filling of blockquotes containing multiple paragraphs."
3406 (markdown-test-string "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n>\n> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n"
3408 (should (looking-at "^>$"))
3409 (should (= (point) 128))
3411 (should (= (point) (point-max)))))
3413 (ert-deftest test-markdown-movement
/reference-definition
()
3414 "Test jumping to reference definitions."
3415 ;; Jumping to explicit reference definition
3416 (markdown-test-string "[a][ref]\n\n[ref]: gopher://localhost/\n"
3417 (markdown-reference-goto-definition)
3418 (should (= (point) 18)))
3419 ;; Jumping to implicit reference definition
3420 (markdown-test-string "[a][]\n\n[a]: ftp://localhost/\n"
3421 (markdown-reference-goto-definition)
3422 (should (= (point) 13)))
3423 ;; Creating non-existent reference definition
3424 (markdown-test-string "[a][]\n"
3425 (markdown-reference-goto-definition)
3426 (should (= (point) 13))
3427 (should (string-equal (buffer-string) "[a][]\n\n[a]: \n"))))
3429 (ert-deftest test-markdown-movement
/back-to-same-level-over-code-block
()
3430 "`markdown-backward-same-level' over code block which contains header
3431 like statement. Detail: https://github.com/jrblevin/markdown-mode/issues/75"
3432 (markdown-test-string "
3438 # Header Like Statement
3443 (search-forward "## Header 2-3")
3444 (let ((last-header-pos (point)))
3446 (call-interactively #'markdown-backward-same-level
)
3447 (should (looking-at-p "## Header 2-1"))
3449 (goto-char last-header-pos
)
3450 (call-interactively #'markdown-backward-same-level
)
3451 (should (looking-at-p "## Header 2-2"))
3453 (goto-char last-header-pos
)
3454 (markdown-backward-same-level 2)
3455 (should (looking-at-p "## Header 2-1"))
3457 (search-forward "# Header Like Statement")
3458 (call-interactively #'markdown-backward-same-level
)
3459 (should (looking-at-p "## Header 2-1")))))
3463 (ert-deftest test-markdown-link
/follow
()
3464 "Test link following in a browser and in Emacs."
3465 (markdown-test-string "[text](http://path?query=foo#id)"
3466 (let* ((opened-url nil
)
3467 (browse-url-browser-function
3468 (lambda (url &rest args
) (setq opened-url url
))))
3469 (markdown-follow-thing-at-point nil
)
3470 (should (equal opened-url
"http://path?query=foo#id"))))
3471 (when (featurep 'url-parse
)
3472 (markdown-test-string "[text](path?query=foo#id)"
3473 (markdown-follow-thing-at-point nil
)
3474 (should (equal (file-name-nondirectory (buffer-file-name)) "path"))
3477 ;;; Wiki link tests:
3479 (ert-deftest test-markdown-wiki-link
/file-local-variables
()
3480 "Test enabling wiki links via file-local variables."
3481 (markdown-test-file "wiki-links.text"
3482 (should-not markdown-enable-wiki-links
)
3483 (hack-local-variables)
3484 (should markdown-enable-wiki-links
)))
3486 (ert-deftest test-markdown-wiki-link
/aliasing
()
3487 "Test filename extraction for aliased wiki links."
3488 (let ((markdown-enable-wiki-links t
))
3489 (markdown-test-file "wiki-links.text"
3490 ;; Confirm location of first wiki link
3491 (should (eq (markdown-next-link) 8))
3492 ;; Confirm location of second wiki link
3493 (should (eq (markdown-next-link) 73))
3494 ;; Test predicate function
3495 (should (markdown-wiki-link-p))
3496 ;; Test alias-first filename extraction
3497 (setq markdown-wiki-link-alias-first t
)
3498 (should (string-equal (markdown-wiki-link-link) "second"))
3499 ;; Test alias-second filename extraction
3500 (setq markdown-wiki-link-alias-first nil
)
3501 (should (string-equal (markdown-wiki-link-link) "first")))))
3503 (ert-deftest test-markdown-wiki-link
/navigation
()
3504 "Test wiki link navigation."
3505 (let ((markdown-enable-wiki-links t
))
3506 (markdown-test-file "wiki-links.text"
3507 ;; Advance to first link
3508 (should (eq (markdown-next-link) 8))
3509 ;; Advance to second link
3510 (should (eq (markdown-next-link) 73))
3511 ;; Avance to final link
3512 (should (eq (markdown-next-link) 155))
3513 ;; Return nil and don't advance point
3514 (should (eq (markdown-next-link) nil
))
3515 (should (eq (point) 155))
3516 ;; Move back to second link
3517 (should (eq (markdown-previous-link) 73))
3518 ;; Move back to first link
3519 (should (eq (markdown-previous-link) 8))
3520 ;; Return nil and don't move point
3521 (should (eq (markdown-previous-link) nil
))
3522 (should (eq (point) 8)))))
3524 (ert-deftest test-markdown-wiki-link
/font-lock
()
3525 "Test font lock faces for wiki links."
3526 (markdown-test-temp-file "wiki-links.text"
3527 (let* ((fn (concat (file-name-directory buffer-file-name
)
3529 (markdown-enable-wiki-links t
))
3530 ;; Create inline.text in the same temp directory, refontify
3531 (write-region "" nil fn nil
1)
3532 (markdown-fontify-buffer-wiki-links)
3533 ;; Confirm location of first wiki link
3534 (should (eq (markdown-next-link) 8))
3535 ;; First wiki link doesn't have a corresponding file
3536 (markdown-test-range-has-property 8 20 'font-lock-face markdown-missing-link-face
)
3537 ;; Second wiki link doesn't have a corresponding file
3538 (should (eq (markdown-next-link) 73))
3539 (markdown-test-range-has-property 73 88 'font-lock-face markdown-missing-link-face
)
3540 ;; Move to third wiki link, and create the missing file
3541 (should (eq (markdown-next-link) 155))
3542 (should (string-equal (markdown-wiki-link-link) "inline"))
3543 (markdown-test-range-has-property 155 164 'font-lock-face markdown-link-face
)
3544 ;; Check wiki links in code blocks
3545 (markdown-test-range-has-face 360 395 markdown-pre-face
)
3546 ;; Remove temporary files
3550 (ert-deftest test-markdown-wiki-link
/kill
()
3551 "Simple tests for `markdown-kill-thing-at-point' for wiki links."
3552 (let ((kill-ring nil
)
3553 (markdown-enable-wiki-links t
)
3554 (tests (list '("[[foo]]" .
"foo")
3555 '("[[foo|bar]]" .
"bar"))))
3556 (dolist (test tests
)
3557 ;; Load test string (the car), move to end of first line, kill
3558 ;; thing at point, and then verify that the kill ring contains cdr.
3559 (markdown-test-string (car test
)
3561 (call-interactively 'markdown-kill-thing-at-point
)
3562 (should (string-equal (current-kill 0) (cdr test
)))))))
3566 (ert-deftest test-markdown-filling
/blockquote
()
3567 "Test filling of blockquotes.
3568 See `adaptive-fill-first-line-regexp'."
3569 (markdown-test-string "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
3571 (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."))))
3573 (ert-deftest test-markdown-filling
/blockquote-paragraphs
()
3574 "Test filling of blockquotes containing multiple paragraphs."
3575 (markdown-test-string "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n>\n> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n"
3578 (should (string-equal (buffer-string) "> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n>\n> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n> nisi ut aliquip ex ea commodo consequat.\n"))))
3580 (ert-deftest test-markdown-filling
/space-after-list-marker
()
3581 "`fill-paragraph' should preserve more than one space after a list marker,
3582 since users may wish to indent their lists more than one space more than the
3583 width of the marker. The examples on the Markdown Syntax page have three
3584 spaces after the list marker for a total indentation of four."
3585 (let ((str "\n\n* List item indented four spaces.\n* Also four spaces."))
3586 (markdown-test-string str
3589 (should (string-equal (buffer-string) str
)))))
3591 (ert-deftest test-markdown-filling
/multi-line-list-with-more-space
()
3592 "`fill-paragraph' should preserve more than one space after a list marker
3593 (see `test-preserve-space-after-list-marker')."
3594 (let ((str "* This list item is continued on\n the next line"))
3595 (markdown-test-string str
3596 ;; The first line is exactly 35 columns
3597 (let ((fill-column 35))
3599 (should (string-equal (buffer-string) str
))))))
3601 (ert-deftest test-markdown-filling
/definition-list-add-leading-spaces
()
3602 "`fill-paragraph' should adapt to spaces after list marker."
3603 (markdown-test-string
3604 ": This list item is continued on the next line"
3605 (let ((fill-column 35))
3607 (should (string-equal
3609 ": This list item is continued on\n the next line")))))
3611 (ert-deftest test-markdown-filling
/definition-list-preserve-leading-spaces
()
3612 "`fill-paragraph' should preserve spaces after list marker."
3613 (let ((str ": This list item is continued on\n the next line")
3615 (markdown-test-string
3616 str
(fill-paragraph)
3617 (should (string-equal (buffer-string) str
)))))
3619 (ert-deftest test-markdown-filling
/list-item-plus
()
3620 "Test filling of list items with plus sign markers.
3621 See `adaptive-fill-regexp'."
3622 (markdown-test-string " + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
3624 (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."))))
3626 (ert-deftest test-markdown-filling
/list-item-plus-in-blockquote
()
3627 "Test filling of list items with plus sign markers inside blockquote.
3628 See `adaptive-fill-regexp'."
3629 (markdown-test-string "> + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
3631 (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."))))
3633 (ert-deftest test-markdown-filling
/line-break
()
3634 "Test filling of paragraphs with hard line breaks.
3635 See `paragraph-separate'."
3636 (markdown-test-string "Lorem ipsum dolor sit amet, \nconsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
3637 (let ((fill-column 70))
3639 (should (string-equal (buffer-string) "Lorem ipsum dolor sit amet, \nconsectetur adipisicing elit, sed do eiusmod tempor incididunt ut\nlabore et dolore magna aliqua.")))))
3641 (ert-deftest test-markdown-filling
/decimal-number-at-beginning
()
3642 "Test filling when a number with a decimal appears at the beginning of a line."
3643 (markdown-test-string "The circumference of a circle divided by it's radius is around\n3.14."
3645 (should (string-equal (buffer-string) "The circumference of a circle divided by it's radius is around 3.14."))))
3647 (ert-deftest test-markdown-filling
/avoid-unintended-list-item
()
3648 "Avoid breaking lines where it would result in an unintended list item."
3649 (markdown-test-string "Lorem ipsum dolor sit 4. amet"
3650 (let ((fill-column 22))
3652 (should (string-equal (buffer-string) "Lorem ipsum dolor\nsit 4. amet")))))
3654 (ert-deftest test-markdown-filling
/no-break-link-reference
()
3655 "Shouldn't break line between label and url, or combine two link references."
3656 (let ((str "[label1]: http://long-url.example.com\n[label2]: http://another-long-url.example.com/"))
3657 (markdown-test-string str
3658 (let ((fill-column 15)) ; after end of label, before end of URL
3660 (should (string-equal (buffer-string) str
))))))
3662 (ert-deftest test-markdown-filling
/no-break-before-list-item
()
3663 "There's no point in putting the first item of a list on the next line,
3664 indented the same amount."
3665 :expected-result
:failed
3666 (let ((str "* [Link](http://way-too-long.example.com)\n"))
3667 (markdown-test-string str
3669 (let ((fill-column 10))
3671 (funcall auto-fill-function
)
3672 (should (string-equal (buffer-string) str
))))))
3674 (ert-deftest test-markdown-filling
/break-within-list-item
()
3675 "This doesn't suppress auto-fill within a multi-word list item."
3676 :expected-result
:failed
3677 (markdown-test-string "* [Link](http://example.com/) more text"
3679 (let ((fill-column 10))
3681 (funcall auto-fill-function
)
3682 (should (string-equal
3684 "* [Link](http://example.com/)\n more text")))))
3686 (ert-deftest test-markdown-filling
/preserve-next-line-footnote
()
3687 "Footnote block can be after label"
3688 (let ((str "[^label1]:\n Footnote block\n more footnote")) ; six spaces
3689 (markdown-test-string str
3690 (let ((fill-column 20)) ; could fit "footnote" after label, but shouldn't
3692 (should (string-equal (buffer-string) str
))))))
3694 (ert-deftest test-markdown-filling
/wrap-same-line-footnote
()
3695 "Additional lines must be indented one level (four spaces) when wrapped."
3696 (markdown-test-string "[^label]: Long line should be wrapped"
3697 (let ((fill-column 25)) ; wrap before end of "should"
3699 (should (string-equal (buffer-string) "[^label]: Long line\n should be wrapped")))))
3701 (ert-deftest test-markdown-filling
/wrap-extra-hanging-indentation
()
3702 "Additional lines must be indented one level (four spaces) when wrapped."
3703 (markdown-test-string "[^label]: Long line\n should be wrapped"
3704 (let ((fill-column 25)) ; wrap before end of "should"
3706 (should (string-equal (buffer-string) "[^label]: Long line\n should be wrapped")))))
3708 (ert-deftest test-markdown-filling
/full-justification
()
3709 "Test paragraph detection with lines with lots of whitespace."
3710 (markdown-test-string "Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Dolor Sit Amet Consectetur http://very-long-url.lorem.ipsum.sic.dolor.sit.amet.com"
3711 (setq default-justification
'full
)
3713 (should (string-equal (buffer-string) "Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem\nDolor Sit Amet Consectetur\nhttp://very-long-url.lorem.ipsum.sic.dolor.sit.amet.com"))
3714 (backward-paragraph)
3716 (should (= (point) 198))))
3718 (ert-deftest test-markdown-filling
/list-line
()
3719 "Test fill-paragraph for list line. Don't insert bullet automatically.
3720 Detail: https://github.com/jrblevin/markdown-mode/issues/79"
3721 (markdown-test-string "* foo foo *foo* foo foo foo foo foo foo"
3722 (let ((fill-column 10))
3726 (back-to-indentation)
3727 (should-not (looking-at-p "\\*foo"))
3729 (back-to-indentation)
3730 (should-not (looking-at-p "\\*foo")))))
3732 (ert-deftest test-markdown-filling
/ignore-header
()
3733 "# Test fill-paragraph for containing header line paragraph.
3734 https://github.com/jrblevin/markdown-mode/issues/159"
3735 (markdown-test-string "# this is header line
3736 this is not header line
3738 (let ((fill-column 10))
3740 (should (string= (buffer-substring (point) (line-end-position)) "# this is header line")))))
3742 (ert-deftest test-markdown-filling
/unclosed-square-bracket
()
3743 "Test fill-paragraph following an unclosed square bracket."
3744 (markdown-test-string "```\n[3\n```\n\naaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbb"
3745 (let ((fill-column 20))
3748 (should (looking-at "aaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbb")))))
3750 (ert-deftest test-markdown-filling
/skip-code-blocks
()
3751 "Test `markdown-fill-paragraph' on code blocks."
3752 (let ((text "test\n\n```\nhello\nworld\n```"))
3753 (markdown-test-string text
3755 ;; Fill at each line; buffer should not change.
3757 (should (string-equal (buffer-string) text
))))))
3759 (ert-deftest test-markdown-filling
/long-paragraph-with-link
()
3760 "Test `fill-paragraph' on a long paragraph with a long link."
3761 (markdown-test-string
3762 "aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa [aaa aaa aaa aaa](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) aaa aaa aaa aaa aaa."
3764 (should (string-equal (buffer-string) "aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa\naaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa\naaa aaa [aaa aaa aaa aaa](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) aaa\naaa aaa aaa aaa."))))
3768 (ert-deftest test-markdown-hook
/xhtml-standalone
()
3769 "Test `markdown-xhtml-standalone-regexp' and `markdown-output-standalone-p'."
3770 (should (string-match markdown-xhtml-standalone-regexp
3771 "<?xml version='1.0' encoding='UTF-8'?>"))
3772 (should (string-match markdown-xhtml-standalone-regexp
3774 (should (string-match markdown-xhtml-standalone-regexp
3776 (should-not (string-match markdown-xhtml-standalone-regexp
3778 (should-not (string-match markdown-xhtml-standalone-regexp
3779 "<div id=\"name\">")))
3783 (ert-deftest test-markdown-hook
/before-export
()
3784 "Test hook run before export XHTML."
3785 (markdown-test-temp-file "lists.text"
3786 (let* ((before-hook-run nil
)
3787 (orig-point (point))
3789 ;; Change value of a variable
3790 (setq before-hook-run t
)
3792 (goto-char (point-min))
3794 ;; Deliberately move the point
3797 (should (looking-back "^## List Cases" nil
))
3798 (should-not (= (point) orig-point
))))
3801 (add-hook 'markdown-before-export-hook func
)
3802 ;; Export XHTML and return filename
3804 (obuffer (get-file-buffer ofile
)))
3805 ;; Test side effects of hook
3806 (should (eq before-hook-run t
))
3807 ;; Test position of point
3808 (should (= (point) orig-point
))
3809 ;; Test that buffer was restored to original state
3810 (goto-char (point-min))
3811 (should (looking-at "^# List Cases"))
3813 (remove-hook 'markdown-before-export-hook func
)
3814 (kill-buffer obuffer
)
3815 (delete-file ofile
))))
3817 (ert-deftest test-markdown-hook
/after-export
()
3818 "Test hook run after export XHTML."
3819 (markdown-test-temp-file "lists.text"
3820 (let* ((after-hook-run nil
)
3822 ;; Change variable value
3823 (setq after-hook-run t
)
3824 ;; Add comment to output buffer
3825 (goto-char (point-min))
3826 (insert "<!-- after-export-hook -->\n")))
3829 (add-hook 'markdown-after-export-hook func
)
3830 ;; Export XHTML and return filename
3832 (obuffer (get-file-buffer ofile
)))
3833 (message "obuffer = %S" obuffer
)
3834 ;; Test that variable was changed
3835 (should (eq after-hook-run t
))
3836 ;; Test that output buffer remains open
3837 (should (get-buffer obuffer
))
3838 ;; Test that output buffer modification remains
3839 (with-current-buffer obuffer
3840 (goto-char (point-min))
3841 (should (looking-at "<!-- after-export-hook -->\n")))
3842 ;; Test that buffer modification was saved
3843 (should-not (buffer-modified-p obuffer
))
3845 (remove-hook 'markdown-after-export-hook func
)
3846 (kill-buffer obuffer
)
3847 (delete-file ofile
))))
3849 ;;; Extension: math support
3851 (ert-deftest test-markdown-math
/file-local-variable
()
3852 "Test enabling math mode via `hack-local-variables-hook'."
3853 (markdown-test-file "math.text"
3854 (should-not markdown-enable-math
)
3855 (hack-local-variables)
3856 (should markdown-enable-math
)))
3858 (ert-deftest test-markdown-math
/reload
()
3859 "Test enabling math mode via function `markdown-enable-math'."
3860 (let ((markdown-enable-math t
))
3861 (markdown-test-file "math.text"
3862 ;; Flag should be set to t
3863 (should markdown-enable-math
)
3864 ;; Font-lock keywords should be updated
3865 (should (member (cons markdown-regex-math-display
'((1 markdown-markup-face prepend
)
3866 (2 markdown-math-face append
)
3867 (3 markdown-markup-face prepend
)))
3868 markdown-mode-font-lock-keywords
)))))
3870 (ert-deftest test-markdown-math
/font-lock
()
3871 "Test markdown math mode."
3872 (let ((markdown-enable-math t
))
3873 (markdown-test-file "math.text"
3874 (markdown-test-range-has-face 1 32 nil
)
3875 (markdown-test-range-has-face 33 33 markdown-markup-face
)
3876 (markdown-test-range-has-face 34 45 markdown-math-face
)
3877 (markdown-test-range-has-face 46 46 markdown-markup-face
)
3878 (markdown-test-range-has-face 47 49 nil
)
3879 (markdown-test-range-has-face 50 51 markdown-markup-face
)
3880 (markdown-test-range-has-face 52 63 markdown-math-face
)
3881 (markdown-test-range-has-face 64 65 markdown-markup-face
)
3882 (markdown-test-range-has-face 66 98 nil
)
3883 (markdown-test-range-has-face 99 100 markdown-markup-face
)
3884 (markdown-test-range-has-face 101 112 markdown-math-face
)
3885 (markdown-test-range-has-face 113 114 markdown-markup-face
)
3886 (markdown-test-range-has-face 113 114 markdown-markup-face
)
3887 (markdown-test-range-has-face 117 117 markdown-header-delimiter-face
)
3888 (markdown-test-range-has-face 119 152 markdown-header-face-1
)
3889 (markdown-test-range-has-face 129 129 markdown-markup-face
)
3890 (markdown-test-range-has-face 136 136 markdown-markup-face
)
3892 (markdown-test-range-has-face 174 177 markdown-markup-face
)
3893 (markdown-test-range-has-face 179 179 markdown-markup-face
)
3894 (markdown-test-range-has-face 180 187 markdown-language-keyword-face
)
3895 (markdown-test-range-has-face 188 188 markdown-markup-face
)
3896 (markdown-test-range-has-face 190 211 markdown-pre-face
)
3897 (markdown-test-range-has-face 212 215 markdown-markup-face
)
3899 (markdown-test-range-has-face 218 218 markdown-markup-face
)
3900 (markdown-test-range-has-face 219 223 markdown-math-face
)
3901 (markdown-test-range-has-face 224 224 markdown-markup-face
)
3902 (markdown-test-range-has-face 350 351 markdown-markup-face
)
3903 (markdown-test-range-has-face 352 356 markdown-math-face
)
3904 (markdown-test-range-has-face 357 358 markdown-markup-face
)
3905 (markdown-test-range-has-face 359 391 nil
)
3906 (markdown-test-range-has-face 392 393 markdown-markup-face
)
3907 (markdown-test-range-has-face 394 398 markdown-math-face
)
3908 (markdown-test-range-has-face 399 400 markdown-markup-face
))))
3910 (ert-deftest test-markdown-math
/font-lock-italics
()
3911 "Test markdown math mode with underscores."
3912 (let ((markdown-enable-math t
))
3913 (markdown-test-file "math.text"
3914 (markdown-test-range-has-face 227 227 markdown-markup-face
)
3915 (markdown-test-range-has-face 228 233 markdown-math-face
)
3916 (markdown-test-range-has-face 234 234 markdown-markup-face
)
3917 (markdown-test-range-has-face 235 270 nil
)
3918 (markdown-test-range-has-face 271 271 markdown-markup-face
)
3919 (markdown-test-range-has-face 272 274 markdown-math-face
)
3920 (markdown-test-range-has-face 275 275 markdown-markup-face
))))
3922 (ert-deftest test-markdown-math
/font-lock-no-bold
()
3923 "Bold markers in math should not trigger bold."
3924 (let ((markdown-enable-math t
))
3925 (markdown-test-file "math.text"
3926 (markdown-test-range-has-face 279 299 markdown-math-face
)
3927 (markdown-test-range-has-face 301 308 nil
)
3928 (markdown-test-range-has-face 310 312 markdown-math-face
))))
3932 (ert-deftest test-markdown-gfm
/pre-1
()
3933 "GFM pre block font lock test."
3934 (markdown-test-file-gfm "gfm.text"
3935 (markdown-test-range-has-face 2626 2637 nil
)
3936 (markdown-test-range-has-face 2639 2641 markdown-markup-face
)
3937 (markdown-test-range-has-face 2642 2645 markdown-language-keyword-face
)
3938 (markdown-test-range-has-face 2647 2728 markdown-pre-face
)
3939 (markdown-test-range-has-face 2730 2732 markdown-markup-face
)))
3941 (ert-deftest test-markdown-gfm
/italic-1
()
3942 "GFM italic font lock test."
3943 (markdown-test-file-gfm "gfm.text"
3944 (markdown-test-range-has-face 1483 1483 markdown-markup-face
)
3945 (markdown-test-range-has-face 1484 1487 markdown-italic-face
)
3946 (markdown-test-range-has-face 1488 1488 markdown-markup-face
)
3947 (markdown-test-range-has-face 1729 1790 nil
)))
3949 (ert-deftest test-markdown-gfm
/strike-through-1
()
3950 "GFM strike through font lock test."
3951 (markdown-test-string-gfm "one ~~two~~ three"
3952 (markdown-test-range-has-face 1 4 nil
)
3953 (markdown-test-range-has-face 5 6 markdown-markup-face
)
3954 (markdown-test-range-has-face 7 9 markdown-strike-through-face
)
3955 (markdown-test-range-has-face 10 11 markdown-markup-face
)
3956 (markdown-test-range-has-face 12 17 nil
)))
3958 (ert-deftest test-markdown-gfm
/toggle-strike-through
()
3959 "Test toggling functionality of `markdown-insert-strike-through'."
3960 (markdown-test-string-gfm "one ~~two~~ three"
3962 (markdown-insert-strike-through)
3963 (should (string-equal (buffer-string) "one two three"))
3964 (should (= (point) 8))
3966 (markdown-insert-strike-through)
3967 (should (= (point) 16))
3968 (should (string-equal (buffer-string) "one two ~~three~~"))))
3970 (ert-deftest test-markdown-gfm
/insert-code-block
()
3971 "GFM code block insertion test."
3972 ;; Test empty markup insertion
3973 (markdown-test-string-gfm "line 1\nline 2\n"
3975 (markdown-insert-gfm-code-block "elisp")
3976 (should (equal (car markdown-gfm-used-languages
) "elisp"))
3977 (should (equal (car (markdown-gfm-get-corpus)) "elisp"))
3978 (should (string-equal (buffer-string)
3979 "line 1\n\n``` elisp\n\n```\n\nline 2\n")))
3980 ;; Test with active region
3981 (markdown-test-string-gfm "line 1\nline 2\nline 3\n"
3983 (transient-mark-mode)
3984 (push-mark (point) t t
)
3986 (should (markdown-use-region-p))
3987 (markdown-insert-gfm-code-block "elisp")
3988 (should (string-equal (buffer-string)
3989 "line 1\n\n``` elisp\nline 2\n```\n\nline 3\n"))))
3991 (ert-deftest test-markdown-gfm
/gfm-parse-buffer-for-languages
()
3992 "Parse buffer for existing languages for `markdown-gfm-used-languages' test."
3993 (markdown-test-string-gfm "``` MADEUP\n\n```\n``` LANGUAGES\n\n```\n```MaDeUp\n\n```\n```\n\n```\n``` \n\n```\n"
3994 (markdown-gfm-parse-buffer-for-languages)
3995 (should (equal markdown-gfm-used-languages
3996 (list "MaDeUp" "LANGUAGES" "MADEUP")))
3997 (should (equal (car markdown-gfm-used-languages
) "MaDeUp"))
3998 (should (equal (car (markdown-gfm-get-corpus)) "MaDeUp"))
3999 (goto-char (point-max))
4000 (markdown-insert-gfm-code-block "newlang")
4001 (should (equal markdown-gfm-used-languages
4002 (list "newlang" "MaDeUp" "LANGUAGES" "MADEUP")))
4003 (should (equal (car markdown-gfm-used-languages
) "newlang"))
4004 (should (equal (car (markdown-gfm-get-corpus)) "newlang"))
4005 (let ((markdown-gfm-downcase-languages nil
))
4007 (equal (markdown-gfm-get-corpus)
4008 (append markdown-gfm-used-languages
4009 markdown-gfm-additional-languages
4010 markdown-gfm-recognized-languages
))))
4011 (let ((markdown-gfm-downcase-languages t
))
4014 (markdown-gfm-get-corpus)
4015 (append markdown-gfm-used-languages
4016 (cl-mapcar #'downcase
4017 (append markdown-gfm-additional-languages
4018 markdown-gfm-recognized-languages
))))))))
4020 (ert-deftest test-markdown-gfm
/code-block-font-lock
()
4021 "GFM code block font lock test."
4022 (markdown-test-file-gfm "gfm.text"
4023 (markdown-test-range-has-face 2639 2641 markdown-markup-face
) ; ```
4024 (markdown-test-range-has-face 2642 2645 markdown-language-keyword-face
) ; lang
4025 (markdown-test-range-has-face 2647 2728 markdown-pre-face
) ; code
4026 (markdown-test-range-has-face 2730 2732 markdown-markup-face
))) ; ```
4028 (ert-deftest test-markdown-gfm
/code-block-font-lock-2
()
4029 "GFM code block font lock test without language identifier."
4030 (markdown-test-string-gfm "Plain code block:\n\n```\nfoo\n```\n"
4031 (markdown-test-range-has-face 20 22 markdown-markup-face
)
4032 (markdown-test-range-has-face 24 26 markdown-pre-face
)
4033 (markdown-test-range-has-face 28 30 markdown-markup-face
)))
4035 ;;; Tests for other extensions:
4037 (ert-deftest test-markdown-ext
/pandoc-fancy-lists
()
4038 "Test basic support for font lock and filling of Pandoc 'fancy lists'."
4039 (markdown-test-string " #. abc\ndef\n"
4041 (markdown-test-range-has-face 1 1 nil
)
4042 (markdown-test-range-has-face 2 3 markdown-list-face
)
4043 (markdown-test-range-has-face 4 11 nil
)
4046 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
4047 (should (string-equal (buffer-string) " #. abc\n def\n"))
4048 (markdown-indent-region (line-beginning-position) (line-end-position) nil
)
4049 (should (string-equal (buffer-string) " #. abc\n def\n"))))
4051 (ert-deftest test-markdown-ext
/wiki-link-rules
()
4052 "Test wiki link search rules and font lock for missing pages."
4053 (let ((markdown-enable-wiki-links t
)
4054 (markdown-wiki-link-fontify-missing t
)
4055 (markdown-wiki-link-search-subdirectories t
)
4056 (markdown-wiki-link-search-parent-directories t
))
4058 (find-file "wiki/root")
4063 (should (string-match-p
4065 (markdown-convert-wiki-link-to-filename "foo")))
4066 (should (string-equal
4067 (markdown-convert-wiki-link-to-filename "doesnotexist")
4070 (markdown-test-range-has-property 1 11 'font-lock-face markdown-link-face
)
4071 (markdown-test-range-has-property 14 33 'font-lock-face markdown-missing-link-face
)
4072 (markdown-test-range-has-property 36 42 'font-lock-face markdown-link-face
)
4073 (markdown-test-range-has-property 45 60 'font-lock-face markdown-missing-link-face
))
4076 (find-file "wiki/sub/foo")
4081 (should (string-match-p
4083 (markdown-convert-wiki-link-to-filename "root")))
4084 (should (string-equal
4085 (markdown-convert-wiki-link-to-filename "doesnotexist")
4088 (markdown-test-range-has-property 1 16 'font-lock-face markdown-missing-link-face
)
4089 (markdown-test-range-has-property 19 26 'font-lock-face markdown-link-face
))
4092 (defadvice markdown-live-preview-window-eww
4093 (around markdown-test-create-fake-eww disable
)
4094 (setq ad-return-value
(get-buffer-create "*eww*")))
4096 (defmacro markdown-test-fake-eww
(&rest body
)
4098 ,@(if (and (fboundp 'libxml-parse-html-region
) (require 'eww nil t
)) body
4099 `((ad-enable-advice #'markdown-live-preview-window-eww
4100 'around
'markdown-test-create-fake-eww
)
4101 (ad-activate #'markdown-live-preview-window-eww
)
4103 (ad-disable-advice #'markdown-live-preview-window-eww
4104 'around
'markdown-test-create-fake-eww
)
4105 (ad-activate #'markdown-live-preview-window-eww
)))))
4107 (defmacro markdown-test-eww-or-nothing
(test &rest body
)
4108 (if (and (fboundp 'libxml-parse-html-region
) (require 'eww nil t
)
4109 (executable-find markdown-command
))
4111 (message "no eww, no libxml2, or no %s found: skipping %s" markdown-command test
)
4114 (ert-deftest test-markdown-ext
/live-preview-exports
()
4115 (markdown-test-temp-file "inline.text"
4116 (unless (and (fboundp 'libxml-parse-html-region
) (require 'eww nil t
))
4117 (should-error (markdown-live-preview-mode)))
4118 (markdown-test-fake-eww
4119 (markdown-live-preview-mode)
4120 (should (buffer-live-p markdown-live-preview-buffer
))
4121 (should (eq (current-buffer)
4122 (with-current-buffer markdown-live-preview-buffer
4123 markdown-live-preview-source-buffer
)))
4124 (kill-buffer markdown-live-preview-buffer
)
4125 (should (null markdown-live-preview-buffer
))
4126 (set-buffer-modified-p t
)
4127 (save-buffer) ; should create new export
4128 (should (buffer-live-p markdown-live-preview-buffer
)))))
4130 (ert-deftest test-markdown-ext
/live-preview-delete-exports
()
4131 (markdown-test-fake-eww
4132 (let ((markdown-live-preview-delete-export 'delete-on-destroy
)
4134 (markdown-test-temp-file "inline.text"
4135 (markdown-live-preview-mode)
4136 (setq file-output
(markdown-export-file-name)))
4137 (should-not (file-exists-p file-output
)))
4138 (let ((markdown-live-preview-delete-export 'delete-on-export
)
4140 (markdown-test-temp-file "inline.text"
4141 (markdown-live-preview-mode)
4142 (setq file-output
(markdown-export-file-name))
4143 (should-not (file-exists-p file-output
))))
4144 (let ((markdown-live-preview-delete-export nil
)
4147 (markdown-test-temp-file "inline.text"
4148 (markdown-live-preview-mode)
4149 (setq file-output
(markdown-export-file-name))
4150 (should (file-exists-p file-output
)))
4151 (delete-file file-output
)))))
4153 (ert-deftest test-markdown-ext
/live-preview-follow-min-max
()
4154 (markdown-test-eww-or-nothing "live-preview-follow-min-max"
4155 (markdown-test-temp-file "inline.text"
4156 (markdown-live-preview-mode)
4157 (should (buffer-live-p markdown-live-preview-buffer
))
4158 (should (window-live-p (get-buffer-window markdown-live-preview-buffer
)))
4159 (with-selected-window (get-buffer-window markdown-live-preview-buffer
)
4160 (goto-char (point-min)))
4161 (goto-char (point-min))
4163 (markdown-live-preview-export)
4164 (let (final-pt final-win-st-diff
)
4165 ;; test that still starts at point-min
4166 (with-selected-window (get-buffer-window markdown-live-preview-buffer
)
4167 (should (= (window-point) 1))
4168 (should (= (markdown-visual-lines-between-points
4169 (window-start) (window-point))
4171 (set-window-point (selected-window) (point-max))
4172 (setq final-pt
(window-point)
4173 final-win-st-diff
(markdown-visual-lines-between-points
4174 (window-start) (window-point))))
4175 (goto-char (point-min))
4177 (markdown-live-preview-export)
4178 (with-selected-window (get-buffer-window markdown-live-preview-buffer
)
4179 (should (= (window-point) (+ final-pt
(length "this is "))))
4180 (should (= (markdown-visual-lines-between-points
4181 (window-start) (window-point))
4183 ;; test that still starts at point-max, with correct line difference
4184 (goto-char (floor (/ (float (- (point-max) (point-min))) 2)))
4185 (setq final-pt
(window-point)
4186 final-win-st-diff
(markdown-visual-lines-between-points
4187 (window-start) final-pt
)))
4188 (markdown-live-preview-export)
4189 ;; test that still starts at same point, with correct line difference
4190 (with-selected-window (get-buffer-window markdown-live-preview-buffer
)
4191 (should (= (window-point) final-pt
))
4192 (should (= (markdown-visual-lines-between-points
4193 (window-start) (window-point))
4194 final-win-st-diff
)))))))
4198 (ert-deftest test-markdown-imenu
/metadata
()
4199 "Don't correct header like statement in metadata.
4200 https://github.com/jrblevin/markdown-mode/issues/145"
4201 (markdown-test-string "---
4210 (let ((headers (mapcar #'car
(markdown-imenu-create-flat-index))))
4211 (should (member "Header1" headers
))
4212 (should (member "Header2" headers
))
4213 (should-not (member "comments = false" headers
)))))
4215 (provide 'markdown-test
)
4217 ;;; markdown-test.el ends here