branch: elpa/beancount commit ad26ec2b29078f174899e8590eff17606389b302 Author: Daniele Nicolodi <dani...@grinta.net> Commit: Daniele Nicolodi <dani...@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)))