[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode d552910 218/468: Add a test for defun font-lockin
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode d552910 218/468: Add a test for defun font-locking; add make check target to run it |
Date: |
Thu, 5 Aug 2021 04:58:39 -0400 (EDT) |
branch: elpa/lua-mode
commit d552910f45add9a1465b3f650045610823a79895
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Add a test for defun font-locking; add make check target to run it
---
Makefile | 5 ++
ert-tests/test-defun-font-lock.el | 109 ++++++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+)
diff --git a/Makefile b/Makefile
index cd93847..0c77e66 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,8 @@ DISTFILE = lua-mode-$(VERSION).zip
# EMACS value may be overridden
EMACS?=emacs
+TESTS=ert-tests/test-defun-font-lock.el
+
default:
@echo version is $(VERSION)
@@ -16,6 +18,9 @@ dist:
rm -f $(DISTFILE) && \
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
+
release:
git fetch && \
git diff remotes/origin/master --exit-code && \
diff --git a/ert-tests/test-defun-font-lock.el
b/ert-tests/test-defun-font-lock.el
new file mode 100644
index 0000000..85ecfef
--- /dev/null
+++ b/ert-tests/test-defun-font-lock.el
@@ -0,0 +1,109 @@
+(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
+ "\
+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
+ "\
+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
+ "\
+local foo = function()
+ ;
+end
+-- and
+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))
+
- [nongnu] elpa/lua-mode bba7fc0 163/468: Fix byte-compilation, (continued)
- [nongnu] elpa/lua-mode bba7fc0 163/468: Fix byte-compilation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d128a74 170/468: Add initial version of test/indentation/README.md, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4399254 177/468: Merge pull request #39, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 08ff6ea 183/468: Merge remote-tracking branch 'origin/master', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8aa98ae 185/468: Non-functional refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7605d2c 186/468: lua-font-lock-keywords: rewrite poorly written regexp (issue #47), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c24f16e 188/468: Put Lua reference resources into TODO file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5d81110 196/468: Wrap symbols required during compilation into (eval-when compile ...), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 040bc8f 213/468: Bump NEWS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d8dc55 214/468: Rename lua--function-name-rx, use it in font-lock keywords init, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d552910 218/468: Add a test for defun font-locking; add make check target to run it,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 4141c85 222/468: Make builtin font-locking more stable; enable it after ".." operator, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1716660 223/468: Fix interaction with electric-pair-mode (issue #54), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4217513 230/468: Remove highlighting of numbers for consistency with other major-modes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 248bea3 233/468: Remove syntax hacks for '.' & '_' characters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c5e9620 238/468: Fix stacktrace parsing in inferior process buffer, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f834c21 105/468: lua-mark-all-multiline-literals: fix missed rename, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode aec4eea 117/468: lua-mark/-unmark-all-multiline-literals: fix error occurring on empty buffer (fixes #4 ?), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 535ca1b 128/468: lua-mark-char-multiline-delim, lua-unmark-multiline-literals: inhibit after-change-functions to avoid running automarking twice on the same text, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bb9330f 132/468: Fix string contents indentation (issue #6), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d57fdaf 134/468: String content indentation: put back code that forbidden ANY indentation unless it's enabled, Philip Kaludercic, 2021/08/05