-
-
Notifications
You must be signed in to change notification settings - Fork 84
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 ability to format objects/arrays in function tags
thanks @tomdavies and @oliver-schulz closes #370
- Loading branch information
1 parent
92c083b
commit d446efc
Showing
6 changed files
with
192 additions
and
42 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
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
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,94 @@ | ||
"""Test nunjucks functions. | ||
poetry run pytest tests/test_nunjucks/test_functions.py | ||
""" | ||
import pytest | ||
|
||
from src.djlint.reformat import formatter | ||
from tests.conftest import config_builder, printer | ||
|
||
test_data = [ | ||
pytest.param( | ||
( | ||
"{{ myfunc({\n" | ||
" bar: {\n" | ||
" baz: {\n" | ||
" cux: 1\n" | ||
" }\n" | ||
" }\n" | ||
"})}}" | ||
), | ||
("{{ myfunc({bar: {baz: {cux: 1}}}) }}\n"), | ||
({}), | ||
id="long line", | ||
), | ||
pytest.param( | ||
( | ||
"{{ myfunc({\n" | ||
" bar: {\n" | ||
" baz: {\n" | ||
" cux: 1\n" | ||
" }\n" | ||
" }\n" | ||
"})}}" | ||
), | ||
( | ||
"{{ myfunc({\n" | ||
" bar: {\n" | ||
" baz: {\n" | ||
" cux: 1\n" | ||
" }\n" | ||
" }\n" | ||
"}) }}\n" | ||
), | ||
({"max_line_length": 1}), | ||
id="short line", | ||
), | ||
pytest.param( | ||
( | ||
"<div>{{ myfunc({\n" | ||
" bar: {\n" | ||
" baz: {\n" | ||
" cux: 1\n" | ||
" }\n" | ||
" }\n" | ||
"})}}</div>" | ||
), | ||
( | ||
"<div>\n" | ||
" {{ myfunc({\n" | ||
" bar: {\n" | ||
" baz: {\n" | ||
" cux: 1\n" | ||
" }\n" | ||
" }\n" | ||
" }) }}\n" | ||
"</div>\n" | ||
), | ||
({"max_line_length": 1}), | ||
id="nested", | ||
), | ||
pytest.param( | ||
( | ||
"{{ myfunc({\n" | ||
" bar: {\n" | ||
" baz: {\n" | ||
" cux: 1\n" | ||
" }\n" | ||
" }\n" | ||
"})}" | ||
), | ||
("{{ myfunc({\n" "bar: {\n" "baz: {\n" "cux: 1\n" "}\n" "}\n" "})}\n"), | ||
({}), | ||
id="broken", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize(("source", "expected", "args"), test_data) | ||
def test_base(source, expected, args, nunjucks_config): | ||
args["profile"] = "nunjucks" | ||
output = formatter(config_builder(args), source) | ||
|
||
printer(expected, source, output) | ||
assert expected == output |
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