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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/forth-mode 89b9904ceb 119/153: Add some tests for font-loc


From: ELPA Syncer
Subject: [nongnu] elpa/forth-mode 89b9904ceb 119/153: Add some tests for font-lock faces
Date: Sat, 29 Jan 2022 08:02:24 -0500 (EST)

branch: elpa/forth-mode
commit 89b9904cebb48e5bca5e999561cab0515dec8dee
Author: Helmut Eller <eller.helmut@gmail.com>
Commit: Helmut Eller <eller.helmut@gmail.com>

    Add some tests for font-lock faces
    
    * tests.el (forth-parsing-words-font-lock): Add some tests.
    (forth-backslash-comment-font-lock): Adjust a little as there are
    now more keywords and more correct handling of words that are at
    the end-of-buffer.
    (forth-assert-face): Test 'face of 'font-lock-face.  We probably
    don't care about how it's implemented as long as it looks the
    same.
    (forth-strip-|-and-→, forth-strip-|-and-¹²): Use remove
    instead of delete. That's slightly nicer.
    
    * forth-syntax.el (forth-syntax--state-normal): Call parser
    functions directly so that words that are at the end-of-buffer can
    be font-locked.
---
 forth-syntax.el | 14 +++++++++-----
 test/tests.el   | 32 +++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/forth-syntax.el b/forth-syntax.el
index 9992404522..3ea857aa5e 100644
--- a/forth-syntax.el
+++ b/forth-syntax.el
@@ -223,10 +223,13 @@ SYNTAX must be a valid argument for `string-to-syntax'."
           #'forth-syntax--state-eob)
          (t
           (forth-syntax--set-word-syntax start (point))
-          (setq forth-syntax--current-word-start start)
-          (let ((word (buffer-substring-no-properties start (point))))
-            (or (forth-syntax--lookup word)
-                #'forth-syntax--state-normal))))))
+          (let* ((word (buffer-substring-no-properties start (point)))
+                 (parser (forth-syntax--lookup word)))
+            (cond (parser
+                   (setq forth-syntax--current-word-start start)
+                   (funcall parser))
+                  (t
+                   #'forth-syntax--state-normal)))))))
 
 
 ;;; Guess initial state
@@ -262,9 +265,10 @@ SYNTAX must be a valid argument for `string-to-syntax'."
     (remove-text-properties start end '(font-lock-face))
     (let* ((guess (forth-syntax--guess-state start))
           (state (cdr guess)))
-      ;;(message "forth-syntax-propertize: %s %s %s" start end guess)
+      (message "forth-syntax-propertize: %s %s %s" start end guess)
       (goto-char (car guess))
       (while (< (point) end)
+       (message "forth-syntax-propertize2: %s %s" (point) state)
        (let ((start (point)))
          (setq state (funcall state))
          (cl-assert (< start (point))))))))
diff --git a/test/tests.el b/test/tests.el
index 0dfbdb3c19..9b20953fe3 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -34,13 +34,13 @@
 (defun forth-strip-|-and-→ (string)
   (let* ((s2 (forth-strip-| string))
         (pos (1+ (string-match "→" s2))))
-    (list (delete ?→ s2) pos)))
+    (list (remove ?→ s2) pos)))
 
 (defun forth-strip-|-and-¹² (string)
   (let* ((s2 (forth-strip-| string))
-        (start (1+ (string-match "¹" (delete ?² s2))))
-        (end (1+ (string-match "²" (delete ?¹ s2)))))
-    (list (delete ?² (delete ?¹ s2))
+        (start (1+ (string-match "¹" (remove ?² s2))))
+        (end (1+ (string-match "²" (remove ?¹ s2)))))
+    (list (remove ?² (remove ?¹ s2))
          start end)))
 
 (defun forth-assert-face (content face)
@@ -48,7 +48,8 @@
     (destructuring-bind (content pos) (forth-strip-|-and-→ content)
       (forth-with-temp-buffer content
        (font-lock-ensure)
-       (should (eq face (get-text-property pos 'face)))))))
+       (should (eq face (or (get-text-property pos 'face)
+                            (get-text-property pos 'font-lock-face))))))))
 
 (defun forth-should-indent (expected &optional content)
   "Assert that CONTENT turns into EXPECTED after the buffer is re-indented.
@@ -102,9 +103,9 @@ The whitespace before and including \"|\" on each line is 
removed."
                         →x y )" font-lock-comment-face))
 
 (ert-deftest forth-backslash-comment-font-lock ()
-  (forth-assert-face "→\\" nil)
+  (forth-assert-face "→\\" font-lock-comment-delimiter-face)
   (forth-assert-face "→\\ " font-lock-comment-delimiter-face)
-  (forth-assert-face " →\\" nil)
+  (forth-assert-face " →\\" font-lock-comment-delimiter-face)
   (forth-assert-face "\t→\\ " font-lock-comment-delimiter-face)
   (forth-assert-face " →\\\t" font-lock-comment-delimiter-face)
   (forth-assert-face " →\\\n" font-lock-comment-delimiter-face)
@@ -126,7 +127,7 @@ The whitespace before and including \"|\" on each line is 
removed."
   (forth-assert-face "abort→\" ab\"" font-lock-string-face)
   (forth-assert-face ".→\" ab\"" font-lock-string-face)
   (forth-assert-face "c→\" ab\"" font-lock-string-face)
-  (forth-assert-face "[char] \" →of" nil)
+  (forth-assert-face "[char] \" →swap" nil)
   (forth-assert-face "frob\" →ab\" " nil)
   (forth-assert-face "s\" →a \n b " font-lock-string-face)
   (forth-assert-face "s\" a \n →b " nil)
@@ -143,7 +144,20 @@ The whitespace before and including \"|\" on each line is 
removed."
 
 (ert-deftest forth-parsing-words-font-lock ()
   (forth-assert-face "postpone ( →x " nil)
-  (forth-assert-face "' s\" →x "nil))
+  (forth-assert-face "' s\" →x "nil)
+  (forth-assert-face "case [char] ' →of exit endof " font-lock-keyword-face)
+  (forth-assert-face "→postpone postpone" font-lock-keyword-face)
+  (forth-assert-face "postpone →postpone" nil)
+  (forth-assert-face "→literal" font-lock-keyword-face)
+  (forth-assert-face "postpone →literal" nil)
+  (forth-assert-face "[ 48 ] →literal" font-lock-keyword-face)
+  (forth-assert-face "→: frob ;" font-lock-keyword-face)
+  (forth-assert-face ": →frob ;" font-lock-function-name-face)
+  (forth-assert-face "constant →foo" font-lock-function-name-face)
+  (forth-assert-face "create →foo" font-lock-function-name-face)
+  (forth-assert-face "value →foo" font-lock-function-name-face)
+  (forth-assert-face "variable →foo" font-lock-function-name-face)
+  (forth-assert-face "synonym →foo bar" font-lock-function-name-face))
 
 (ert-deftest forth-indent-colon-definition ()
   (forth-should-indent



reply via email to

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