fixed #26, added test

This commit is contained in:
Christopher Pickering 2021-11-16 11:40:29 +01:00
parent 7c7cac916f
commit b2b26e9ee1
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 19 additions and 5 deletions

View file

@ -6,6 +6,7 @@ next_release
- Added rule T027 to check for unclosed in template syntax
- Added rule T028 to check for missing spaceless tags in attributes
- Added rule H029 to check for lowercase form method
- Ignored djagno blocktranslate tags that do not have "trimmed" from formatter
0.5.9a
------

View file

@ -636,8 +636,8 @@ class Config:
| {{-?\s*/\*\s*djlint\:off\s*\*/\s*-?}}.*?{{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}}
| <!--.*?-->
| <\?php.*?\?>
# | {\%[ ]trans[ ][^}]*?\%}
| {%[ ]+?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]+?endcomment[ ]+?%}
| {%[ ]*?blocktranslate[ ]+?((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%}
| {%[ ]*?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%}
"""
self.ignored_inline_blocks: str = r"""
@ -645,7 +645,8 @@ class Config:
| {\*.*?\*}
| {\#.*?\#}
| <\?php.*?\?>
| {%[ ]+?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]+?endcomment[ ]+?%}
| {%[ ]*?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%}
| {%[ ]*?blocktranslate[ ]+?((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%}
"""
self.optional_single_line_html_tags: str = r"""

View file

@ -7,7 +7,7 @@ run::
for a single test, run::
pytest tests/test_django.py::test_attribute_include --cov=src/djlint \
pytest tests/test_django.py::test_blocktranslate --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
"""
@ -233,10 +233,22 @@ def test_blocktranslate(runner: CliRunner, tmp_file: TextIO) -> None:
runner,
b"""{% blocktranslate %}The width is: {{ width }}{% endblocktranslate %}""",
)
assert output["exit_code"] == 0
assert (
output["text"]
== r"""{% blocktranslate %}The width is: {{ width }}{% endblocktranslate %}
"""
)
output = reformat(
tmp_file,
runner,
b"""{% blocktranslate trimmed %}The width is: {{ width }}{% endblocktranslate %}""",
)
assert output["exit_code"] == 1
assert (
output["text"]
== r"""{% blocktranslate %}
== r"""{% blocktranslate trimmed %}
The width is: {{ width }}
{% endblocktranslate %}
"""