[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode f2e7138 220/468: Move font-lock test helpers into
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode f2e7138 220/468: Move font-lock test helpers into a separate file |
Date: |
Thu, 5 Aug 2021 04:58:40 -0400 (EDT) |
branch: elpa/lua-mode
commit f2e7138c567e9ad3874062c6006693c587e73552
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Move font-lock test helpers into a separate file
---
Makefile | 4 +-
ert-tests/lua-font-lock-test-helpers.el | 52 +++++++++++++
ert-tests/test-defun-font-lock.el | 133 +++++++++++---------------------
3 files changed, 98 insertions(+), 91 deletions(-)
diff --git a/Makefile b/Makefile
index 0c77e66..921b196 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,9 @@ dist:
git archive --format=zip -o $(DISTFILE) --prefix=lua-mode/ HEAD
check:
- emacs -Q -batch -l ert -l lua-mode.el $(addprefix -l ,$(TESTS)) -f
ert-run-tests-batch-and-exit
+ emacs -Q -batch -l ert \
+ -l lua-mode.el -l ert-tests/lua-font-lock-test-helpers.el \
+ $(addprefix -l ,$(TESTS)) -f ert-run-tests-batch-and-exit
release:
git fetch && \
diff --git a/ert-tests/lua-font-lock-test-helpers.el
b/ert-tests/lua-font-lock-test-helpers.el
new file mode 100644
index 0000000..19da5c1
--- /dev/null
+++ b/ert-tests/lua-font-lock-test-helpers.el
@@ -0,0 +1,52 @@
+(require 'lua-mode)
+
+(defun get-str-faces (str)
+ "Find contiguous spans of non-default faces in STR.
+
+E.g. for properly fontified Lua string \"local x = 100\" it should return
+ '(\"local\" font-lock-keyword-face
+ \"x\" font-lock-variable-name-face
+ \"100\" font-lock-constant-face)
+"
+ (let ((pos 0)
+ nextpos
+ result prop)
+ (while pos
+ (setq nextpos (next-single-property-change pos 'face str)
+ prop (get-text-property pos 'face str))
+ (when prop
+ (push (substring-no-properties str pos nextpos) result)
+ (push prop result))
+ (setq pos nextpos))
+ (nreverse result)))
+
+(defun lua-fontify-str (str)
+ "Return string fontified according to lua-mode's rules"
+ (with-temp-buffer
+ (lua-mode)
+ (insert str)
+ (font-lock-fontify-buffer)
+ (buffer-string)))
+
+(defun lua-get-line-faces (str)
+ "Find contiguous spans of non-default faces in each line of STR.
+
+The result is a list of lists."
+ (mapcar
+ 'get-str-faces
+ (split-string (lua-fontify-str str) "\n" nil)))
+
+(defun lua-mk-font-lock-faces (sym)
+ "Decorate symbols with font-lock-%s-face recursively.
+
+This is a mere typing/reading aid for lua-mode's font-lock tests."
+ (or (cond
+ ((symbolp sym) (intern-soft (format "font-lock-%s-face" (symbol-name
sym))))
+ ((listp sym) (mapcar 'lua-mk-font-lock-faces sym)))
+ sym))
+
+(defmacro should-lua-font-lock-equal (strs faces)
+ `(should (equal (lua-get-line-faces ,strs)
+ (lua-mk-font-lock-faces ,faces))))
+
+(provide 'lua-font-lock-test-helpers)
diff --git a/ert-tests/test-defun-font-lock.el
b/ert-tests/test-defun-font-lock.el
index 85ecfef..d41acf1 100644
--- a/ert-tests/test-defun-font-lock.el
+++ b/ert-tests/test-defun-font-lock.el
@@ -1,95 +1,51 @@
(require 'ert)
-
-(defun get-str-faces (str)
- "Find contiguous spans of non-default faces in STR.
-
-E.g. for properly fontified Lua string \"local x = 100\" it should return
- '(\"local\" font-lock-keyword-face
- \"x\" font-lock-variable-name-face
- \"100\" font-lock-constant-face)
-"
- (let ((pos 0)
- nextpos
- result prop)
- (while pos
- (setq nextpos (next-single-property-change pos 'face str)
- prop (get-text-property pos 'face str))
- (when prop
- (push (substring-no-properties str pos nextpos) result)
- (push prop result))
- (setq pos nextpos))
- (nreverse result)))
-
-(defun lua-fontify-str (str)
- "Return string fontified according to lua-mode's rules"
- (with-temp-buffer
- (lua-mode)
- (insert str)
- (font-lock-fontify-buffer)
- (buffer-string)))
-
-(defun lua-get-line-faces (str)
- "Find contiguous spans of non-default faces in each line of STR.
-
-The result is a list of lists."
- (mapcar
- 'get-str-faces
- (split-string (lua-fontify-str str) "\n" nil)))
-
-(defun lua-mk-font-lock-faces (sym)
- "Decorate symbols with font-lock-%s-face recursively.
-
-This is a mere typing/reading aid for lua-mode's font-lock tests."
- (or (cond
- ((symbolp sym) (intern-soft (format "font-lock-%s-face" (symbol-name
sym))))
- ((listp sym) (mapcar 'lua-mk-font-lock-faces sym)))
- sym))
-
-(defmacro should-lua-font-lock-equal (strs faces)
- `(should (equal (lua-get-line-faces ,strs)
- (lua-mk-font-lock-faces ,faces))))
-
-(progn
- (ert-deftest lua-font-lock-defuns ()
- (should-lua-font-lock-equal
- ;; Let's start with some basic stuff
- "function foo() end"
- '(("function" keyword "foo" function-name "end" keyword)))
-
- (should-lua-font-lock-equal
- ;; Check all defun variants, check embedded defuns
- "\
+(require 'lua-font-lock-test-helpers
+ ;; let's try a bit to help Emacs find the helpers, just in case
+ (concat (file-name-directory (or load-file-name (buffer-file-name)
+ default-directory))
+ "lua-font-lock-test-helpers.el"))
+
+
+(ert-deftest lua-font-lock-defuns ()
+ (should-lua-font-lock-equal
+ ;; Let's start with some basic stuff
+ "function foo() end"
+ '(("function" keyword "foo" function-name "end" keyword)))
+
+ (should-lua-font-lock-equal
+ ;; Check all defun variants, check embedded defuns
+ "\
function foo()
function bar() end
local function baz() end
qux = function() end
local quux = function() end
end"
- '(("function" keyword "foo" function-name)
- ("function" keyword "bar" function-name "end" keyword)
- ("local" keyword "function" keyword "baz" function-name "end" keyword)
- ("qux" function-name "function" keyword "end" keyword)
- ("local" keyword "quux" function-name "function" keyword "end" keyword)
- ("end" keyword))))
-
- (ert-deftest lua-font-lock-defuns-inside-table ()
- ;; Check defuns within table definition
- (should-lua-font-lock-equal
- "\
+ '(("function" keyword "foo" function-name)
+ ("function" keyword "bar" function-name "end" keyword)
+ ("local" keyword "function" keyword "baz" function-name "end" keyword)
+ ("qux" function-name "function" keyword "end" keyword)
+ ("local" keyword "quux" function-name "function" keyword "end" keyword)
+ ("end" keyword))))
+
+(ert-deftest lua-font-lock-defuns-inside-table ()
+ ;; Check defuns within table definition
+ (should-lua-font-lock-equal
+ "\
somefunc {
function() end,
foobar = function() end,
[\"quxquux\"] = function() end
}"
- '(nil
- ("function" keyword "end" keyword)
- ("foobar" function-name "function" keyword "end" keyword)
- ("\"quxquux\"" string "function" keyword "end" keyword)
- nil)))
-
- (ert-deftest lua-gh-issue59 ()
- (should-lua-font-lock-equal
- "\
+ '(nil
+ ("function" keyword "end" keyword)
+ ("foobar" function-name "function" keyword "end" keyword)
+ ("\"quxquux\"" string "function" keyword "end" keyword)
+ nil)))
+
+(ert-deftest lua-gh-issue59 ()
+ (should-lua-font-lock-equal
+ "\
local foo = function()
;
end
@@ -97,13 +53,10 @@ end
local function foo()
;
end"
- '(("local" keyword "foo" function-name "function" keyword)
- nil
- ("end" keyword)
- ("-- " comment-delimiter "and" comment)
- ("local" keyword "function" keyword "foo" function-name)
- nil
- ("end" keyword))))
-
- (ert-run-tests-interactively t))
-
+ '(("local" keyword "foo" function-name "function" keyword)
+ nil
+ ("end" keyword)
+ ("-- " comment-delimiter "and" comment)
+ ("local" keyword "function" keyword "foo" function-name)
+ nil
+ ("end" keyword))))
- [nongnu] elpa/lua-mode 97ce427 198/468: Restore compatibility with Emacs23 broken by commit 8d28342, (continued)
- [nongnu] elpa/lua-mode 97ce427 198/468: Restore compatibility with Emacs23 broken by commit 8d28342, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ff3f5e1 199/468: lua-font-lock-keywords: don't eval-when-compile initial value, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2a0314b 200/468: Improve multiline highlighting via font-lock-syntactic-keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cd5c071 201/468: Clean up lua-mode start-up function a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b195cdc 205/468: Bump TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cee511c 206/468: for/local varname highlighting: match '=' at EOL properly, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a1dc850 207/468: Post-refactoring fix: evaluate string variables in font-lock-defaults value, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8ffd075 208/468: lua-calculate-indentation-info: non-functional refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4484128 215/468: lua-calculate-indentation-override: unindent to the last block-close token, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 79e6815 216/468: Rewrite lua-beginning-of-proc, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f2e7138 220/468: Move font-lock test helpers into a separate file,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 94aadfd 221/468: Font-lock "nil", "true" and "false" as constants rather than keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 617c392 224/468: make test: test both compiled and uncompiled variants, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7157658 225/468: Create cask project; pull in ert.el to enable testing emacs23, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ed76a6e 227/468: .gitignore: ignore all *.elc, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 67a9022 229/468: test-electric-mode: check interaction with electric-pair-skip-self flag, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b10d6ae 232/468: Add missing modulo operator (%) to line-continuation tokens, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2d308e8 237/468: Move "no-query-on-exit" initialization to lua-start-process, update it, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 397b883 236/468: Send code to inferior process via loadstring to avoid tempfile issues, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 24cc45e 239/468: Skip shebang line when sending to inferior buffer (issue #61), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c53d071 344/468: travis: disable git-snapshot, Philip Kaludercic, 2021/08/05