""",
)
assert output["exit_code"] == 0
# check styles when tag is first
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
def test_small_tag(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
text""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
text
"""
)
def test_dd_tag(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
text""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
text
"""
)
def test_hr_tag(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
def test_span_tag(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
"""
)
def test_dt_tag(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
text""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
text
"""
)
def test_details_summary_tags(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
summary
body""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
summary
body
"""
)
def test_figure_figcaption_tags(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
caption""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
caption
"""
)
def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 1
assert (
output["text"]
== """
\n
"""
)
def test_picture_source_img_tags(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""\

""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
"""
)
def test_ignored_block(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 1
assert (
output["text"]
== """
"""
)
# check custom ignore tag {# djlint:off #} {# djlint:on #}
output = reformat(
tmp_file,
runner,
b"""
{# djlint:off #}
{# djlint:on #}
{% comment %} djlint:off {% endcomment %}
{% comment %} djlint:on {% endcomment %}
{{ /* djlint:off */ }}
{{ /* djlint:on */ }}
{{!-- djlint:off --}}
{{!-- djlint:on --}}
""",
)
assert output["exit_code"] == 0
assert (
output["text"]
== """
{# djlint:off #}
{# djlint:on #}
{% comment %} djlint:off {% endcomment %}
{% comment %} djlint:on {% endcomment %}
{{ /* djlint:off */ }}
{{ /* djlint:on */ }}
{{!-- djlint:off --}}
{{!-- djlint:on --}}
"""
)
# check script tag
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
assert (
"""
"""
in output["text"]
)
# check inline script includes
output = reformat(
tmp_file,
runner,
b"""
""",
)
print(output["text"])
assert output["exit_code"] == 0
def test_style_tag(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
# check style includes
output = reformat(
tmp_file,
runner,
b"""
""",
)
assert output["exit_code"] == 0
def test_self_closing_tags(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
Hello
World
""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
Hello
World
"""
)
def test_void_self_closing_tag(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""
Hello
World
""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text()
== """
Hello
World
"""
)