Give '$' punctuation syntax in make-mode (Bug#24477)
[emacs.git] / test / lisp / progmodes / bat-mode-tests.el
blob5b824841d41a7996a554c7dcf59a7b5075544722
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>
6 ;; Keywords:
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/>.
23 ;;; Commentary:
27 ;;; Code:
29 (require 'ert)
30 (require 'bat-mode)
31 (require 'htmlfontify)
33 (defun bat-test-fontify (str)
34 "Fontify STR in `bat-mode' to a HTML string using `htmlfontify' and return it."
35 (with-temp-buffer
36 (insert str)
37 (bat-mode)
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."
43 (should
44 (equal
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."
50 (should
51 (equal
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."
57 (should
58 (equal
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."
64 (should
65 (equal
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."
74 (with-temp-buffer
75 (bat-mode)
76 (insert str)
77 (goto-char 1)
78 (font-lock-ensure)
79 (fill-paragraph)
80 (buffer-string)))
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")))
86 (provide 'bat-tests)
87 ;;; bat-mode-tests.el ends here