emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]