From 886d59021aa9a76e8e0e8a7cbafc8b67fdc17633 Mon Sep 17 00:00:00 2001
From: Christopher Pickering
Date: Mon, 16 May 2022 09:25:29 -0500
Subject: [PATCH] feat(breaks): allowed p, head, and body tags that are
short/empty to be on a single line
Added more tests.
---
src/djlint/settings.py | 3 +
tests/test_config/test_custom_tags/html.html | 2 +-
.../test_custom_tags/test_config.py | 11 +-
tests/test_config/test_json/test_config.py | 11 +-
tests/test_config/test_pragmas/test_config.py | 24 +-
tests/test_django/test_comments.py | 13 +-
tests/test_djlint/test_djlint.py | 8 +-
tests/test_handlebars/test_each.py | 4 +-
tests/test_handlebars/test_venerable.py | 63 ++
tests/test_handlebars/test_with.py | 4 +-
tests/test_html/test_alpinejs.py | 11 +-
tests/test_html/test_attributes.py | 875 +++++++++++++++-
tests/test_html/test_basics.py | 980 ++++++++++++++++++
tests/test_html/test_bracket_same_line.py | 311 ++++++
tests/test_html/test_case.py | 82 ++
tests/test_html/test_cdata.py | 52 +
tests/test_html/test_comments.py | 387 ++++++-
tests/test_html/test_css.py | 286 +++++
tests/test_html/test_doctype_declarations.py | 265 +++++
tests/test_html/test_ignored.py | 9 +-
tests/test_html/test_interpolation.py | 66 ++
tests/test_html/test_next_line_empty.py | 71 ++
tests/test_html/test_selfclosing.py | 9 +-
.../test_single_attribute_per_line.py | 138 +++
tests/test_html/test_srcset.py | 68 ++
tests/test_html/test_svg.py | 130 +++
tests/test_html/test_symbol_entities.py | 41 +
tests/test_html/test_tag_code.py | 10 +-
tests/test_html/test_tag_dd.py | 10 +-
tests/test_html/test_tag_details_summary.py | 10 +-
tests/test_html/test_tag_dt.py | 10 +-
tests/test_html/test_tag_fig_caption.py | 9 +-
tests/test_html/test_tag_hr.py | 9 +-
tests/test_html/test_tag_picture.py | 9 +-
tests/test_html/test_tag_pre.py | 10 +-
tests/test_html/test_tag_script.py | 610 ++++++++++-
tests/test_html/test_tag_small.py | 9 +-
tests/test_html/test_tag_span.py | 9 +-
tests/test_html/test_tag_textarea.py | 152 +--
tests/test_html/test_tags.py | 927 +++++++++++++++++
tests/test_html/test_text.py | 50 +
tests/test_html/test_whitespace.py | 784 ++++++++++++++
tests/test_html/test_yaml.py | 134 ++-
43 files changed, 6458 insertions(+), 218 deletions(-)
create mode 100644 tests/test_handlebars/test_venerable.py
create mode 100644 tests/test_html/test_basics.py
create mode 100644 tests/test_html/test_bracket_same_line.py
create mode 100644 tests/test_html/test_case.py
create mode 100644 tests/test_html/test_cdata.py
create mode 100644 tests/test_html/test_css.py
create mode 100644 tests/test_html/test_doctype_declarations.py
create mode 100644 tests/test_html/test_interpolation.py
create mode 100644 tests/test_html/test_next_line_empty.py
create mode 100644 tests/test_html/test_single_attribute_per_line.py
create mode 100644 tests/test_html/test_srcset.py
create mode 100644 tests/test_html/test_svg.py
create mode 100644 tests/test_html/test_symbol_entities.py
create mode 100644 tests/test_html/test_tags.py
create mode 100644 tests/test_html/test_text.py
create mode 100644 tests/test_html/test_whitespace.py
diff --git a/src/djlint/settings.py b/src/djlint/settings.py
index e478e0e..6dac3d5 100644
--- a/src/djlint/settings.py
+++ b/src/djlint/settings.py
@@ -726,6 +726,9 @@ class Config:
| li
| script
| style
+ | head
+ | body
+ | p
"""
self.always_self_closing_html_tags: str = r"""
diff --git a/tests/test_config/test_custom_tags/html.html b/tests/test_config/test_custom_tags/html.html
index 93612a3..09ffe95 100644
--- a/tests/test_config/test_custom_tags/html.html
+++ b/tests/test_config/test_custom_tags/html.html
@@ -1 +1 @@
-{% example stuff %}this is a long paragraph
{% endexample %}
+{% example stuff %}this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf
{% endexample %}
diff --git a/tests/test_config/test_custom_tags/test_config.py b/tests/test_config/test_custom_tags/test_config.py
index ff6eb0f..f546ea2 100644
--- a/tests/test_config/test_custom_tags/test_config.py
+++ b/tests/test_config/test_custom_tags/test_config.py
@@ -2,13 +2,12 @@
run::
- pytest tests/test_config.py --cov=src/djlint --cov-branch \
+ pytest tests/test_config/test_custom_tags/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
- pytest tests/test_config.py::test_custom_html --cov=src/djlint \
- --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
+ pytest tests/test_config/test_custom_tags/test_config.py::test_custom_tags
"""
# pylint: disable=C0116
@@ -23,12 +22,12 @@ def test_custom_tags(runner: CliRunner) -> None:
result = runner.invoke(
djlint, ["tests/test_config/test_custom_tags/html.html", "--check"]
)
-
+ print(result.output)
assert (
- """-{% example stuff %}this is a long paragraph
{% endexample %}
+ """-{% example stuff %}this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf
{% endexample %}
+{% example stuff %}
+
-+ this is a long paragraph
++ this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf
+
+{% endexample %}
"""
diff --git a/tests/test_config/test_json/test_config.py b/tests/test_config/test_json/test_config.py
index 0aa30a6..7081bde 100644
--- a/tests/test_config/test_json/test_config.py
+++ b/tests/test_config/test_json/test_config.py
@@ -2,13 +2,10 @@
run::
- pytest tests/test_config_json.py --cov=src/djlint --cov-branch \
+ pytest tests/test_config/test_json/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
-for a single test, run::
-
- pytest tests/test_config_json.py::test_custom_html --cov=src/djlint \
- --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
+ pytest tests/test_config/test_json/test_config.py::test_config
"""
# pylint: disable=C0116
@@ -26,9 +23,7 @@ def test_config(runner: CliRunner) -> None:
assert (
"""-{% example stuff %}this is a long paragraph
{% endexample %}
+{% example stuff %}
-+
-+ this is a long paragraph
-+
++ this is a long paragraph
+{% endexample %}
"""
in result.output
diff --git a/tests/test_config/test_pragmas/test_config.py b/tests/test_config/test_pragmas/test_config.py
index 0be0417..7ecc37a 100644
--- a/tests/test_config/test_pragmas/test_config.py
+++ b/tests/test_config/test_pragmas/test_config.py
@@ -2,13 +2,10 @@
run::
- pytest tests/test_config.py --cov=src/djlint --cov-branch \
+ pytest tests/test_config/test_pragmas/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
-for a single test, run::
-
- pytest tests/test_config.py::test_custom_html --cov=src/djlint \
- --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
+ pytest tests/test_config/test_pragmas/test_config.py::test_require_pragma
"""
# pylint: disable=C0116
@@ -68,14 +65,11 @@ def test_require_pragma(runner: CliRunner) -> None:
assert (
""" {{!-- djlint:on --}}
-
+-
-
-{{firstname}}
{{lastname}}
-+ {{firstname}}
-+
-+
-+ {{lastname}}
-+
"""
++{{firstname}}
++{{lastname}}
"""
in result.output
)
assert """1 file would be updated.""" in result.output
@@ -98,13 +92,9 @@ def test_require_pragma(runner: CliRunner) -> None:
-
-{{ end }}
+Test
-+
-+ {{ .Variable }}
-+
++{{ .Variable }}
+{{ range .Items }}
-+
-+ {{ . }}
-+
++{{ . }}
+{{ end }}
1 file would be updated."""
diff --git a/tests/test_django/test_comments.py b/tests/test_django/test_comments.py
index bbb8d54..232751b 100644
--- a/tests/test_django/test_comments.py
+++ b/tests/test_django/test_comments.py
@@ -2,13 +2,10 @@
run::
- pytest tests/test_django.py --cov=src/djlint --cov-branch \
+ pytest tests/test_django/test_comments.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
-for a single test, run::
-
- pytest tests/test_django.py::test_alpine_js --cov=src/djlint \
- --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
+ pytest tests/test_django/test_comments.py::test_comment
"""
# pylint: disable=C0116
@@ -100,8 +97,7 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
{% endcomment %}
-
-
+