[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode ad9f398 028/104: Add some font-lock tests
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode ad9f398 028/104: Add some font-lock tests |
Date: |
Sun, 29 Aug 2021 11:36:57 -0400 (EDT) |
branch: elpa/zig-mode
commit ad9f39818cfcd6600d9e833e3e4ef55fb166300e
Author: Matthew D. Steele <mdsteele@alum.mit.edu>
Commit: Matthew D. Steele <mdsteele@alum.mit.edu>
Add some font-lock tests
---
tests.el | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/tests.el b/tests.el
index 9086175..2f81db3 100644
--- a/tests.el
+++ b/tests.el
@@ -4,6 +4,93 @@
(require 'zig-mode)
;;===========================================================================;;
+;; Font lock tests
+
+(defun zig-test-font-lock (code expected)
+ (let* ((fontified-code
+ (with-temp-buffer
+ (zig-mode)
+ (insert code)
+ (font-lock-fontify-buffer)
+ (buffer-string)))
+ (start 0)
+ (actual '()))
+ (while start
+ (let* ((end (next-single-property-change start 'face fontified-code))
+ (substring (substring-no-properties fontified-code start end))
+ (face (get-text-property start 'face fontified-code)))
+ (when face
+ (setq actual (cons (list substring face) actual)))
+ (setq start end)))
+ (should (equal expected (reverse actual)))))
+
+(ert-deftest test-font-lock-backslash-in-char-literal ()
+ (zig-test-font-lock
+ "const escaped = '\\'';"
+ '(("const" font-lock-keyword-face)
+ ("escaped" font-lock-variable-name-face)
+ ("'\\''" font-lock-string-face))))
+
+(ert-deftest test-font-lock-backslash-in-str-literal ()
+ (zig-test-font-lock
+ "\"This quote \\\" is escaped\""
+ '(("\"This quote \\\" is escaped\"" font-lock-string-face))))
+
+(ert-deftest test-font-lock-builtins ()
+ (zig-test-font-lock
+ "const std = @import(\"std\");"
+ '(("const" font-lock-keyword-face)
+ ("std" font-lock-variable-name-face)
+ ("@import" font-lock-builtin-face)
+ ("\"std\"" font-lock-string-face))))
+
+(ert-deftest test-font-lock-comments ()
+ (zig-test-font-lock
+ "
+// This is a normal comment\n
+/// This is a doc comment\n
+//// This is a normal comment again\n"
+ '(("// This is a normal comment\n" font-lock-comment-face)
+ ("/// This is a doc comment\n" font-lock-doc-face)
+ ("//// This is a normal comment again\n" font-lock-comment-face))))
+
+(ert-deftest test-font-lock-decl-const ()
+ (zig-test-font-lock
+ "const greeting = \"Hello, world!\";"
+ '(("const" font-lock-keyword-face)
+ ("greeting" font-lock-variable-name-face)
+ ("\"Hello, world!\"" font-lock-string-face))))
+
+(ert-deftest test-font-lock-decl-fn ()
+ (zig-test-font-lock
+ "fn plus1(value: u32) u32 { return value + 1; }"
+ '(("fn" font-lock-keyword-face)
+ ("plus1" font-lock-function-name-face)
+ ("value" font-lock-variable-name-face)
+ ("u32" font-lock-type-face)
+ ("u32" font-lock-type-face)
+ ("return" font-lock-keyword-face))))
+
+(ert-deftest test-font-lock-decl-var ()
+ (zig-test-font-lock
+ "var finished = false;"
+ '(("var" font-lock-keyword-face)
+ ("finished" font-lock-variable-name-face)
+ ("false" font-lock-constant-face))))
+
+(ert-deftest test-font-lock-multiline-str-literal ()
+ (zig-test-font-lock
+ "
+const python =
+ \\\\def main():
+ \\\\ print(\"Hello, world!\")
+;"
+ '(("const" font-lock-keyword-face)
+ ("python" font-lock-variable-name-face)
+ ("\\\\def main():\n" zig-multiline-string-face)
+ ("\\\\ print(\"Hello, world!\")\n" zig-multiline-string-face))))
+
+;;===========================================================================;;
;; Indentation tests
(defun zig-test-indent-region (original expected)
- [nongnu] elpa/zig-mode 9be8b72 080/104: upd: zig test flags, (continued)
- [nongnu] elpa/zig-mode 9be8b72 080/104: upd: zig test flags, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 68f3fc5 087/104: Update the required emacs version from 24 to 24.3, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode d263591 090/104: Account for opening brace after newline, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 07efab0 095/104: Merge pull request #48 from noisegul/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b6abeb4 093/104: Add a defvar to define if user wants to return to buffer after fmt., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode df572da 099/104: Add opaque keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode acf3ee8 104/104: Add GitHub Actions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2842797 007/104: Fix builtins. Reorder tables., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e69ebc0 012/104: and, or, @panic., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9a252eb 016/104: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ad9f398 028/104: Add some font-lock tests,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 2879253 029/104: Don't let backslashes escape newlines in multiline strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 4542a5d 036/104: add imenu support, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 604484c 039/104: M-x untabify, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 67ad48b 045/104: fix multiline string properties rules regex, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ab46e22 048/104: add some zig cli build commands, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode acebfb1 057/104: Add anyframe; remove promise, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fc7fde3 056/104: Merge pull request #23 from joachimschmidt557/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ad844c3 062/104: noasync -> nosuspend, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2c45c45 059/104: Merge pull request #24 from joachimschmidt557/add-anyframe, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 22187f4 076/104: Merge pull request #32 from joachimschmidt557/remove-this, ELPA Syncer, 2021/08/29