Slightly hacky but good enough math rendering in emacs 馃獎
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 6eb8ec58b6a4123fdfdab53e4328130b42cb26da 48 lines 2.0 kB view raw
1;;; mathrender-test.el --- Tests for mathrender.el -*- lexical-binding: t; -*- 2 3(require 'ert) 4(require 'mathrender (expand-file-name "mathrender.el")) 5 6(ert-deftest mathrender-test-scan-display-math () 7 "Test scanning of $$...$$ display math blocks." 8 (with-temp-buffer 9 (insert "Text before $$ a^2 + b^2 = c^2 $$ text after.") 10 (mathrender--scan (point-min) (point-max)) 11 (let ((ovs (overlays-in (point-min) (point-max)))) 12 ;; 1 overlay created 13 (should (= (length ovs) 1)) 14 ;; Starts and ends exactly at the $$ delimiters 15 (should (= (overlay-start (car ovs)) 13)) 16 (should (= (overlay-end (car ovs)) 34)) 17 (should (overlay-get (car ovs) 'mathrender-preview))))) 18 19(ert-deftest mathrender-test-scan-inline-math () 20 "Test scanning of $...$ inline math blocks." 21 (with-temp-buffer 22 (insert "Inline $x=1$ math.") 23 (mathrender--scan (point-min) (point-max)) 24 (let ((ovs (overlays-in (point-min) (point-max)))) 25 (should (= (length ovs) 1)) 26 (should (= (overlay-start (car ovs)) 8)) 27 (should (= (overlay-end (car ovs)) 13))))) 28 29(ert-deftest mathrender-test-scan-reject-invalid-single-dollar () 30 "Test that single dollars used as currency or with invalid spacing are rejected." 31 (with-temp-buffer 32 ;; Invalid because there's a space after the first $, or it's a currency amount 33 (insert "I have $ 5.00 and $10.00.") 34 (mathrender--scan (point-min) (point-max)) 35 (let ((ovs (overlays-in (point-min) (point-max)))) 36 (should (= (length ovs) 0))))) 37 38(ert-deftest mathrender-test-parse-overlay () 39 "Test that an overlay correctly extracts math text and inline status." 40 (with-temp-buffer 41 (insert "$$ \\int_0^1 x dx $$") 42 (let ((ov (mathrender--make-overlay (point-min) (point-max)))) 43 (let ((parsed (mathrender--parse-overlay ov))) 44 (should (equal (car parsed) "\\int_0^1 x dx")) 45 (should (equal (cdr parsed) nil)))))) ; nil means display math 46 47(provide 'mathrender-test) 48;;; mathrender-test.el ends here