aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSimen Heggestøyl2020-05-10 16:17:27 +0200
committerSimen Heggestøyl2020-05-10 17:18:03 +0200
commit8f808be68bfab51fe282e7ee2f6bc8c28bf7a442 (patch)
tree8cf425abaf74b14f150186dad8991e03dc65f661 /test
parent1efaa1d66b9bc51284c7cac4477f45c9bde4fcfb (diff)
downloademacs-8f808be68bfab51fe282e7ee2f6bc8c28bf7a442.tar.gz
emacs-8f808be68bfab51fe282e7ee2f6bc8c28bf7a442.zip
Use lexical-binding in glasses.el and add tests
* lisp/progmodes/glasses.el: Use lexical-binding. (glasses-separator, glasses-original-separator, glasses-face) (glasses-separate-parentheses-p) (glasses-separate-parentheses-exceptions) (glasses-separate-capital-groups, glasses-uncapitalize-p) (glasses-uncapitalize-regexp, glasses-convert-on-write-p): Remove redundant :group args. * test/lisp/progmodes/glasses-tests.el: New file with tests for glasses.el.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/glasses-tests.el101
1 files changed, 101 insertions, 0 deletions
diff --git a/test/lisp/progmodes/glasses-tests.el b/test/lisp/progmodes/glasses-tests.el
new file mode 100644
index 00000000000..277a9cc1927
--- /dev/null
+++ b/test/lisp/progmodes/glasses-tests.el
@@ -0,0 +1,101 @@
1;;; glasses-tests.el --- Tests for glasses.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; Author: Simen Heggestøyl <simenheg@gmail.com>
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 <https://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;
26
27;;; Code:
28
29(require 'ert)
30(require 'glasses)
31(require 'seq)
32
33(ert-deftest glasses-tests-parenthesis-exception-p ()
34 (with-temp-buffer
35 (insert "public OnClickListener menuListener() {}")
36 (let ((glasses-separate-parentheses-exceptions '("^Listen")))
37 (should-not (glasses-parenthesis-exception-p 1 (point-max)))
38 (should (glasses-parenthesis-exception-p 15 (point-max)))
39 (should-not (glasses-parenthesis-exception-p 24 (point-max)))
40 (should (glasses-parenthesis-exception-p 28 (point-max))))))
41
42(ert-deftest glasses-tests-overlay-p ()
43 (should
44 (glasses-overlay-p (glasses-make-overlay (point-min) (point-max))))
45 (should-not
46 (glasses-overlay-p (make-overlay (point-min) (point-max)))))
47
48(ert-deftest glasses-tests-make-overlay-p ()
49 (let ((o (glasses-make-overlay (point-min) (point-max))))
50 (should (eq (overlay-get o 'category) 'glasses)))
51 (let ((o (glasses-make-overlay (point-min) (point-max) 'foo)))
52 (should (eq (overlay-get o 'category) 'foo))))
53
54(ert-deftest glasses-tests-make-readable ()
55 (with-temp-buffer
56 (insert "pp.setBackgroundResource(R.drawable.button_right);")
57 (glasses-make-readable (point-min) (point-max))
58 (pcase-let ((`(,o1 ,o2 ,o3)
59 (sort (overlays-in (point-min) (point-max))
60 (lambda (o1 o2)
61 (< (overlay-start o1) (overlay-start o2))))))
62 (should (= (overlay-start o1) 7))
63 (should (equal (overlay-get o1 'before-string)
64 glasses-separator))
65 (should (= (overlay-start o2) 17))
66 (should (equal (overlay-get o2 'before-string)
67 glasses-separator))
68 (should (= (overlay-start o3) 25))
69 (should (equal (overlay-get o3 'before-string) " ")))))
70
71(ert-deftest glasses-tests-make-readable-dont-separate-parentheses ()
72 (with-temp-buffer
73 (insert "pp.setBackgroundResource(R.drawable.button_right);")
74 (let ((glasses-separate-parentheses-p nil))
75 (glasses-make-readable (point-min) (point-max))
76 (should-not (overlays-at 25)))))
77
78(ert-deftest glasses-tests-make-unreadable ()
79 (with-temp-buffer
80 (insert "pp.setBackgroundResource(R.drawable.button_right);")
81 (glasses-make-readable (point-min) (point-max))
82 (should (seq-some #'glasses-overlay-p
83 (overlays-in (point-min) (point-max))))
84 (glasses-make-unreadable (point-min) (point-max))
85 (should-not (seq-some #'glasses-overlay-p
86 (overlays-in (point-min) (point-max))))))
87
88(ert-deftest glasses-tests-convert-to-unreadable ()
89 (with-temp-buffer
90 (insert "set_Background_Resource(R.button_right);")
91 (let ((glasses-convert-on-write-p nil))
92 (should-not (glasses-convert-to-unreadable))
93 (should (equal (buffer-string)
94 "set_Background_Resource(R.button_right);")))
95 (let ((glasses-convert-on-write-p t))
96 (should-not (glasses-convert-to-unreadable))
97 (should (equal (buffer-string)
98 "setBackgroundResource(R.button_right);")))))
99
100(provide 'glasses-tests)
101;;; glasses-tests.el ends here