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

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

[nongnu] elpa/forth-mode 66f7a2dc97 060/153: Add tests for various Forth


From: ELPA Syncer
Subject: [nongnu] elpa/forth-mode 66f7a2dc97 060/153: Add tests for various Forth block and non-block files.
Date: Sat, 29 Jan 2022 08:02:16 -0500 (EST)

branch: elpa/forth-mode
commit 66f7a2dc9736ec28745a963c64a5aa54550bc89c
Author: Lars Brinkhoff <lars.brinkhoff@delphi.com>
Commit: Lars Brinkhoff <lars.brinkhoff@delphi.com>

    Add tests for various Forth block and non-block files.
---
 build.el            | 14 ++++----------
 forth-block-mode.el |  4 ++++
 forth-mode.el       | 20 +++++++++++++++++---
 test/block1.fth     |  1 +
 test/block2.fth     | 32 ++++++++++++++++++++++++++++++++
 test/noblock.fth    |  1 +
 test/tests.el       | 23 +++++++++++++++++++++++
 7 files changed, 82 insertions(+), 13 deletions(-)

diff --git a/build.el b/build.el
index f0c599d040..6172088e19 100644
--- a/build.el
+++ b/build.el
@@ -3,7 +3,7 @@
 (let ((generated-autoload-file (concat default-directory "autoloads.el")))
   (update-directory-autoloads "."))
 (load-file "autoloads.el")
-(add-to-list 'load-path ".")
+(add-to-list 'load-path default-directory)
 
 (if (locate-library "ert")
     (require 'ert)
@@ -18,13 +18,7 @@
   "Compile package."
   (should-not (string-match "failed" (byte-recompile-directory "." 0))))
 
-(ert-deftest load-forth-mode ()
-  "Load forth-mode."
-  (should (require 'forth-mode))
-  (should (featurep 'forth-mode))
-  (with-temp-buffer
-    (forth-mode)
-    (should (eq major-mode 'forth-mode))
-    (kill-buffer)))
+(load-file "test/tests.el")
 
-(ert-run-tests-batch-and-exit)
+;;; Ensure compile-package is run first.
+(ert-run-tests-batch-and-exit '(or compile-package t))
diff --git a/forth-block-mode.el b/forth-block-mode.el
index 84be683e35..5d577fdcfb 100644
--- a/forth-block-mode.el
+++ b/forth-block-mode.el
@@ -1,6 +1,8 @@
 (require 'cl)
 (require 'forth-mode)
 
+(defvar forth-block-with-newlines)
+
 (defun forth-line (n)
   (goto-char (point-min))
   (forward-line (1- n)))
@@ -80,6 +82,8 @@
 (define-minor-mode forth-block-mode
   "Minor mode for Forth code in blocks."
   :lighter " block"
+  (make-local-variable 'forth-block-with-newlines)
+  (setq forth-block-with-newlines (forth-block-with-newlines-p))
   (setq require-final-newline nil)
   (forth-unblockify)
   (add-hook 'before-save-hook 'forth-blockify nil t)
diff --git a/forth-mode.el b/forth-mode.el
index f298a84269..cd706954ac 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -79,13 +79,27 @@
            (push (car def) list)))))
     (list (forth-symbol-start) (forth-symbol-end) list)))
 
+(defun forth-block-with-newlines-p ()
+  (save-excursion
+    (forth-beginning)
+    (let ((result t))
+      (dotimes (i 16)
+       (goto-char (* 64 (1+ i)))
+       (unless (looking-at "\n")
+         (setq result nil)))
+      result)))
+
+(defun forth-block-without-newlines-p ()
+  (save-excursion
+    (forth-beginning)
+    (not (search-forward "\n" 1024 t))))
+
 (defun forth-block-p ()
   "Guess whether the current buffer is a Forth block file."
   (and (> (point-max) 1)
        (eq (logand (point-max) 1023) 1)
-       (save-excursion
-        (forth-beginning)
-        (not (search-forward "\n" 1024 t)))))
+       (or (forth-block-with-newlines-p)
+          (forth-block-without-newlines-p))))
 
 (unless (fboundp 'prog-mode)
   (defalias 'prog-mode 'fundamental-mode))
diff --git a/test/block1.fth b/test/block1.fth
new file mode 100644
index 0000000000..2a09adf2fe
--- /dev/null
+++ b/test/block1.fth
@@ -0,0 +1 @@
+                                                                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
              [...]
\ No newline at end of file
diff --git a/test/block2.fth b/test/block2.fth
new file mode 100644
index 0000000000..e9fae59544
--- /dev/null
+++ b/test/block2.fth
@@ -0,0 +1,32 @@
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
+                                                               
diff --git a/test/noblock.fth b/test/noblock.fth
new file mode 100644
index 0000000000..f08b6c74c3
--- /dev/null
+++ b/test/noblock.fth
@@ -0,0 +1 @@
+: foo ;
diff --git a/test/tests.el b/test/tests.el
new file mode 100644
index 0000000000..840230d608
--- /dev/null
+++ b/test/tests.el
@@ -0,0 +1,23 @@
+(ert-deftest load-forth-mode ()
+  "Load forth-mode."
+  (should (require 'forth-mode))
+  (should (featurep 'forth-mode))
+  (with-temp-buffer
+    (forth-mode)
+    (should (eq major-mode 'forth-mode))
+    (kill-buffer)))
+
+(ert-deftest load-not-block ()
+  (find-file "test/noblock.fth")
+  (should (eq major-mode 'forth-mode))
+  (should-not (and (boundp 'forth-block-mode) forth-block-mode)))
+
+(ert-deftest load-block-with-newlines ()
+  (find-file "test/block2.fth")
+  (should (eq major-mode 'forth-mode))
+  (should (and (boundp 'forth-block-mode) forth-block-mode)))
+
+(ert-deftest load-block-without-newlines ()
+  (find-file "test/block1.fth")
+  (should (eq major-mode 'forth-mode))
+  (should (and (boundp 'forth-block-mode) forth-block-mode)))



reply via email to

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