[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/forth-mode 952995d95e 098/153: Add tests for indentation
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/forth-mode 952995d95e 098/153: Add tests for indentation |
Date: |
Sat, 29 Jan 2022 08:02:22 -0500 (EST) |
branch: elpa/forth-mode
commit 952995d95e665af26be01c97735e36ec33348214
Author: Helmut Eller <helmut@msibook>
Commit: Helmut Eller <helmut@msibook>
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 | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 82 insertions(+), 5 deletions(-)
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..a8f978247a 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -24,10 +24,23 @@
,@body))
(defun forth-assert-face (content pos face)
- (when (boundp 'syntax-propertize-function)
- (forth-with-temp-buffer content
- (font-lock-fontify-buffer)
- (should (eq face (get-text-property pos 'face))))))
+ (forth-with-temp-buffer content
+ (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)
@@ -79,3 +92,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 1a05d27d82 077/153: Fix loading backend file., (continued)
- [nongnu] elpa/forth-mode 1a05d27d82 077/153: Fix loading backend file., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b95f1b8a02 146/153: Fix typos in doc, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 2e75fb156f 081/153: Fix warning about defvar ignored., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 96c20f03f5 128/153: Make completion-at-point test work with Emacs23, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 867922d61e 112/153: Handle string literals more correctly, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 16f359442e 109/153: Add tests for word movement commands, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 45650c28a2 140/153: Check if forth interactive buffer is live, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode ab790fdac8 091/153: Don't kill *forth* buffer when there's a fatal error., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode be0272be3a 076/153: Inhibut Gforth terminal attribute output., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 312f3860aa 124/153: Try to indent (foo), ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 952995d95e 098/153: Add tests for indentation,
ELPA Syncer <=
- [nongnu] elpa/forth-mode 0bbf7992d6 135/153: Workaround pcase bug in Emacs-24.3, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode ee0781f0a8 066/153: Add more functions for evaluating Forth expressions., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 1ffc174c13 127/153: Pass Makefile variable FORTH as environment variable to build.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 9b0982e169 149/153: Fix CI, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 52d84393c0 141/153: Remove newlines to fix markdown formatting., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 2d30ca8eaa 142/153: Use add-to-list in installation instructions instead of pushnew., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 8c0e519c57 148/153: Add restart-forth to source window menu, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 5e99586c1e 065/153: Remove prompt from Forth output., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 6bc035fd90 040/153: Fix missing argument to define-key., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode fbd2c51cea 070/153: Initialize pseudo terminal window size, ELPA Syncer, 2022/01/29