[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/forth-mode d90c4a46e0 118/153: Use funny characters (→, ¹
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/forth-mode d90c4a46e0 118/153: Use funny characters (→, ¹ and ²) to mark positions in test strings. |
Date: |
Sat, 29 Jan 2022 08:02:24 -0500 (EST) |
branch: elpa/forth-mode
commit d90c4a46e01377e5f526966f4e26dd548aef775c
Author: Helmut Eller <eller.helmut@gmail.com>
Commit: Helmut Eller <eller.helmut@gmail.com>
Use funny characters (→, ¹ and ²) to mark positions in test strings.
Inserting those characters is easier and less error prone
than manually counting characters in strings.
* test/tests.el (forth-strip-|-and-→, forth-strip-|-and-¹²): New
helpers.
(forth-assert-face, forth-assert-forward-sexp,
forth-assert-forward-word): Use them.
Update uses accordingly.
---
test/tests.el | 180 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 93 insertions(+), 87 deletions(-)
diff --git a/test/tests.el b/test/tests.el
index 7026be1faa..0dfbdb3c19 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -28,15 +28,28 @@
(defun font-lock-ensure ()
(font-lock-fontify-buffer)))
-(defun forth-assert-face (content pos face)
- (when (boundp 'syntax-propertize-function)
- (forth-with-temp-buffer content
- (font-lock-ensure)
- (should (eq face (get-text-property pos 'face))))))
-
(defun forth-strip-| (string)
(replace-regexp-in-string "^[ \t]*|" "" (substring-no-properties string)))
+(defun forth-strip-|-and-→ (string)
+ (let* ((s2 (forth-strip-| string))
+ (pos (1+ (string-match "→" s2))))
+ (list (delete ?→ 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 end)))
+
+(defun forth-assert-face (content face)
+ (when (boundp 'syntax-propertize-function)
+ (destructuring-bind (content pos) (forth-strip-|-and-→ content)
+ (forth-with-temp-buffer content
+ (font-lock-ensure)
+ (should (eq face (get-text-property pos 'face)))))))
+
(defun forth-should-indent (expected &optional content)
"Assert that CONTENT turns into EXPECTED after the buffer is re-indented.
If CONTENT is not supplied uses EXPECTED as input.
@@ -50,94 +63,87 @@ The whitespace before and including \"|\" on each line is
removed."
(should (string= (forth-strip-| expected)
(substring-no-properties (buffer-string))))))))
-(defun forth-assert-forward-sexp (content start end)
- (forth-with-temp-buffer content
- (goto-char start)
- (forward-sexp)
- (should (= (point) end))))
-
-(defun forth-assert-forward-word (content start end)
- (forth-with-temp-buffer content
- (goto-char start)
- (font-lock-ensure) ; Make sure syntax-propertize function is called
- (forward-word)
- (should (= (point) end))))
+(defun forth-assert-forward-sexp (content)
+ (destructuring-bind (content start end) (forth-strip-|-and-¹² content)
+ (forth-with-temp-buffer content
+ (goto-char start)
+ (forward-sexp)
+ (should (= (point) end)))))
-(defun forth-strip-|-and-↓ (string)
- (let* ((s2 (forth-strip-| string))
- (pos (string-match "↓" s2)))
- (cons (delete ?↓ s2) pos)))
+(defun forth-assert-forward-word (content)
+ (destructuring-bind (content start end) (forth-strip-|-and-¹² content)
+ (forth-with-temp-buffer content
+ (goto-char start)
+ (font-lock-ensure) ; Make sure syntax-propertize function is called
+ (forward-word)
+ (should (= (point) end)))))
(defun forth-should-before/after (before after fun)
- (let* ((before+point (forth-strip-|-and-↓ before))
- (before (car before+point))
- (point-before (cdr before+point))
- (after+point (forth-strip-|-and-↓ after))
- (after (car after+point))
- (point-after (cdr after+point)))
- (forth-with-temp-buffer before
- (goto-char point-before)
- (funcall fun)
- (should (string= after (substring-no-properties (buffer-string))))
- (should (= (point) point-after)))))
+ (destructuring-bind (before point-before) (forth-strip-|-and-→ before)
+ (destructuring-bind (after point-after) (forth-strip-|-and-→ after)
+ (forth-with-temp-buffer before
+ (goto-char point-before)
+ (funcall fun)
+ (should (string= after (substring-no-properties (buffer-string))))
+ (should (= (point) point-after))))))
(ert-deftest forth-paren-comment-font-lock ()
- (forth-assert-face "( )" 1 font-lock-comment-delimiter-face)
- (forth-assert-face ".( )" 1 font-lock-comment-face)
- (forth-assert-face "( )" 3 font-lock-comment-delimiter-face)
- (forth-assert-face " ( )" 2 font-lock-comment-delimiter-face)
- (forth-assert-face "\t( )" 2 font-lock-comment-delimiter-face)
- (forth-assert-face "(\t)" 1 font-lock-comment-delimiter-face)
- (forth-assert-face "(foo) " 3 nil)
- (forth-assert-face "(foo)" 3 nil)
- (forth-assert-face "() " 2 nil)
- (forth-assert-face "( foo) " 3 font-lock-comment-face)
+ (forth-assert-face "→( )" font-lock-comment-delimiter-face)
+ (forth-assert-face "→.( )" font-lock-comment-face)
+ (forth-assert-face "( →)" font-lock-comment-delimiter-face)
+ (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 "(fo→o) " nil)
+ (forth-assert-face "(fo→o)" nil)
+ (forth-assert-face "(→) " nil)
+ (forth-assert-face "( →foo) " font-lock-comment-face)
(forth-assert-face "( a b --
- x y )" 1 font-lock-comment-delimiter-face))
+ →x y )" font-lock-comment-face))
(ert-deftest forth-backslash-comment-font-lock ()
- (forth-assert-face "\\" 1 nil)
- (forth-assert-face "\\ " 1 font-lock-comment-delimiter-face)
- (forth-assert-face " \\" 2 nil)
- (forth-assert-face "\t\\ " 2 font-lock-comment-delimiter-face)
- (forth-assert-face " \\\t" 2 font-lock-comment-delimiter-face)
- (forth-assert-face " \\\n" 2 font-lock-comment-delimiter-face)
- (forth-assert-face "a\\b" 2 nil)
- (forth-assert-face "a\\b " 2 nil))
+ (forth-assert-face "→\\" nil)
+ (forth-assert-face "→\\ " font-lock-comment-delimiter-face)
+ (forth-assert-face " →\\" nil)
+ (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)
+ (forth-assert-face "a→\\b" nil)
+ (forth-assert-face "a→\\b " nil))
(ert-deftest forth-brace-colon-font-lock ()
- (forth-assert-face "{: :}" 1 font-lock-comment-face)
- (forth-assert-face "{: :}" 5 font-lock-comment-face)
- (forth-assert-face "{: a b :}" 4 font-lock-comment-face)
- (forth-assert-face "{::}" 1 nil)
+ (forth-assert-face "→{: :}" font-lock-comment-face)
+ (forth-assert-face "{: :→}" font-lock-comment-face)
+ (forth-assert-face "{: →a b :}" font-lock-comment-face)
+ (forth-assert-face "→{::}" nil)
(forth-assert-face "{: a b --
- x y :}" 1 font-lock-comment-face)
- (forth-assert-face "t{ 2 1+ -> 3 }t" 2 nil))
+ →x y :}" font-lock-comment-face)
+ (forth-assert-face "t→{ 2 1+ -> 3 }t" nil))
(ert-deftest forth-string-font-lock ()
- (forth-assert-face "s\" ab\"" 1 nil)
- (forth-assert-face "s\" ab\"" 2 font-lock-string-face)
- (forth-assert-face "abort\" ab\"" 6 font-lock-string-face)
- (forth-assert-face ".\" ab\"" 2 font-lock-string-face)
- (forth-assert-face "c\" ab\"" 2 font-lock-string-face)
- (forth-assert-face "[char] \" of" 10 nil)
- (forth-assert-face "frob\" ab\" " 6 nil)
- (forth-assert-face "s\" 4 \n 8 " 4 font-lock-string-face)
- (forth-assert-face "s\" 4 \n 8 " 8 nil)
- (forth-assert-face "s\\\" ab\"" 1 nil)
- (forth-assert-face "s\\\" ab\"" 3 font-lock-string-face)
- (forth-assert-face "s\\\" ab\"" 6 font-lock-string-face)
- (forth-assert-face "s\\\" a\\\"c\"" 7 font-lock-string-face)
- (forth-assert-face "s\\\" \\\\ 7 \" 12" 7 font-lock-string-face)
- (forth-assert-face "s\\\" \\\\ 7 \" 12" 12 nil)
- (forth-assert-face "s\\\" \\\" 7 \" 12" 7 font-lock-string-face)
- (forth-assert-face "s\\\" \\\" 7 \" 12" 12 nil)
- (forth-assert-face "s\\\" 5 \n 9 " 4 font-lock-string-face)
- (forth-assert-face "s\\\" 5 \n 9 " 9 nil))
+ (forth-assert-face "→s\" ab\"" nil)
+ (forth-assert-face "s→\" ab\"" font-lock-string-face)
+ (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 "frob\" →ab\" " nil)
+ (forth-assert-face "s\" →a \n b " font-lock-string-face)
+ (forth-assert-face "s\" a \n →b " nil)
+ (forth-assert-face "→s\\\" ab\"" nil)
+ (forth-assert-face "s\\→\" ab\"" font-lock-string-face)
+ (forth-assert-face "s\\\" a→b\"" font-lock-string-face)
+ (forth-assert-face "s\\\" a\\\"→c\"" font-lock-string-face)
+ (forth-assert-face "s\\\" \\\\ →a \" b" font-lock-string-face)
+ (forth-assert-face "s\\\" \\\\ a \" →b" nil)
+ (forth-assert-face "s\\\" \\\" →a \" b" font-lock-string-face)
+ (forth-assert-face "s\\\" \\\" a \" →b" nil)
+ (forth-assert-face "s\\\" →a \n b " font-lock-string-face)
+ (forth-assert-face "s\\\" a \n →b " nil))
(ert-deftest forth-parsing-words-font-lock ()
- (forth-assert-face "postpone ( x " 11 nil)
- (forth-assert-face "' s\" x " 6 nil))
+ (forth-assert-face "postpone ( →x " nil)
+ (forth-assert-face "' s\" →x "nil))
(ert-deftest forth-indent-colon-definition ()
(forth-should-indent
@@ -212,15 +218,15 @@ The whitespace before and including \"|\" on each line is
removed."
|endcase"))
(ert-deftest forth-sexp-movements ()
- (forth-assert-forward-sexp " : foo bar ; \ x" 2 13)
- (forth-assert-forward-sexp " :noname foo bar ; \ x" 2 19)
- (forth-assert-forward-sexp " if drop exit else 1+ then bar " 2 27))
+ (forth-assert-forward-sexp " ¹: foo bar ;² \ x")
+ (forth-assert-forward-sexp " ¹:noname foo bar ;² \ x")
+ (forth-assert-forward-sexp " ¹if drop exit else 1+ then² bar "))
;; IDEA: give the filename in "include filename" string syntax.
(ert-deftest forth-word-movements ()
- (forth-assert-forward-word "include /tmp/foo.fth \ bar" 1 8)
- (forth-assert-forward-word "include /tmp/foo.fth \ bar" 8 13)
- (forth-assert-forward-word "foo-bar" 1 4))
+ (forth-assert-forward-word "¹include² /tmp/foo.fth \ bar")
+ (forth-assert-forward-word "include¹ /tmp²/foo.fth \ bar")
+ (forth-assert-forward-word "¹foo²-bar"))
(ert-deftest forth-spec-parsing ()
(should (equal (forth-spec--build-url "SWAP" 1994)
@@ -232,8 +238,8 @@ The whitespace before and including \"|\" on each line is
removed."
(ert-deftest forth-fill-comment ()
(forth-should-before/after
"\\ foo bar
- |\\ baz↓
+ |\\ baz→
|: frob ( x y -- z ) ;"
- "\\ foo bar baz↓
+ "\\ foo bar baz→
|: frob ( x y -- z ) ;"
#'fill-paragraph))
- [nongnu] elpa/forth-mode 05e8a02796 139/153: Highlight LEAVE, (continued)
- [nongnu] elpa/forth-mode 05e8a02796 139/153: Highlight LEAVE, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 1f922f41f4 138/153: Declare forth-smie-basic-indent as safe local-variable., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 74c0e17c45 122/153: Improve beginning-of-defun, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b40ffb3127 078/153: Fix building with Emacs 23., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 1d85344467 113/153: Add commands to browse description in Forth standards, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode c5e63e29f1 072/153: Basic indentation of control structures, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 0d22cedbaf 133/153: Improve indentation of BEGIN-STRUCTURE/END-STRUCTURE, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 47f33ea62a 063/153: Move interaction functions to forth-interactive-mode., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 6fac263222 068/153: Automatic build with Wercker., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 9cf3d777ec 064/153: Fix for C-c C-s forth-see., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode d90c4a46e0 118/153: Use funny characters (→, ¹ and ²) to mark positions in test strings.,
ELPA Syncer <=
- [nongnu] elpa/forth-mode c99ed046df 074/153: Remove debug message., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 64209f501c 108/153: Merge pull request #35 from ellerh/forward-sexp-tests, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode e6ee5ddf99 069/153: Handle ( ...) comments with syntax-propertize-function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode e966275c2e 100/153: Add tests for indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode dc3f7fabed 131/153: Use -y with apt-get., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode f531a1bcd7 096/153: Print test name in ERT shim., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 38d5152011 153/153: Version 0.2., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 9f885433e1 048/153: Use ERT for some light testing as part of build., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b9586a57a5 147/153: Add menu, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode fdc218c6f2 052/153: Don't get Makefile variable EMACS from environment; it may be set to 't'., ELPA Syncer, 2022/01/29