1 ;;; bat-mode-tests.el --- Tests for bat-mode.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 ;; Author: Vladimir Panteleev <vladimir@thecybershadow.net>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
31 (require 'htmlfontify
)
33 (defun bat-test-fontify (str)
34 "Fontify STR in `bat-mode' to a HTML string using `htmlfontify' and return it."
38 (let ((hfy-optimizations '(body-text-only merge-adjacent-tags
)))
39 (with-current-buffer (htmlfontify-buffer) (buffer-string)))))
41 (ert-deftest bat-test-fontification-var-decl
()
42 "Test fontification of variable declarations."
45 (bat-test-fontify "set a_b-c{d}e=f")
46 "<span class=\"builtin\">set</span> <span class=\"variable-name\">a_b-c{d}e</span>=f")))
48 (ert-deftest bat-test-fontification-var-exp
()
49 "Test fontification of variable expansions."
52 (bat-test-fontify "echo %a_b-c{d}e%")
53 "<span class=\"builtin\">echo</span> %<span class=\"variable-name\">a_b-c{d}e</span>%")))
55 (ert-deftest bat-test-fontification-var-delayed-exp
()
56 "Test fontification of delayed variable expansions."
59 (bat-test-fontify "echo !a_b-c{d}e!")
60 "<span class=\"builtin\">echo</span> !<span class=\"variable-name\">a_b-c{d}e</span>!")))
62 (ert-deftest bat-test-fontification-iter-var-1
()
63 "Test fontification of iteration variables."
66 (bat-test-fontify "echo %%a\necho %%~dp1\necho %%~$PATH:I\necho %%~1")
67 "<span class=\"builtin\">echo</span> %%<span class=\"variable-name\">a</span>
68 <span class=\"builtin\">echo</span> %%~dp<span class=\"variable-name\">1</span>
69 <span class=\"builtin\">echo</span> %%~$<span class=\"variable-name\">PATH</span>:<span class=\"variable-name\">I</span>
70 <span class=\"builtin\">echo</span> %%~<span class=\"variable-name\">1</span>")))
72 (defun bat-test-fill-paragraph (str)
73 "Return the result of invoking `fill-paragraph' on STR in a `bat-mode' buffer."
82 (ert-deftest bat-test-fill-paragraph-comment
()
83 "Test `fill-paragraph' in a comment block."
84 (should (equal (bat-test-fill-paragraph "rem foo\nrem bar\n") "rem foo bar\n")))
87 ;;; bat-mode-tests.el ends here