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

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

[nongnu] elpa/d-mode daf5e05 149/346: Add basic fontification test


From: ELPA Syncer
Subject: [nongnu] elpa/d-mode daf5e05 149/346: Add basic fontification test
Date: Sun, 29 Aug 2021 11:00:20 -0400 (EDT)

branch: elpa/d-mode
commit daf5e055115902b3ef79919fba22134689b83bde
Author: Vladimir Panteleev <git@thecybershadow.net>
Commit: Vladimir Panteleev <git@thecybershadow.net>

    Add basic fontification test
---
 d-mode-test.el     | 20 ++++++++++++++++++++
 tests/fonts.d      |  6 ++++++
 tests/fonts.d.html |  6 ++++++
 3 files changed, 32 insertions(+)

diff --git a/d-mode-test.el b/d-mode-test.el
index c7da07b..58ee5f4 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -54,6 +54,8 @@
 
 (require 'd-mode nil t)
 
+(require 'htmlfontify)
+
 (defconst d-test-teststyle
   '((c-tab-always-indent . t)
     (c-basic-offset . 2)
@@ -256,6 +258,23 @@ If the resulting indentation ends up being different, 
raise an error."
                      "Got:     
\n--------------------\n%s\n--------------------\n")
              orig (buffer-string))))))
 
+(defun d-test-fontification ()
+  "Test fontification the current file.
+
+Compares fontification against a test file (same file name, with
+a '.html' suffix).  If the result ends up being different from
+the reference file, raise an error."
+  (let* ((hfy-optimizations '(body-text-only merge-adjacent-tags))
+        (actual (with-current-buffer (htmlfontify-buffer nil "test.d") 
(buffer-string)))
+        (expected (with-temp-buffer
+                    (insert-file-contents (concat filename ".html"))
+                    (buffer-string))))
+    (unless (equal actual expected)
+      (error (concat "Test case has been fontified differently.\n"
+                    
"Expected:\n--------------------\n%s\n--------------------\n"
+                    "Got:     
\n--------------------\n%s\n--------------------\n")
+            expected actual))))
+
 (defmacro d-test-deftest (name filename expected-result)
   "Define a d-mode test using the given FILENAME.
 
@@ -267,6 +286,7 @@ is expected to succeed, and nil otherwise."
 
 ;; Run the tests
 (d-test-deftest imenu "tests/imenu.d" t)
+(d-test-deftest fonts "tests/fonts.d" t)
 (d-test-deftest i0021 "tests/I0021.d" t)
 (d-test-deftest i0026 "tests/I0026.d" t)
 (d-test-deftest i0035 "tests/I0035.d" (version< "24.4" emacs-version))
diff --git a/tests/fonts.d b/tests/fonts.d
new file mode 100644
index 0000000..3c4ce87
--- /dev/null
+++ b/tests/fonts.d
@@ -0,0 +1,6 @@
+// #run: (d-test-fontification)
+
+void main()
+{
+       assert(true);
+}
diff --git a/tests/fonts.d.html b/tests/fonts.d.html
new file mode 100644
index 0000000..8096111
--- /dev/null
+++ b/tests/fonts.d.html
@@ -0,0 +1,6 @@
+<span class="comment-delimiter">// </span><span class="comment">#run: 
(d-test-fontification)
+</span>
+<span class="type">void</span> <span class="function-name">main</span>()
+{
+       <span class="keyword">assert</span>(<span class="constant">true</span>);
+}



reply via email to

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