[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 407051ad31 175/500: Add font-lock-tests.el file
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 407051ad31 175/500: Add font-lock-tests.el file |
Date: |
Sat, 29 Jan 2022 08:27:04 -0500 (EST) |
branch: elpa/nix-mode
commit 407051ad3183418b75e3581b105f5bc786cac114
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>
Add font-lock-tests.el file
Based on Haskell’s font-lock-tests file.
---
tests/nix-font-lock-tests.el | 80 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/tests/nix-font-lock-tests.el b/tests/nix-font-lock-tests.el
new file mode 100644
index 0000000000..1ec0008b6a
--- /dev/null
+++ b/tests/nix-font-lock-tests.el
@@ -0,0 +1,80 @@
+;; -*- lexical-binding: t -*-
+(require 'ert)
+(require 'nix-mode)
+
+(defun check-syntax-and-face-match-range (beg end syntax face)
+ "Check if all charaters between positions BEG and END have
+syntax set to SYNTAX and face set to FACE.
+If SYNTAX or FACE are set to t then any syntex respective face is
+not checked."
+ (let (all-syntaxes
+ all-faces
+ (syntax-classes "-.w_()'\"$\\/<>@!|")
+ (text (buffer-substring-no-properties beg end)))
+ (while (< beg end)
+ (cl-pushnew (char-to-string (aref syntax-classes (syntax-class
(syntax-after beg)))) all-syntaxes :test #'equal)
+ (cl-pushnew (get-text-property beg 'face) all-faces :test #'equal)
+ (setq beg (1+ beg)))
+ (unless (eq syntax t)
+ (should (equal (list text (mapconcat #'identity (sort (mapcar (lambda
(syn) (char-to-string syn)) syntax) #'string<) ""))
+ (list text (mapconcat #'identity (sort all-syntaxes
#'string<) "")))))
+ (unless (eq face t)
+ (should (equal (list text (list face))
+ (list text all-faces))))))
+
+(defmacro with-nix-test-buffer (mode &rest body)
+ "Run BODY in the context of a new buffer set to `nix-mode'.
+Buffer is named *nix-mode-buffer*. It is not deleted
+after a test as this aids interactive debugging."
+ (declare (indent 1) (debug t))
+ `(progn
+ ;; we want to create buffer from scratch so that there are no
+ ;; leftover state from the previous test
+ (when (get-buffer "*nix-test-buffer*")
+ (kill-buffer "*nix-test-buffer*"))
+ (save-current-buffer
+ (set-buffer (get-buffer-create "*nix-test-buffer*"))
+ (funcall ,mode)
+ ,@body)))
+
+(defun check-properties (lines-or-contents props &optional mode)
+ "Check if syntax properties and font-lock properties as set properly.
+LINES is a list of strings that will be inserted to a new
+buffer. Then PROPS is a list of tripples of (string syntax
+face). String is searched for in the buffer and then is checked
+if all of its characters have syntax and face. See
+`check-syntax-and-face-match-range`."
+ (with-nix-test-buffer (or mode #'nix-mode)
+ (if (consp lines-or-contents)
+ (dolist (line lines-or-contents)
+ (let ((pos (point)))
+ (insert line "\n")
+ (save-excursion
+ ;; For some reason font-lock-fontify-region
moves the
+ ;; point. I do not think it is guaranteed it
should not,
+ ;; but then it might be our fault.
Investigate later.
+ (font-lock-fontify-region pos (point)))))
+ (insert lines-or-contents)
+ (font-lock-fontify-buffer))
+
+ (goto-char (point-min))
+ (dolist (prop props)
+ (cl-destructuring-bind (string syntax face) prop
+ (let ((case-fold-search nil))
+ (search-forward string))
+ (check-syntax-and-face-match-range
(match-beginning 0) (match-end 0) syntax face)))))
+
+
+(ert-deftest nix-equals-1 ()
+ (check-properties
+ '("pattern = 3")
+ '(("pattern" t nix-attribute-face))))
+
+(ert-deftest nix-equals-2 ()
+ (check-properties
+ '("pattern == 3")
+ '(("pattern" t nil))))
+
+;; Local Variables:
+;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
+;; End:
- [nongnu] elpa/nix-mode 956280c161 116/500: Refactor nix--antiquote-close, (continued)
- [nongnu] elpa/nix-mode 956280c161 116/500: Refactor nix--antiquote-close, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode de02e17924 135/500: Fix fontification of "}${" in some contexts, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0b19f975cd 143/500: Merge pull request #28 from pvmart/fix-nix-mmm, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 719482b701 148/500: Update customizations for Nix related modes., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b3c6560f6d 166/500: Fix typo: rustfmt -> nixfmt, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 038dcf7b1b 147/500: Cleanup, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3edda90cfd 146/500: Remove nix-flycheck, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a967408f64 188/500: Don’t error when nix-shebang fails., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 05d7c828b3 187/500: Fix nix-company and mmm-mode loading., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 281bfc1abf 176/500: Cleanup font-locks again, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 407051ad31 175/500: Add font-lock-tests.el file,
ELPA Syncer <=
- [nongnu] elpa/nix-mode d341ef2f70 195/500: Add missing defcustom type, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode eb7623fb3b 178/500: Handle mmm-mode '' prefixes better, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cc88a55ead 173/500: Add custom faces for Nix., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0181c35a4f 202/500: Add nix-unpack command., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0ac0271f6c 201/500: Update Homepage in .el files, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 39f29d8be4 207/500: Replace indentation code with simpler heuristics, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 57ac40d53b 214/500: Merge pull request #45 from eqyiel/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ba202b6657 220/500: Add nix-shell.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 082a25ba7d 227/500: Add more default packages in nix.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b98c1083a0 234/500: nix-shell-file not risky, ELPA Syncer, 2022/01/29