-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;;; nix-ts-mode-indent-test.el --- Indentation tests for nix-ts-mode. -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2024 Andreas Fuchs | ||
|
||
;; Author: Andreas Fuchs <[email protected]> | ||
;; Keywords: nix | ||
;; Package-Requires: ((emacs "29.1")) | ||
|
||
;; This file is NOT part of GNU Emacs. | ||
|
||
;;; Commentary: | ||
|
||
|
||
;; Tests for tree-sitter powered indentation in `nix-ts-mode`. | ||
|
||
;;; Code: | ||
(require 'ert) | ||
(require 'ert-x) | ||
(require 'nix-ts-mode) | ||
|
||
(defmacro with-nix-buffer-contents (&rest body) | ||
"Run `BODY` in the context of a new buffer set to `nix-ts-mode`." | ||
`(with-temp-buffer | ||
(delay-mode-hooks (nix-ts-mode)) | ||
,@body)) | ||
|
||
(defun check-indentation (contents) | ||
"Reindent CONTENTS according to nix-ts-mode's rules and check that it matches. | ||
CONTENT is a correctly-indented nix expression; all its lines' leading | ||
whitespace is stripped, then re-indented and checked that the | ||
output is identical to the given expression." | ||
(let ((dedented (replace-regexp-in-string "^\\s+" "" contents))) | ||
(insert dedented) | ||
(indent-region (point-min) (point-max)) | ||
(should (equal (buffer-substring (point-min) (point-max)) | ||
contents)))) | ||
|
||
;;; Features | ||
|
||
(ert-deftest nix-multiline-string () | ||
(ert-test-erts-file (ert-resource-file "indent-multiline-string.erts") | ||
(lambda () | ||
(nix-ts-mode) | ||
(indent-region (point-min) (point-max))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Name: simple-multiline-string | ||
|
||
=-= | ||
{ | ||
a = '' | ||
hi [ | ||
test | ||
] | ||
''; | ||
} | ||
=-= | ||
{ | ||
a = '' | ||
hi [ | ||
test | ||
] | ||
''; | ||
} | ||
=-=-= | ||
|
||
Name: multiline-string-with-interpolations | ||
|
||
=-= | ||
{ | ||
b = "hi"; | ||
a = '' | ||
${b} | ||
but also | ||
bye | ||
''; | ||
} | ||
=-= | ||
{ | ||
b = "hi"; | ||
a = '' | ||
${b} | ||
but also | ||
bye | ||
''; | ||
} | ||
=-=-= | ||
|
||
Name: multiline-string-with-escaped-interpolations | ||
|
||
=-= | ||
{ | ||
a = '' | ||
what=''${1:-hi} | ||
echo "$what" | ||
''; | ||
} | ||
=-= | ||
{ | ||
a = '' | ||
what=''${1:-hi} | ||
echo "$what" | ||
''; | ||
} | ||
=-=-= |