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.

add basic tests

+83
+48
mathrender-test.el
··· 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
+35
src/main.rs
··· 339 339 std::process::exit(1); 340 340 } 341 341 } 342 + } 343 + 344 + #[cfg(test)] 345 + mod tests { 346 + use super::*; 347 + 348 + #[test] 349 + fn test_safe_tex2typst() { 350 + let mut buf = String::new(); 351 + safe_tex2typst("x = 1", &mut buf); 352 + assert!(buf.contains("x = 1")); 353 + } 354 + 355 + #[test] 356 + fn test_convert_matrix() { 357 + let mut buf = String::new(); 358 + env_matrix_convert("pmatrix", "1 & 2 \\\\ 3 & 4", &mut buf); 359 + assert_eq!(buf, "mat(1, 2; 3, 4)"); 360 + } 361 + 362 + #[test] 363 + fn test_convert_cases() { 364 + let mut buf = String::new(); 365 + env_cases_convert("x & y \\\\ a & b", &mut buf); 366 + assert!(buf.contains("cases(")); 367 + assert!(buf.contains("x")); 368 + assert!(buf.contains("y")); 369 + } 370 + 371 + #[test] 372 + fn test_latex_to_typst() { 373 + let input = "x + \\begin{pmatrix} 1 & 2 \\\\ 3 & 4 \\end{pmatrix} = y"; 374 + let result = latex_to_typst(input); 375 + assert!(result.contains("mat(1, 2; 3, 4)")); 376 + } 342 377 }