aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--lisp/progmodes/glasses.el11
-rw-r--r--test/lisp/progmodes/glasses-tests.el101
2 files changed, 102 insertions, 10 deletions
diff --git a/lisp/progmodes/glasses.el b/lisp/progmodes/glasses.el
index cad74f9f63a..ab65a1590c0 100644
--- a/lisp/progmodes/glasses.el
+++ b/lisp/progmodes/glasses.el
@@ -1,4 +1,4 @@
1;;; glasses.el --- make cantReadThis readable 1;;; glasses.el --- make cantReadThis readable -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 1999-2020 Free Software Foundation, Inc. 3;; Copyright (C) 1999-2020 Free Software Foundation, Inc.
4 4
@@ -66,7 +66,6 @@ defined by `glasses-original-separator'. If you don't want to add missing
66separators, set `glasses-separator' to an empty string. If you don't want to 66separators, set `glasses-separator' to an empty string. If you don't want to
67replace existent separators, set `glasses-original-separator' to an empty 67replace existent separators, set `glasses-original-separator' to an empty
68string." 68string."
69 :group 'glasses
70 :type 'string 69 :type 'string
71 :set 'glasses-custom-set 70 :set 'glasses-custom-set
72 :initialize 'custom-initialize-default) 71 :initialize 'custom-initialize-default)
@@ -78,7 +77,6 @@ For instance, if you set it to \"_\" and set `glasses-separator' to \"-\",
78underscore separators are displayed as hyphens. 77underscore separators are displayed as hyphens.
79If `glasses-original-separator' is an empty string, no such display change is 78If `glasses-original-separator' is an empty string, no such display change is
80performed." 79performed."
81 :group 'glasses
82 :type 'string 80 :type 'string
83 :set 'glasses-custom-set 81 :set 'glasses-custom-set
84 :initialize 'custom-initialize-default 82 :initialize 'custom-initialize-default
@@ -92,7 +90,6 @@ If it is nil, no face is placed at the capitalized letter.
92For example, you can set `glasses-separator' to an empty string and 90For example, you can set `glasses-separator' to an empty string and
93`glasses-face' to `bold'. Then unreadable identifiers will have no separators, 91`glasses-face' to `bold'. Then unreadable identifiers will have no separators,
94but will have their capitals in bold." 92but will have their capitals in bold."
95 :group 'glasses
96 :type '(choice (const :tag "None" nil) face) 93 :type '(choice (const :tag "None" nil) face)
97 :set 'glasses-custom-set 94 :set 'glasses-custom-set
98 :initialize 'custom-initialize-default) 95 :initialize 'custom-initialize-default)
@@ -100,7 +97,6 @@ but will have their capitals in bold."
100 97
101(defcustom glasses-separate-parentheses-p t 98(defcustom glasses-separate-parentheses-p t
102 "If non-nil, ensure space between an identifier and an opening parenthesis." 99 "If non-nil, ensure space between an identifier and an opening parenthesis."
103 :group 'glasses
104 :type 'boolean) 100 :type 'boolean)
105 101
106(defcustom glasses-separate-parentheses-exceptions 102(defcustom glasses-separate-parentheses-exceptions
@@ -108,7 +104,6 @@ but will have their capitals in bold."
108 "List of regexp that are exceptions for `glasses-separate-parentheses-p'. 104 "List of regexp that are exceptions for `glasses-separate-parentheses-p'.
109They are matched to the current line truncated to the point where the 105They are matched to the current line truncated to the point where the
110parenthesis expression starts." 106parenthesis expression starts."
111 :group 'glasses
112 :type '(repeat regexp)) 107 :type '(repeat regexp))
113 108
114(defcustom glasses-separate-capital-groups t 109(defcustom glasses-separate-capital-groups t
@@ -116,7 +111,6 @@ parenthesis expression starts."
116When the value is non-nil, HTMLSomething and IPv6 are displayed 111When the value is non-nil, HTMLSomething and IPv6 are displayed
117as HTML_Something and I_Pv6 respectively. Set the value to nil 112as HTML_Something and I_Pv6 respectively. Set the value to nil
118if you prefer to display them unchanged." 113if you prefer to display them unchanged."
119 :group 'glasses
120 :type 'boolean 114 :type 'boolean
121 :version "24.1") 115 :version "24.1")
122 116
@@ -124,7 +118,6 @@ if you prefer to display them unchanged."
124 "If non-nil, downcase embedded capital letters in identifiers. 118 "If non-nil, downcase embedded capital letters in identifiers.
125Only identifiers starting with lower case letters are affected, letters inside 119Only identifiers starting with lower case letters are affected, letters inside
126other identifiers are unchanged." 120other identifiers are unchanged."
127 :group 'glasses
128 :type 'boolean 121 :type 'boolean
129 :set 'glasses-custom-set 122 :set 'glasses-custom-set
130 :initialize 'custom-initialize-default) 123 :initialize 'custom-initialize-default)
@@ -135,7 +128,6 @@ other identifiers are unchanged."
135Only words starting with this regexp are uncapitalized. 128Only words starting with this regexp are uncapitalized.
136The regexp is case sensitive. 129The regexp is case sensitive.
137It has any effect only when `glasses-uncapitalize-p' is non-nil." 130It has any effect only when `glasses-uncapitalize-p' is non-nil."
138 :group 'glasses
139 :type 'regexp 131 :type 'regexp
140 :set 'glasses-custom-set 132 :set 'glasses-custom-set
141 :initialize 'custom-initialize-default) 133 :initialize 'custom-initialize-default)
@@ -149,7 +141,6 @@ file write then.
149 141
150Note the removal action does not try to be much clever, so it can remove real 142Note the removal action does not try to be much clever, so it can remove real
151separators too." 143separators too."
152 :group 'glasses
153 :type 'boolean) 144 :type 'boolean)
154 145
155 146
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