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

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

[nongnu] elpa/nix-mode 0c0ec7dbd6 281/500: ert/indent: Add macro to easi


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 0c0ec7dbd6 281/500: ert/indent: Add macro to easily test indentation
Date: Sat, 29 Jan 2022 08:27:14 -0500 (EST)

branch: elpa/nix-mode
commit 0c0ec7dbd66c6f39d65a91d169e25fb03de0fa5c
Author: Elis Hirwing <elis@hirwing.se>
Commit: Elis Hirwing <elis@hirwing.se>

    ert/indent: Add macro to easily test indentation
---
 tests/nix-mode-tests.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/tests/nix-mode-tests.el b/tests/nix-mode-tests.el
index d92a02fef5..4ed5208c29 100644
--- a/tests/nix-mode-tests.el
+++ b/tests/nix-mode-tests.el
@@ -4,6 +4,7 @@
 
 ;;; Code:
 
+(require 'cl-lib)
 (require 'ert)
 (require 'nix-mode)
 
@@ -26,5 +27,48 @@
             (nix-mode)
             (eq (nix--get-string-type (nix--get-parse-state (point))) nil))))
 
+;;; Indentation tests
+
+(defvar nix-mode-test-dir (expand-file-name "testcases"
+                                            (if load-file-name
+                                                (file-name-directory 
load-file-name)
+                                              default-directory))
+  "Directory containing the `nix-mode' testcase files.")
+
+;; Define macro to build indentation tests
+(cl-defmacro with-nix-mode-test ((file &key indent) &rest body)
+  "Set up environment for testing `nix-mode'.
+Execute BODY in a temporary buffer containing the contents of
+FILE, in `nix-mode'. All tests will use the `nix-indent-line'
+function to do the indentation tests."
+
+  `(with-temp-buffer
+     ;; Read test data file
+     (insert-file-contents (expand-file-name ,file nix-mode-test-dir))
+
+     ;; Store the file as a local variable and set the right indentation 
function to use
+     (let ((raw-file (buffer-substring-no-properties (point-min) (point-max)))
+           (nix-indent-function 'nix-indent-line)
+           (inhibit-message t))
+       ;; Load up nix-mode
+       (nix-mode)
+
+       ;; If we're doing an indentation test
+       (if ,indent
+           (progn
+             ;; Indent the buffer
+             (indent-region (point-min) (point-max))
+
+             ;; Compare buffer to the stored buffer contents
+             (should (equal
+                      (buffer-substring-no-properties (point-min) (point-max))
+                      raw-file))))
+
+       ;; Go to beginning
+       (goto-char (point-min))
+
+       ;; Run additional tests
+       ,@body)))
+
 (provide 'nix-mode-tests)
 ;;; nix-mode-tests.el ends here



reply via email to

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