;;; mathrender-test.el --- Tests for mathrender.el -*- lexical-binding: t; -*- (require 'ert) (require 'mathrender (expand-file-name "mathrender.el")) (ert-deftest mathrender-test-scan-display-math () "Test scanning of $$...$$ display math blocks." (with-temp-buffer (insert "Text before $$ a^2 + b^2 = c^2 $$ text after.") (mathrender--scan (point-min) (point-max)) (let ((ovs (overlays-in (point-min) (point-max)))) ;; 1 overlay created (should (= (length ovs) 1)) ;; Starts and ends exactly at the $$ delimiters (should (= (overlay-start (car ovs)) 13)) (should (= (overlay-end (car ovs)) 34)) (should (overlay-get (car ovs) 'mathrender-preview))))) (ert-deftest mathrender-test-scan-inline-math () "Test scanning of $...$ inline math blocks." (with-temp-buffer (insert "Inline $x=1$ math.") (mathrender--scan (point-min) (point-max)) (let ((ovs (overlays-in (point-min) (point-max)))) (should (= (length ovs) 1)) (should (= (overlay-start (car ovs)) 8)) (should (= (overlay-end (car ovs)) 13))))) (ert-deftest mathrender-test-scan-reject-invalid-single-dollar () "Test that single dollars used as currency or with invalid spacing are rejected." (with-temp-buffer ;; Invalid because there's a space after the first $, or it's a currency amount (insert "I have $ 5.00 and $10.00.") (mathrender--scan (point-min) (point-max)) (let ((ovs (overlays-in (point-min) (point-max)))) (should (= (length ovs) 0))))) (ert-deftest mathrender-test-parse-overlay () "Test that an overlay correctly extracts math text and inline status." (with-temp-buffer (insert "$$ \\int_0^1 x dx $$") (let ((ov (mathrender--make-overlay (point-min) (point-max)))) (let ((parsed (mathrender--parse-overlay ov))) (should (equal (car parsed) "\\int_0^1 x dx")) (should (equal (cdr parsed) nil)))))) ; nil means display math (provide 'mathrender-test) ;;; mathrender-test.el ends here