| Server IP : 3.147.158.171 / Your IP : 216.73.216.216 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/api/tests/unit/ |
Upload File : |
"""Unit tests for inline TeX-math normalization."""
from app.utilities.math_tex import convert_math
def test_schwarzschild_criterion_display_math():
# The real bug: a $$...$$ formula leaks verbatim into the published HTML
# (with > already HTML-escaped by the markdown renderer).
html = '<p>The criterion: $$\\nabla_\\text{rad} > \\nabla_\\text{ad}$$</p>'
out = convert_math(html)
assert out == (
'<p>The criterion: '
'<span class="tsai-math">∇<sub>rad</sub> > ∇<sub>ad</sub></span></p>'
)
assert '$$' not in out
assert '\\nabla' not in out
def test_ledoux_criterion_with_greek_subscript():
html = '<p>$$\\nabla_\\text{rad} > \\nabla_\\text{ad} + \\nabla_\\mu$$</p>'
out = convert_math(html)
assert out == (
'<p><span class="tsai-math">'
'∇<sub>rad</sub> > ∇<sub>ad</sub> + ∇<sub>µ</sub>'
'</span></p>'
)
def test_inline_math_superscript():
out = convert_math('<p>Energy is $E = mc^2$ exactly.</p>')
assert out == '<p>Energy is <span class="tsai-math">E = mc<sup>2</sup></span> exactly.</p>'
def test_braced_superscript_and_symbol():
out = convert_math('<p>Loses $10^{-6} M_\\odot$ per year.</p>')
assert out == (
'<p>Loses <span class="tsai-math">10<sup>-6</sup> M<sub>⊙</sub></span> per year.</p>'
)
def test_currency_is_not_treated_as_math():
html = '<p>It costs $5 to $10, not math.</p>'
assert convert_math(html) == html
def test_no_dollar_signs_is_noop():
html = '<p>Plain prose with no math at all.</p>'
assert convert_math(html) == html
def test_idempotent():
html = '<p>$$\\nabla_\\text{rad} > \\nabla_\\text{ad}$$</p>'
once = convert_math(html)
assert convert_math(once) == once