Bertrand Benjamin
cd2fdc162e
All checks were successful
continuous-integration/drone/push Build is passing
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from bopytex.jinja2_env.texenv import texenv
|
|
|
|
|
|
def test_variable_block():
|
|
base_template = r"\Var{a}"
|
|
jinja2_template = texenv.from_string(base_template)
|
|
output = jinja2_template.render(a=2)
|
|
assert output == "2"
|
|
|
|
|
|
def test_block_string():
|
|
base_template = r"\Block{set a = 2}\Var{a}"
|
|
jinja2_template = texenv.from_string(base_template)
|
|
output = jinja2_template.render()
|
|
assert output == "2"
|
|
|
|
|
|
def test_block_line_statement():
|
|
base_template = r"""%-set a = 2
|
|
\Var{a}"""
|
|
jinja2_template = texenv.from_string(base_template)
|
|
output = jinja2_template.render()
|
|
assert output == "2"
|
|
|
|
|
|
def test_block_line_statement_with_comment():
|
|
base_template = r"""%-set a = 2
|
|
%# comment
|
|
\Var{a}"""
|
|
jinja2_template = texenv.from_string(base_template)
|
|
output = jinja2_template.render()
|
|
assert output == "\n2"
|
|
|
|
|
|
def test_add_filter():
|
|
texenv.filters["count_caracters"] = lambda x: len(x)
|
|
base_template = r"""\Var{a} has \Var{a | count_caracters}"""
|
|
jinja2_template = texenv.from_string(base_template)
|
|
output = jinja2_template.render(a="coucou")
|
|
assert output == "coucou has 6"
|