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

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

[nongnu] elpa/beancount ad26ec2b29 025/103: beancount.el: Add fontificat


From: ELPA Syncer
Subject: [nongnu] elpa/beancount ad26ec2b29 025/103: beancount.el: Add fontification tests
Date: Mon, 29 Apr 2024 15:59:42 -0400 (EDT)

branch: elpa/beancount
commit ad26ec2b29078f174899e8590eff17606389b302
Author: Daniele Nicolodi <daniele@grinta.net>
Commit: Daniele Nicolodi <daniele@grinta.net>

    beancount.el: Add fontification tests
---
 beancount-tests.el | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/beancount-tests.el b/beancount-tests.el
index 56f11a0a44..10e1b4d58d 100644
--- a/beancount-tests.el
+++ b/beancount-tests.el
@@ -23,3 +23,91 @@
   (with-temp-buffer
     (beancount-mode)
     (font-lock-ensure)))
+
+(defun beancount-test-fontify-string (string)
+  "Fontify STRING in beancount-mode."
+  (with-temp-buffer
+    (insert string)
+    (beancount-mode)
+    (font-lock-ensure)
+    (buffer-string)))
+
+(defun beancount-test-face-groups (fontified)
+  "Group a fontified string by face.
+Return a list of substrings each followed by its face."
+  (cl-loop for start = 0 then end
+           while start
+           for end   = (next-single-property-change start 'face fontified)
+           for prop  = (get-text-property start 'face fontified)
+           for text  = (substring-no-properties fontified start end)
+           if prop
+           append (list text prop)))
+
+(defun beancount-test-group-str-by-face (str)
+  "Fontify `str' in beancount-mode and group it by face.
+Return a list of substrings each followed by its face."
+  (beancount-test-face-groups (beancount-test-fontify-string str)))
+
+(defun beancount-test-font-lock (source face-groups)
+  "Test that `source' fontifies to the expected `face-groups'."
+  (should (equal (beancount-test-group-str-by-face source) face-groups)))
+
+(ert-deftest beancount/fontify-001 ()
+  :tags '(font regress)
+  (beancount-test-font-lock "
+2019-01-01 * \"Example\"
+  Expenses:Example  1.00 USD
+  Assets:Checking
+"
+   '("2019-01-01"       beancount-date
+     "*"                beancount-narrative-cleared
+     "\"Example\""      beancount-narrative-cleared
+     "Expenses:Example" beancount-account
+     "1.00 USD"         beancount-amount
+     "Assets:Checking"  beancount-account)))
+
+(ert-deftest beancount/fontify-002 ()
+  :tags '(font regress)
+  (beancount-test-font-lock "
+2019-01-01 ! \"Example\"
+  Expenses:Example  1.00 USD
+  Assets:Checking
+"
+   '("2019-01-01"       beancount-date
+     "!"                beancount-narrative-pending
+     "\"Example\""      beancount-narrative-pending
+     "Expenses:Example" beancount-account
+     "1.00 USD"         beancount-amount
+     "Assets:Checking"  beancount-account)))
+
+(ert-deftest beancount/fontify-003 ()
+  :tags '(font regress)
+  (beancount-test-font-lock "
+2019-01-01 A \"Example\"
+  Expenses:Example  1.00 USD
+  Assets:Checking
+"
+   '("2019-01-01"       beancount-date
+     "A"                beancount-narrative
+     "\"Example\""      beancount-narrative
+     "Expenses:Example" beancount-account
+     "1.00 USD"         beancount-amount
+     "Assets:Checking"  beancount-account)))
+
+(ert-deftest beancount/fontify-004 ()
+  :tags '(font regress)
+  (beancount-test-font-lock "
+2019-01-01 * \"Example\"
+  #foo
+  ^bar
+  Expenses:Example  1.00 USD
+  Assets:Checking
+"
+   '("2019-01-01"       beancount-date
+     "*"                beancount-narrative-cleared
+     "\"Example\""      beancount-narrative-cleared
+     "#foo"             beancount-tag
+     "^bar"             beancount-link
+     "Expenses:Example" beancount-account
+     "1.00 USD"         beancount-amount
+     "Assets:Checking"  beancount-account)))



reply via email to

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