Add Unicode math output formatting

This commit is contained in:
Hermes Agent
2026-09-11 13:54:01 +02:00
parent b2d2ba58fc
commit 6bb572f9e4
7 changed files with 206 additions and 6 deletions
+9
View File
@@ -13,6 +13,7 @@ def test_load_default_config(tmp_path):
assert cfg.provider == "ollama"
assert cfg.hotkey == "ctrl+alt+a"
assert cfg.math_text_format == "unicode"
assert "Réponds directement" in cfg.system_prompt
@@ -25,6 +26,14 @@ def test_timeout_zero_disables_timeout(tmp_path):
assert cfg.request_timeout_seconds is None
def test_reject_invalid_math_text_format(tmp_path):
path = tmp_path / "config.json"
path.write_text(json.dumps({"provider": "ollama", "math_text_format": "bad"}), encoding="utf-8")
with pytest.raises(ValueError):
load_config(path)
def test_reject_invalid_provider(tmp_path):
path = tmp_path / "config.json"
path.write_text(json.dumps({"provider": "bad"}), encoding="utf-8")
+24
View File
@@ -0,0 +1,24 @@
import pytest
from ai_typewriter.math_format import format_math_text
def test_plain_mode_keeps_linear_math_literal():
assert format_math_text("z_1 + x^2", "plain") == "z_1 + x^2"
def test_unicode_mode_converts_indices_exponents_and_symbols():
result = format_math_text(r"z_1 + x^2 + x_(i+1) + \alpha + \infty", "unicode")
assert result == "z₁ + x² + xᵢ₊₁ + α + ∞"
def test_unicode_mode_converts_common_operators():
result = format_math_text(r"\int_0^1 f(x) dx \leq \sum_(k=1)^n a_k", "unicode")
assert result == "∫₀¹ f(x) dx ≤ ∑ₖ₌₁ⁿ aₖ"
def test_invalid_math_text_format_is_rejected():
with pytest.raises(ValueError):
format_math_text("x_1", "bad")