-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formatter): added support for nunjucks async loop tags
- Loading branch information
1 parent
11da1b6
commit 5a32bb3
Showing
2 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
"""Test nunjucks ascyn tags. | ||
poetry run pytest tests/test_nunjucks/test_async.py | ||
""" | ||
import pytest | ||
|
||
from src.djlint.reformat import formatter | ||
from tests.conftest import printer | ||
|
||
test_data = [ | ||
pytest.param( | ||
( | ||
"<ul>{% asyncEach athlete in athlete_list %}<li>{{ athlete.name }}</li>{% empty %}<li>Sorry, no athletes in this list.</li>{% endeach %}</ul>" | ||
), | ||
( | ||
"<ul>\n" | ||
" {% asyncEach athlete in athlete_list %}\n" | ||
" <li>{{ athlete.name }}</li>\n" | ||
" {% empty %}\n" | ||
" <li>Sorry, no athletes in this list.</li>\n" | ||
" {% endeach %}\n" | ||
"</ul>\n" | ||
), | ||
id="eachAsync", | ||
), | ||
pytest.param( | ||
( | ||
"<ul>{% asyncAll athlete in athlete_list %}<li>{{ athlete.name }}</li>{% empty %}<li>Sorry, no athletes in this list.</li>{% endall %}</ul>" | ||
), | ||
( | ||
"<ul>\n" | ||
" {% asyncAll athlete in athlete_list %}\n" | ||
" <li>{{ athlete.name }}</li>\n" | ||
" {% empty %}\n" | ||
" <li>Sorry, no athletes in this list.</li>\n" | ||
" {% endall %}\n" | ||
"</ul>\n" | ||
), | ||
id="eachAll", | ||
), | ||
pytest.param( | ||
( | ||
"{% asyncEach i in items %}\n" | ||
" <div>{% formfield i %}</div>\n" | ||
"{% endeach %}" | ||
), | ||
( | ||
"{% asyncEach i in items %}\n" | ||
" <div>{% formfield i %}</div>\n" | ||
"{% endeach %}\n" | ||
), | ||
id="each test nested formfield", | ||
), | ||
pytest.param( | ||
( | ||
"{% asyncAll i in items %}\n" | ||
" <div>{% formfield i %}</div>\n" | ||
"{% endall %}" | ||
), | ||
( | ||
"{% asyncAll i in items %}\n" | ||
" <div>{% formfield i %}</div>\n" | ||
"{% endall %}\n" | ||
), | ||
id="all test nested formfield", | ||
), | ||
pytest.param( | ||
( | ||
'<div class="form-inputs plans-form">\n' | ||
' <div class="trans-wrapper pos-comparator-flex">\n' | ||
" {% asyncEach field in POSOptimizer %}\n" | ||
" <div>\n" | ||
" <label>{{ field.label }}</label>\n" | ||
" {% formfield field show_label=False %}\n" | ||
" </div>\n" | ||
" {% endeach %}\n" | ||
" {% asyncAll field in POSOptimizer %}\n" | ||
" <div>\n" | ||
" <label>{{ field.label }}</label>\n" | ||
" {% formfield field show_label=False %}\n" | ||
" </div>\n" | ||
" {% endall %}\n" | ||
" <div>\n" | ||
" <label> </label>\n" | ||
' <button type="submit">{% trans "Calcola" %}</button>\n' | ||
" </div>\n" | ||
" </div>\n" | ||
"</div>\n" | ||
), | ||
( | ||
'<div class="form-inputs plans-form">\n' | ||
' <div class="trans-wrapper pos-comparator-flex">\n' | ||
" {% asyncEach field in POSOptimizer %}\n" | ||
" <div>\n" | ||
" <label>{{ field.label }}</label>\n" | ||
" {% formfield field show_label=False %}\n" | ||
" </div>\n" | ||
" {% endeach %}\n" | ||
" {% asyncAll field in POSOptimizer %}\n" | ||
" <div>\n" | ||
" <label>{{ field.label }}</label>\n" | ||
" {% formfield field show_label=False %}\n" | ||
" </div>\n" | ||
" {% endall %}\n" | ||
" <div>\n" | ||
" <label> </label>\n" | ||
' <button type="submit">{% trans "Calcola" %}</button>\n' | ||
" </div>\n" | ||
" </div>\n" | ||
"</div>\n" | ||
), | ||
id="each test nested formfield inside for", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize(("source", "expected"), test_data) | ||
def test_base(source, expected, django_config): | ||
output = formatter(django_config, source) | ||
|
||
printer(expected, source, output) | ||
assert expected == output |