"""Djlint tests specific to django. run:: pytest tests/test_django/test_comments.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing pytest tests/test_django/test_comments.py::test_nested_inline_comment """ # pylint: disable=C0116 from typing import TextIO from click.testing import CliRunner from tests.conftest import reformat def test_dj_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( tmp_file, runner, b"{# comment #}\n{% if this %}
{% endif %}" ) assert output.text == """{# comment #}\n{% if this %}
{% endif %}\n""" # no change was required assert output.exit_code == 0 def test_comment(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( tmp_file, runner, b"""{% comment "Optional note" %}{{ body }}{% endcomment %}""" ) assert output.exit_code == 0 # too short to put on multiple lines assert ( output.text == r"""{% comment "Optional note" %}{{ body }}{% endcomment %} """ ) output = reformat( tmp_file, runner, b"""

Lorem ipsum dolor sit amet

{% comment %} {% endcomment %}
""", ) assert output.exit_code == 0 output = reformat( tmp_file, runner, b"""
{# djlint:off #}

Lorem ipsum dolor sit amet

{# djlint:on #}
""", ) assert output.exit_code == 0 output = reformat( tmp_file, runner, b""" {% comment %} {% endcomment %} """, ) assert output.exit_code == 0 output = reformat( tmp_file, runner, b""" {# djlint:off #} {% comment %} {% endcomment %} {# djlint:on #} """, ) assert output.exit_code == 0 def test_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( tmp_file, runner, b"{#
#}\n{% if this %}
{% endif %}" ) assert output.text == """{#
#}\n{% if this %}
{% endif %}\n""" assert output.exit_code == 0 def test_nested_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( tmp_file, runner, b"""
{% if 1 %}
{% endif %} """, ) assert output.exit_code == 0