aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVladimir Panteleev2017-02-10 11:23:24 +0200
committerEli Zaretskii2017-02-10 11:23:24 +0200
commit2d284db5c9c5ff23269e2ec277f5348abdf1cd47 (patch)
tree6f135fd8d70b0e0d18391915295b521aa2635a6f /test
parent937bf04804246c86a4b1bd55b506169f5a894e3b (diff)
downloademacs-2d284db5c9c5ff23269e2ec277f5348abdf1cd47.tar.gz
emacs-2d284db5c9c5ff23269e2ec277f5348abdf1cd47.zip
Improve fontification in bat-mode
* lisp/progmodes/bat-mode.el (bat-font-lock-keywords): Match word and symbol constituents when looking for variable names to fontify; also, correct the syntax table and mark the equal sign (=) character as punctuation. Improve fontification accuracy of iteration/positional variables. (bat-mode): Set comment-start-skip. (Bug#25541) * test/lisp/progmodes/bat-mode-tests.el: New file, tests for bat-mode.el.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/bat-mode-tests.el86
1 files changed, 86 insertions, 0 deletions
diff --git a/test/lisp/progmodes/bat-mode-tests.el b/test/lisp/progmodes/bat-mode-tests.el
new file mode 100644
index 00000000000..565718eea41
--- /dev/null
+++ b/test/lisp/progmodes/bat-mode-tests.el
@@ -0,0 +1,86 @@
1;;; bat-mode-tests.el --- Tests for bat-mode.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2017 Free Software Foundation, Inc.
4
5;; Author: Vladimir Panteleev <vladimir@thecybershadow.net>
6;; Keywords:
7
8;; This file is part of GNU Emacs.
9
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.
14
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.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'ert)
30(require 'bat-mode)
31(require 'htmlfontify)
32
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)))))
40
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")))
47
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>%")))
54
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>!")))
61
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")
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
71(defun bat-test-fill-paragraph (str)
72 "Return the result of invoking `fill-paragraph' on STR in a `bat-mode' buffer."
73 (with-temp-buffer
74 (bat-mode)
75 (insert str)
76 (goto-char 1)
77 (font-lock-ensure)
78 (fill-paragraph)
79 (buffer-string)))
80
81(ert-deftest bat-test-fill-paragraph-comment ()
82 "Test `fill-paragraph' in a comment block."
83 (should (equal (bat-test-fill-paragraph "rem foo\nrem bar\n") "rem foo bar\n")))
84
85(provide 'bat-tests)
86;;; bat-mode-tests.el ends here