[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 6445ebfad6 285/500: Merge pull request #63 from e
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 6445ebfad6 285/500: Merge pull request #63 from etu/ert-indent-testing |
Date: |
Sat, 29 Jan 2022 08:27:14 -0500 (EST) |
branch: elpa/nix-mode
commit 6445ebfad696bdfd1d7bc8ddd463772ba61763e8
Merge: 7f968e8a7f 02b59d9bcf
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #63 from etu/ert-indent-testing
Ert indent testing
---
tests/nix-mode-tests.el | 66 +++++++++++++++++++++++++++++++++++++++
tests/testcases/issue-60.1.nix | 7 +++++
tests/testcases/issue-60.2.nix | 8 +++++
tests/testcases/issue-60.3.nix | 8 +++++
tests/testcases/list-contents.nix | 14 +++++++++
5 files changed, 103 insertions(+)
diff --git a/tests/nix-mode-tests.el b/tests/nix-mode-tests.el
index d92a02fef5..7505908834 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,70 @@
(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)))
+
+(ert-deftest nix-mode-indent-test-list-contents ()
+ "Proper indentation for items inside of a list."
+ (with-nix-mode-test ("list-contents.nix" :indent t)))
+
+(ert-deftest nix-mode-test-indent-issue-60-1 ()
+ "Proper indentation of attrsets inside of lists inside of attrsets.
+
+Related issue: https://github.com/NixOS/nix-mode/issues/60"
+ (with-nix-mode-test ("issue-60.1.nix" :indent t)))
+
+(ert-deftest nix-mode-test-indent-issue-60-2 ()
+ "Proper indentation of code inside of let blocks.
+
+Related issue: https://github.com/NixOS/nix-mode/issues/60"
+ (with-nix-mode-test ("issue-60.2.nix" :indent t)))
+
+(ert-deftest nix-mode-test-indent-issue-60-3 ()
+ "Proper indentation of import and newline after equal.
+
+Related issue: https://github.com/NixOS/nix-mode/issues/60"
+ (with-nix-mode-test ("issue-60.3.nix" :indent t)))
+
(provide 'nix-mode-tests)
;;; nix-mode-tests.el ends here
diff --git a/tests/testcases/issue-60.1.nix b/tests/testcases/issue-60.1.nix
new file mode 100644
index 0000000000..c575243447
--- /dev/null
+++ b/tests/testcases/issue-60.1.nix
@@ -0,0 +1,7 @@
+{
+ x86 = [
+ {
+ name = "t1.small.x86";
+ }
+ ];
+}
diff --git a/tests/testcases/issue-60.2.nix b/tests/testcases/issue-60.2.nix
new file mode 100644
index 0000000000..7a27cf793d
--- /dev/null
+++ b/tests/testcases/issue-60.2.nix
@@ -0,0 +1,8 @@
+let
+ x = [
+ (let y = 1; in y)
+ { foo = 1; }
+ [ 1 2 3 ]
+ x
+ ];
+in x
diff --git a/tests/testcases/issue-60.3.nix b/tests/testcases/issue-60.3.nix
new file mode 100644
index 0000000000..1cf7350a78
--- /dev/null
+++ b/tests/testcases/issue-60.3.nix
@@ -0,0 +1,8 @@
+let
+ mozilla-overlay =
+ import
+ (
+ builtins.fetchTarball
+ https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
+ );
+in mozilla-overlay
diff --git a/tests/testcases/list-contents.nix
b/tests/testcases/list-contents.nix
new file mode 100644
index 0000000000..4c6630eb32
--- /dev/null
+++ b/tests/testcases/list-contents.nix
@@ -0,0 +1,14 @@
+[
+ 1
+ false
+ true
+ https://nixos.org/
+ {
+ attr = "set";
+ }
+ [
+ "nested"
+ "list"
+ ]
+ "string"
+]
- [nongnu] elpa/nix-mode ef2efae30a 482/500: nix-flake: Use flatten-list and bump Emacs to 27.1, (continued)
- [nongnu] elpa/nix-mode ef2efae30a 482/500: nix-flake: Use flatten-list and bump Emacs to 27.1, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c4e4f386b7 490/500: chore: Add nix-flake.el to Cask, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 10fc00dba8 015/500: Fix bad setting for indent-tabs-mode., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 630cc427cd 009/500: Update builtins, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 295bcbd919 023/500: Don't indent strings, comments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7a97635267 025/500: Move to nix-re-file-path, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c08ae1cdfe 049/500: Add limit arg to looking-back., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 504285ce39 138/500: Remove nix-buffer, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c06222659c 185/500: Don’t enable mmm-mode automatically, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 858d127fb5 259/500: Add custom for directory location, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6445ebfad6 285/500: Merge pull request #63 from etu/ert-indent-testing,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 54ef833100 294/500: Merge pull request #68 from etu/fix-recent-regressions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e8921b8a78 295/500: Prioritize closing } over regular indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 80a1e96c71 296/500: Merge branch 'grahamc-fix-issue-69', ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 53ea839a52 418/500: Replace javascript-mode with js-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aae6f710e0 404/500: Address review comments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d27820b040 442/500: Merge pull request #131 from nagy/nix-process-refactor, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5f44621864 474/500: nix-flake: Make the argument bindings more predictable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a18a226ce9 123/500: Add nix-mode tests., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9e59bcf59e 216/500: Fix read only .drv file issue, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8ab089b251 230/500: Set nix-shell-attribute, ELPA Syncer, 2022/01/29