[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/forth-mode e966275c2e 100/153: Add tests for indentation
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/forth-mode e966275c2e 100/153: Add tests for indentation |
Date: |
Sat, 29 Jan 2022 08:02:22 -0500 (EST) |
branch: elpa/forth-mode
commit e966275c2e73ccde50f24927b01e8211643bd9ec
Merge: 3deee67777 8d1d8ea795
Author: Lars Brinkhoff <lars@nocrew.org>
Commit: GitHub <noreply@github.com>
Add tests for indentation
* test/tests.el: Add some tests.
* forth-smie.el (forth-smie--grammar): Add missing ?do ... +loop rule.
Remove {: ... :} as {: is currently a comment.
---
forth-smie.el | 2 +-
test/tests.el | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/forth-smie.el b/forth-smie.el
index bfe7086461..3bc14fb139 100644
--- a/forth-smie.el
+++ b/forth-smie.el
@@ -14,10 +14,10 @@
("of" words "endof")
("case" words "endcase")
("?do" words "loop")
+ ("?do" words "+loop")
("do" words "loop")
("do" words "+loop")
("begin-structure" words "end-structure")
- ("{:" words ":}")
(":" words ";"))
(words)))))
diff --git a/test/tests.el b/test/tests.el
index 9b3337fe16..dc680db763 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -29,6 +29,20 @@
(font-lock-fontify-buffer)
(should (eq face (get-text-property pos 'face))))))
+(defun forth-strip-| (string)
+ (replace-regexp-in-string "^[ \t]*|" "" (substring-no-properties string)))
+
+(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.
+The whitespace before and including \"|\" on each line is removed."
+ (let ((content (or content expected)))
+ (forth-with-temp-buffer (forth-strip-| content)
+ (let ((inhibit-message t)) ; Suppress "Indenting region ... done" message
+ (indent-region (point-min) (point-max)))
+ (should (string= (forth-strip-| expected)
+ (substring-no-properties (buffer-string)))))))
+
(ert-deftest forth-paren-comment-font-lock ()
(forth-assert-face "( )" 1 font-lock-comment-delimiter-face)
(forth-assert-face ".( )" 1 font-lock-comment-face)
@@ -79,3 +93,67 @@
(ert-deftest forth-parsing-words-font-lock ()
(forth-assert-face "postpone ( x " 11 nil)
(forth-assert-face "' s\" x " 6 nil))
+
+(ert-deftest forth-indent-colon-definition ()
+ (forth-should-indent
+ ": foo ( x y -- y x )
+ | swap
+ |;"))
+
+(ert-deftest forth-indent-if-then-else ()
+ (forth-should-indent
+ "x if
+ | 3 +
+ |then")
+ (forth-should-indent
+ "x if
+ | 3 +
+ |else
+ | 1+
+ |then"))
+
+(ert-deftest forth-indent-begin-while-repeat ()
+ (forth-should-indent
+ "begin
+ | 0>
+ |while
+ | 1-
+ |repeat")
+ (forth-should-indent
+ "begin
+ | 0>
+ |while
+ | begin
+ | foo
+ | while
+ | bar
+ | repeat
+ | 1-
+ |repeat"))
+
+;; FIXME: this kind of code is indented poorly (difficult for SMIE)
+;; |: foo ( )
+;; | begin
+;; | bar while
+;; | baz while
+;; |again then then ;
+
+(ert-deftest forth-indent-do ()
+ (forth-should-indent
+ "10 0 ?do
+ | .
+ |loop")
+ (forth-should-indent
+ "10 0 ?do
+ | . 2
+ |+loop"))
+
+(ert-deftest forth-indent-case ()
+ (forth-should-indent
+ "x case
+ | [char] f of
+ | foo
+ | endof
+ | [char] b of bar endof
+ | drop exit
+ |endcase"))
- [nongnu] elpa/forth-mode 1d85344467 113/153: Add commands to browse description in Forth standards, (continued)
- [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, 2022/01/29
- [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 <=
- [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