"""Tests for the Jinja ↔ s-expression bridge.""" import asyncio from shared.sexp.jinja_bridge import ( sexp, sexp_async, register_components, get_component_env, _COMPONENT_ENV, ) # --------------------------------------------------------------------------- # Helpers # --------------------------------------------------------------------------- def run(coro): return asyncio.run(coro) def setup_function(): """Clear component env before each test.""" _COMPONENT_ENV.clear() # --------------------------------------------------------------------------- # sexp() — synchronous rendering # --------------------------------------------------------------------------- class TestSexp: def test_simple_html(self): assert sexp('(div "Hello")') == "
Hello
" def test_with_kwargs(self): html = sexp('(p name)', name="Alice") assert html == "

Alice

" def test_multiple_kwargs(self): html = sexp('(a :href url title)', url="/about", title="About") assert html == 'About' def test_escaping(self): html = sexp('(p text)', text="") assert "<script>" in html assert "