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 %} - - + """, ) @@ -123,8 +119,7 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None: {# djlint:on #} - - + """, ) diff --git a/tests/test_djlint/test_djlint.py b/tests/test_djlint/test_djlint.py index 36674c7..cdc0b77 100644 --- a/tests/test_djlint/test_djlint.py +++ b/tests/test_djlint/test_djlint.py @@ -5,9 +5,7 @@ run:: pytest tests/test_djlint/test_djlint.py --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing -for a single test:: - - pytest tests/test_djlint/test_djlint.py::test_version + pytest tests/test_djlint/test_djlint.py::test_check_reformatter_no_error or:: @@ -162,9 +160,7 @@ def test_check_reformatter_simple_error_quiet( def test_check_reformatter_no_error(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, b"
\n

\n nice stuff here\n

\n
" - ) + write_to_file(tmp_file.name, b"
\n

nice stuff here

\n
") result = runner.invoke(djlint, [tmp_file.name, "--check"]) assert result.exit_code == 0 assert "0 files would be updated." in result.output diff --git a/tests/test_handlebars/test_each.py b/tests/test_handlebars/test_each.py index db72056..ae08e54 100644 --- a/tests/test_handlebars/test_each.py +++ b/tests/test_handlebars/test_each.py @@ -30,9 +30,7 @@ def test_each(runner: CliRunner, tmp_file: TextIO) -> None: output.text == r"""{{#each people }} {{ print_person }} -

- and more long stuff -

+

and more long stuff

{{/each }} """ ) diff --git a/tests/test_handlebars/test_venerable.py b/tests/test_handlebars/test_venerable.py new file mode 100644 index 0000000..b595a96 --- /dev/null +++ b/tests/test_handlebars/test_venerable.py @@ -0,0 +1,63 @@ +"""Djlint tests for handlebars. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run:: + + pytest tests/test_html/test_handlebars_venerable.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_handlebars_venerable.py::test_long_attributes --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_template(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_handlebars/test_with.py b/tests/test_handlebars/test_with.py index 6ab09e3..975a14b 100644 --- a/tests/test_handlebars/test_with.py +++ b/tests/test_handlebars/test_with.py @@ -28,9 +28,7 @@ def test_with(runner: CliRunner, tmp_file: TextIO) -> None: assert ( output.text == r"""{{#with person }} -

- {{ firstname }} {{ lastname }} -

+

{{ firstname }} {{ lastname }}

{{/with }} """ ) diff --git a/tests/test_html/test_alpinejs.py b/tests/test_html/test_alpinejs.py index d5089f8..1747e9e 100644 --- a/tests/test_html/test_alpinejs.py +++ b/tests/test_html/test_alpinejs.py @@ -1,4 +1,13 @@ -"""DjLint tests for alpine.js.""" +"""DjLint tests for alpine.js. + +run: + + pytest tests/test_html/test_alpinejs.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_alpinejs.py::test_alpine_js + +""" # pylint: disable=C0116 from typing import TextIO diff --git a/tests/test_html/test_attributes.py b/tests/test_html/test_attributes.py index 759668d..ce820f8 100644 --- a/tests/test_html/test_attributes.py +++ b/tests/test_html/test_attributes.py @@ -1,14 +1,23 @@ -"""Djlint tests specific to html. +"""Djlint tests for html attributes. run:: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_attributes.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_attributes.py::test_long_attributes +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + """ # pylint: disable=C0116 from typing import TextIO @@ -99,3 +108,861 @@ def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None: json-data='{"menu":{"header":"SVG Viewer","items":[{"id":"Open"}]}}'>\n """ ) + + +# def test_attributes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +#
+#
+#
+# +# +#
+#
+# +#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
+#
String
+#
String
+#
String
+#
+#
+#
...
+#
+# ... +#
+#
+#
+#
+#
+# +# +# +# +# +# +# +# +#

+#

+# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +#
+#
+#
+# +# +#
+#
+# +#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
String
+#
+#
String
+#
String
+#
String
+#
+#
+# ... +#
+#
+# ... +#
+#
+#
+# +# +# +# +#

+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_boolean(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +#
+# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_case_sensitive(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_bem1(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
Foo
+#
+#
+#
+#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# Foo +#
+#
+#
+#
+#
+#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_bem2(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+#
+#

+# ... +#

+#
+#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+#
+#

+# ... +#

+#
+#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_colon(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_leading_dashes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_many_short_names(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_names(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# +# +#
+#
+# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# +# +# +#
+#
+#

+# +#

+#
+#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_class_print_width_edge(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_dobule_quotes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# John 'ShotGun' Nelson +# """ +# ).strip() + +# html_out = ( +# """ +# John 'ShotGun' Nelson +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_duplicate(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# 123 +# """ +# ).strip() + +# html_out = ( +# """ +# 123 +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_single_quotes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# John "ShotGun" Nelson +# """ +# ).strip() + +# html_out = ( +# """ +# John "ShotGun" Nelson +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_smart_quotes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_srcset(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_style(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_without_quotes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#

String

+# """ +# ).strip() + +# html_out = ( +# """ +#

String

+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out diff --git a/tests/test_html/test_basics.py b/tests/test_html/test_basics.py new file mode 100644 index 0000000..33db33b --- /dev/null +++ b/tests/test_html/test_basics.py @@ -0,0 +1,980 @@ +"""Djlint tests for basic stuff. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run:: + + poetry run pytest tests/test_html/test_basics.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + poetry run pytest tests/test_html/test_basics.py::test_brocken_html + +""" +# pylint: disable=C0116 +from typing import TextIO + +from click.testing import CliRunner + +from tests.conftest import reformat + +# def test_brocken_html(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +#
+# < +# """ +# ).strip() + +# html_out = ( +# """ +# +#
+# < +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +def test_comment(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""""", + ) + + assert ( + output.text + == """ +""" + ) + + +# def test_emtpy_doc(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b"", + ) + + assert ( + output.text + == """ +""" + ) + + +# def test_form(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+#
+# +# +# We'll never share your email with anyone else. +#
+#
+# +# +#
+#
+# +# +#
+#
+# +# +#
+#
+# +# +#
+#
+# +# +# This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line. +#
+#
+# Radio buttons +#
+# +#
+#
+# +#
+#
+# +#
+#
+#
+# +#
+# +#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+#
+# +# +# We'll never share your email with anyone else. +#
+#
+# +# +#
+#
+# +# +#
+#
+# +# +#
+#
+# +# +#
+#
+# +# +# This is some placeholder block-level help text for the above input. It's +# a bit lighter and easily wraps to a new line. +#
+#
+# Radio buttons +#
+# +#
+#
+# +#
+#
+# +#
+#
+#
+# +#
+# +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b""" + + + + + + Document + + + +

Hello World

+ + +""", + ) + + assert output.exit_code == 0 + + +def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b""" + + + Anchor + + + +""", + ) + + assert output.exit_code == 0 + + +# def test_html5_boilerplate(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +#

Hello world! This is HTML5 Boilerplate.

+# +# +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +#

Hello world! This is HTML5 Boilerplate.

+# +# +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_issue_9368_2(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# a-b- +# """ +# ).strip() + +# html_out = ( +# """ +# a-b- +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b"""a trackpad, or a gyroscope. +""", + ) + + assert output.exit_code == 0 + + +def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b"""a->b-> +""", + ) + + assert output.exit_code == 0 + + +# def test_more_html(runner: CliRunner, tmp_file: TextIO) -> None: + +# output = reformat( +# tmp_file, +# runner, +# b""" +# +# +# +# Anchor +# +# +# +# """ +# ) + +# assert output.text == """ +# +# +# Anchor +# +# +# +# """ + + +def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b""" + + + + + + +""", + ) + + assert output.exit_code == 0 + + +# def test_void_elements_2(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# text after +# +# 1 +# 1 +# """ +# ).strip() + +# html_out = ( +# """ +# text after +# +# +# +# 1 +# 1 +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_with_colon(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +#
+# +#
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
+#
block
BLOCK
block
block
block
+#
 pre pr
+# e
+# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# block BLOCK block block block +# pre pr +# e +# pre-wrap pr +# e-wrap +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline
+#
+# +#
+# +#
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
+#
block
BLOCK
block
block
block
+#
 pre pr
+# e
+# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# block BLOCK block block block +# pre pr +# e +# pre-wrap pr +# e-wrap +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline
+#
+# +#
+# +#
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
+#
block
BLOCK
block
block
block
+#
 pre pr
+# e
+# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# block BLOCK block block block +# pre pr +# e +# pre-wrap pr +# e-wrap +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline
+#
+# +#
+# +#
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
+#
block
BLOCK
block
block
block
+#
 pre pr
+# e
+# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# block BLOCK block block block +# pre pr +# e +# pre-wrap pr +# e-wrap +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline
+#
+# +#
+#
+#
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
+#
block
BLOCK
block
block
block
+#
 pre pr
+# e
+# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# block BLOCK block block block +# pre pr +# e +# pre-wrap pr +# e-wrap +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# inline inline inline inline
+#
+# +# +#

text text text text text text text text text text text text text text

+# +#
+# +# +# +# +# +# const func = function() { console.log('Hello, there');} +# .a{color:#f00} +# +# +# +# const func = function() { console.log('Hello, there');} +# .a{color:#f00} +# """ +# ).strip() + +# html_out = ( +# """ +# +#
+# +#
+# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +#
+#
block
+#
BLOCK
+#
block
+#
block
+#
block
+#
+#  pre pr
+# e
+# +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline inline inline +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# +# block BLOCK +# block block block +# pre pr e +# pre-wrap pr e-wrap +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline +# inline inline
+#
+# +#
+# +#
+# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +#
+#
block
+#
BLOCK
+#
block
+#
block
+#
block
+#
+#  pre pr
+# e
+# +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline inline inline +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# +# block BLOCK +# block block block +# pre pr e +# pre-wrap pr e-wrap +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline +# inline inline
+#
+# +#
+# +#
+# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +#
+#
block
+#
BLOCK
+#
block
+#
block
+#
block
+#
+#  pre pr
+# e
+# +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline inline inline +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# +# block BLOCK +# block block block +# pre pr e +# pre-wrap pr e-wrap +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline +# inline inline
+#
+# +#
+# +#
+# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +#
+#
block
+#
BLOCK
+#
block
+#
block
+#
block
+#
+#  pre pr
+# e
+# +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline inline inline +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# +# block BLOCK +# block block block +# pre pr e +# pre-wrap pr e-wrap +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline +# inline inline
+#
+# +#
+#
+#
+# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +#
+#
block
+#
BLOCK
+#
block
+#
block
+#
block
+#
+#  pre pr
+# e
+# +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline inline inline +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block +# +# block BLOCK +# block block block +# pre pr e +# pre-wrap pr e-wrap +# +# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline +# +# inline inline +# inline inline +#
+#
+# +# +#
+#

+# text text text text text text text text text text text text text text +#

+#
+# +#
+# +# +# +# +# +# const func = function() { console.log('Hello, there');} +# .a{color:#f00} +# +# +# +# +# +# +# +# const func = function() { console.log('Hello, there');} +# .a{color:#f00} +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out diff --git a/tests/test_html/test_bracket_same_line.py b/tests/test_html/test_bracket_same_line.py new file mode 100644 index 0000000..bd454a1 --- /dev/null +++ b/tests/test_html/test_bracket_same_line.py @@ -0,0 +1,311 @@ +"""Djlint tests for brackets same line. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run:: + + poetry run pytest tests/test_html/test_bracket_same_line.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + poetry run pytest tests/test_html/test_bracket_same_line.py::test_block + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from ..conftest import reformat + + +# def test_block(runner: CliRunner, tmp_file: TextIO) -> None: +# # set bracket-same-line: false +# html_in = ( +# b""" +#
+# text +#
+#
+#
+# text +#
+#
text
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# text +#
+#
+#
text
+#
text
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# # set bracket-same-line: true +# html_in = ( +# b""" +#
+# text +#
+#
+#
+# text +#
+#
text
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# text +#
+#
+#
text
+#
text
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_embed(runner: CliRunner, tmp_file: TextIO) -> None: +# # set bracket-same-line: false +# html_in = ( +# b""" +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# # set bracket-same-line: true +# html_in = ( +# b""" +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_inline(runner: CliRunner, tmp_file: TextIO) -> None: +# # set bracket-same-line: false +# html_in = ( +# b""" +# +# text +# +# +# text +# +# text +# +# text +# text +# +# texttexttexttexttext +# """ +# ).strip() + +# html_out = ( +# """ +# +# text +# +# +# text +# +# text +# +# text +# text +# +# texttexttexttexttext +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# # set bracket-same-line: true +# html_in = ( +# b""" +# +# text +# +# +# text +# +# text +# +# text +# text +# +# texttexttexttexttext +# """ +# ).strip() + +# html_out = ( +# """ +# +# text +# +# +# text +# +# text +# +# text +# text +# +# texttexttexttexttext +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None: +# # set bracket-same-line: false +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# # set bracket-same-line: true +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_case.py b/tests/test_html/test_case.py new file mode 100644 index 0000000..bbd20b3 --- /dev/null +++ b/tests/test_html/test_case.py @@ -0,0 +1,82 @@ +"""Djlint tests for case. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run:: + + poetry run pytest tests/test_html/test_case.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + poetry run pytest tests/test_html/test_case.py::test_case + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from ..conftest import reformat + + +# def test_case(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# My tITlE +# +# +# +#

Hello world!
This is HTML5 Boilerplate.

+# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# My tITlE +# +# +# +#

+# Hello world!
+# This is HTML5 Boilerplate. +#

+# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out diff --git a/tests/test_html/test_cdata.py b/tests/test_html/test_cdata.py new file mode 100644 index 0000000..241265d --- /dev/null +++ b/tests/test_html/test_cdata.py @@ -0,0 +1,52 @@ +"""Djlint tests for cdata. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run:: + + poetry run pytest tests/test_html/test_cdata.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + poetry run pytest tests/test_html/test_cdata.py::test_example + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_example(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# John Smith]]> +# a +#
+# """ +# ).strip() + +# html_out = ( +# """ +# John Smith]]> +# a +#
+#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out diff --git a/tests/test_html/test_comments.py b/tests/test_html/test_comments.py index a3cd291..8a48f56 100644 --- a/tests/test_html/test_comments.py +++ b/tests/test_html/test_comments.py @@ -1,12 +1,21 @@ -"""Djlint tests specific to html. +"""Djlint tests for comments. -run:: +Some tests may be from prettier.io's html test suite. - pytest tests/test_html.py --cov=src/djlint --cov-branch \ +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_comments.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_comments.py::test_html_comments_tag """ @@ -17,7 +26,7 @@ from typing import TextIO from click.testing import CliRunner from src.djlint import main as djlint -from tests.conftest import write_to_file +from tests.conftest import reformat, write_to_file def test_html_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None: @@ -37,3 +46,369 @@ comment-->
""" ) + + +def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" + +123 + """ + ).strip() + + html_out = """ +123 +""" + + output = reformat(tmp_file, runner, html_in) + + assert output.text == html_out + + +def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" + + + """ + ).strip() + + html_out = """ + +""" + + output = reformat(tmp_file, runner, html_in) + + assert output.text == html_out + + +# def test_conditional(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +#
+# +#
+# +#
+# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +#
+# +#
+# +#
+# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_for_debugging(runner: CliRunner, tmp_file: TextIO) -> None: +# # opened https://github.com/Riverside-Healthcare/djLint/issues/247 +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# """ +# ) + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +def test_hidden(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" + + + + + + + +

This is a paragraph.

+ + + + """ + ).strip() + + html_out = """ + + + + + + +

This is a paragraph.

+ + + +""" + + output = reformat(tmp_file, runner, html_in) + + assert output.text == html_out + + +# def test_surrounding_empty_line(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
  • First
  • Second
  • Second
+# ab +# ab +# ab +# 123456 +# 123456 +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +#
    +# +#
  • First
  • +# +#
  • Second
  • +# +#
  • Second
  • +#
+# ab +# ab +# ab +# 123456 123456 +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out diff --git a/tests/test_html/test_css.py b/tests/test_html/test_css.py new file mode 100644 index 0000000..f46e392 --- /dev/null +++ b/tests/test_html/test_css.py @@ -0,0 +1,286 @@ +"""Djlint tests for css. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_css.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_css.py::test_empty + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from ..conftest import reformat + + +# def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_less(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_postcss(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_scss(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_simple(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# Sample styled page +# +# +# +# +#

Sample styled page

+#

This page is just a demo.

+# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# Sample styled page +# +# +# +# +#

Sample styled page

+#

This page is just a demo.

+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out + + +# def test_single_style(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + +# assert output.text == html_out diff --git a/tests/test_html/test_doctype_declarations.py b/tests/test_html/test_doctype_declarations.py new file mode 100644 index 0000000..58b24d4 --- /dev/null +++ b/tests/test_html/test_doctype_declarations.py @@ -0,0 +1,265 @@ +"""Djlint tests for doctype. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_doctype_declarations.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_doctype_declarations.py::test_case + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_case(runner: CliRunner, tmp_file: TextIO) -> None: +# output = reformat(tmp_file, runner, b"") +# assert "" == output.text + +# output = reformat(tmp_file, runner, b"") +# assert "" == output.text + + +# def test_html4_01_frameset(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ) +# .strip() +# .encode() +# ) + +# html_out = ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# assert html_out == output.text + + +# def test_html4_01_strict(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ) +# .strip() +# .encode() +# ) + +# html_out = ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# assert html_out == output.text + + +# def test_html4_01_transitional(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ) +# .strip() +# .encode() +# ) + +# html_out = ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# assert html_out == output.text + + +# def test_html5(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ) +# .strip() +# .encode() +# ) + +# html_out = ( +# """ +# +# +# +# An HTML standard template +# +# +# +#

… Your HTML content here …

+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# assert html_out == output.text + + +# def test_xhtml1_1(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# XHTML markup +# +# +#
+#

Sample XHTML page

+#
+#
+# Beep +#
+#

Bar Foo,
+# Foo,
+# Bar
+# Foo

+#

String

+#
+#
+# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# XHTML markup +# +# +#
+#

Sample XHTML page

+#
+#
+# Beep +#
+#

+# Bar Foo,
+# Foo,
+# Bar
+# Foo +#

+#

String

+#
+#
+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# assert html_out == output.text diff --git a/tests/test_html/test_ignored.py b/tests/test_html/test_ignored.py index ddb397a..a5c81d8 100644 --- a/tests/test_html/test_ignored.py +++ b/tests/test_html/test_ignored.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for ignored content. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_ignored.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_ignored.py::test_ignored_block """ diff --git a/tests/test_html/test_interpolation.py b/tests/test_html/test_interpolation.py new file mode 100644 index 0000000..8a48f92 --- /dev/null +++ b/tests/test_html/test_interpolation.py @@ -0,0 +1,66 @@ +"""Djlint tests for interpolation. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_interpolation.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_interpolation.py::test_example + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_example(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
Fuga magnam facilis. Voluptatem quaerat porro.{{ +# x => { +# const hello = 'world' +# return hello; +# } +# }} Magni consectetur in et molestias neque esse voluptatibus voluptas. {{ + + +# some_variable +# }} Eum quia nihil nulla esse. Dolorem asperiores vero est error {{ +# preserve +# invalid + +# interpolation +# }} reprehenderit voluptates minus {{console.log( short_interpolation )}} nemo.
+# """ +# ).strip() + +# html_out = ( +# """ +# +#
+# Fuga magnam facilis. Voluptatem quaerat porro.{{ x => { const hello = 'world' +# return hello; } }} Magni consectetur in et molestias neque esse voluptatibus +# voluptas. {{ some_variable }} Eum quia nihil nulla esse. Dolorem asperiores +# vero est error {{ preserve invalid interpolation }} reprehenderit voluptates +# minus {{console.log( short_interpolation )}} nemo. +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# print(output.text) +# assert output.exit_code == 0 diff --git a/tests/test_html/test_next_line_empty.py b/tests/test_html/test_next_line_empty.py new file mode 100644 index 0000000..8705d60 --- /dev/null +++ b/tests/test_html/test_next_line_empty.py @@ -0,0 +1,71 @@ +"""Djlint tests for next line empty. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_next_line_empty.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_next_line_empty.py::test_standalone_end_marker + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_standalone_end_marker(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+# +#
+# +#
+# +#
+# 123123123123 +# 123123 +#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# +#
+# +#
+# +#
+# 123123123123 +# 123123 +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_selfclosing.py b/tests/test_html/test_selfclosing.py index 066fec4..653d597 100644 --- a/tests/test_html/test_selfclosing.py +++ b/tests/test_html/test_selfclosing.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for self closing tags. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_selfclosing.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_selfclosing.py::test_self_closing_tags """ diff --git a/tests/test_html/test_single_attribute_per_line.py b/tests/test_html/test_single_attribute_per_line.py new file mode 100644 index 0000000..43caa05 --- /dev/null +++ b/tests/test_html/test_single_attribute_per_line.py @@ -0,0 +1,138 @@ +"""Djlint tests for single attribute per line. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_single_attribute_per_line.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_single_attribute_per_line.py::test_single_attribute_per_line + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_single_attribute_per_line(runner: CliRunner, tmp_file: TextIO) -> None: +# # single-attribute-per-line: true +# html_in = ( +# b""" +#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+# +# bar +# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +# """ +# ).strip() + +# html_out = ( +# """ +#
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+# +# bar +# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) +# # single-attribute-per-line: false +# html_in = ( +# b""" +#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+# +# bar +# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +# """ +# ).strip() + +# html_out = ( +# """ +#
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+#
+# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +#
+# +# bar +# Lorem ipsum dolor sit amet, consectetur adipiscing elit. +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_srcset.py b/tests/test_html/test_srcset.py new file mode 100644 index 0000000..9dca9ec --- /dev/null +++ b/tests/test_html/test_srcset.py @@ -0,0 +1,68 @@ +"""Djlint tests for srcset. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_srcset.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_srcset.py::test_invalid + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_invalid(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# + +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_svg.py b/tests/test_html/test_svg.py new file mode 100644 index 0000000..62221ab --- /dev/null +++ b/tests/test_html/test_svg.py @@ -0,0 +1,130 @@ +"""Djlint tests for svg. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_svg.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_svg.py::test_svg + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_svg(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# SVG +# +# +# +# +# +# +# +# +# +# +# +# Text +# +# +# +# +#
+#

+# 123 +#

+# +# 123 +# +#
+#
+#
+ +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# SVG +# +# +# +# +# +# +# +# +# +# +# +# +# +# Text +# +# +# +# +# +#
+#

123

+# 123 +#
+#
+#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_symbol_entities.py b/tests/test_html/test_symbol_entities.py new file mode 100644 index 0000000..9593a1b --- /dev/null +++ b/tests/test_html/test_symbol_entities.py @@ -0,0 +1,41 @@ +"""Djlint tests for symbol entities. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_symbol_entities.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_symbol_entities.py::test_symbol_entities + +""" +# pylint: disable=C0116 +from typing import TextIO + +from click.testing import CliRunner + +from tests.conftest import reformat + + +def test_symbol_entities(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b"""

I will display €

+

I will display !

+

I will display €

+

I will display €

+""", + ) + print(output.text) + assert output.exit_code == 0 diff --git a/tests/test_html/test_tag_code.py b/tests/test_html/test_tag_code.py index 121bde8..9fb2d48 100644 --- a/tests/test_html/test_tag_code.py +++ b/tests/test_html/test_tag_code.py @@ -1,13 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html code tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_code.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_code.py::test_code_tag """ # pylint: disable=C0116 diff --git a/tests/test_html/test_tag_dd.py b/tests/test_html/test_tag_dd.py index 962429f..8a1d12c 100644 --- a/tests/test_html/test_tag_dd.py +++ b/tests/test_html/test_tag_dd.py @@ -1,13 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html dd tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_dd.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_dd.py::test_dd_tag """ # pylint: disable=C0116 diff --git a/tests/test_html/test_tag_details_summary.py b/tests/test_html/test_tag_details_summary.py index c9b21de..953a9c3 100644 --- a/tests/test_html/test_tag_details_summary.py +++ b/tests/test_html/test_tag_details_summary.py @@ -1,13 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html details/summary tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_details_summary.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_details_summary.py::test_details_summary_tags """ # pylint: disable=C0116 diff --git a/tests/test_html/test_tag_dt.py b/tests/test_html/test_tag_dt.py index 33fb63c..beee3bc 100644 --- a/tests/test_html/test_tag_dt.py +++ b/tests/test_html/test_tag_dt.py @@ -1,13 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html dt tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_dt.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_dt.py::test_dt_tag """ # pylint: disable=C0116 diff --git a/tests/test_html/test_tag_fig_caption.py b/tests/test_html/test_tag_fig_caption.py index 22fcf3d..1b3945f 100644 --- a/tests/test_html/test_tag_fig_caption.py +++ b/tests/test_html/test_tag_fig_caption.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html figure tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_fig_caption.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_fig_caption.py::test_figure_figcaption_tags """ diff --git a/tests/test_html/test_tag_hr.py b/tests/test_html/test_tag_hr.py index ce72c57..88da795 100644 --- a/tests/test_html/test_tag_hr.py +++ b/tests/test_html/test_tag_hr.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html hr tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_hr.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_hr.py::test_hr_tag """ diff --git a/tests/test_html/test_tag_picture.py b/tests/test_html/test_tag_picture.py index c7d5d50..6fc0341 100644 --- a/tests/test_html/test_tag_picture.py +++ b/tests/test_html/test_tag_picture.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html picture tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_picture.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_picture.py::test_picture_source_img_tags """ diff --git a/tests/test_html/test_tag_pre.py b/tests/test_html/test_tag_pre.py index f4edba2..b5d2945 100644 --- a/tests/test_html/test_tag_pre.py +++ b/tests/test_html/test_tag_pre.py @@ -1,13 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html pre tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_pre.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_pre.py::test_pre_tag """ # pylint: disable=C0116 diff --git a/tests/test_html/test_tag_script.py b/tests/test_html/test_tag_script.py index 72d47b9..bb65228 100644 --- a/tests/test_html/test_tag_script.py +++ b/tests/test_html/test_tag_script.py @@ -1,12 +1,21 @@ -"""Djlint tests specific to html. +"""Djlint tests for html script tags. -run:: +Some tests may be from prettier.io's html test suite. - pytest tests/test_html.py --cov=src/djlint --cov-branch \ +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_tag_script.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_script.py::test_script_tag """ @@ -70,3 +79,594 @@ def test_script_tag(runner: CliRunner, tmp_file: TextIO) -> None: ) assert output.exit_code == 0 + + +# def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_js(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_simple(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# Sample styled page +# +# +# +# +#

Sample styled page

+#

This page is just a demo.

+# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# Sample styled page +# +# +# +# +#

Sample styled page

+#

This page is just a demo.

+# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_single_script(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_something_else(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_template_literal(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_typescript(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_babel(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_legacy(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_module(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_module_attributes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_script(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_tag_small.py b/tests/test_html/test_tag_small.py index f16ef1c..1ce65c9 100644 --- a/tests/test_html/test_tag_small.py +++ b/tests/test_html/test_tag_small.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html small tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_small.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_small.py::test_small_tag """ diff --git a/tests/test_html/test_tag_span.py b/tests/test_html/test_tag_span.py index 36f1dbb..21433fc 100644 --- a/tests/test_html/test_tag_span.py +++ b/tests/test_html/test_tag_span.py @@ -1,12 +1,11 @@ -"""Djlint tests specific to html. +"""Djlint tests for html span tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_span.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_span.py::test_span_tag """ diff --git a/tests/test_html/test_tag_textarea.py b/tests/test_html/test_tag_textarea.py index 274c6f4..1065844 100644 --- a/tests/test_html/test_tag_textarea.py +++ b/tests/test_html/test_tag_textarea.py @@ -1,93 +1,95 @@ -"""Djlint tests specific to html. +"""Djlint tests for html textarea tag. -run:: +run: - pytest tests/test_html.py --cov=src/djlint --cov-branch \ + pytest tests/test_html/test_tag_textarea.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing + pytest tests/test_html/test_tag_textarea.py::test_textarea_tag """ # pylint: disable=C0116 -# from pathlib import Path -# from typing import TextIO +from pathlib import Path +from typing import TextIO -# from click.testing import CliRunner +from click.testing import CliRunner -# from src.djlint import main as djlint -# from tests.conftest import reformat, write_to_file +from src.djlint import main as djlint +from tests.conftest import reformat, write_to_file -# def test_textarea_tag(runner: CliRunner, tmp_file: TextIO) -> None: -# write_to_file(tmp_file.name, b"""
""") -# runner.invoke(djlint, [tmp_file.name, "--reformat"]) -# assert ( -# Path(tmp_file.name).read_text(encoding="utf8") -# == """
-# -#
-# """ -# ) -# # check double nesting -# output = reformat( -# tmp_file, -# runner, -# b"""
-#
-# -#
-#
-# """, -# ) -# assert output.exit_code == 0 +def test_textarea_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file(tmp_file.name, b"""
""") + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ +
+""" + ) + # check double nesting + output = reformat( + tmp_file, + runner, + b"""
+
+ +
+
+""", + ) -# # check attributes -# output = reformat( -# tmp_file, -# runner, -# b"""
-#
-# -#
-#
-# """, -# ) + assert output.exit_code == 0 -# assert ( -# output.text -# == """
-#
-# -#
-#
-# """ -# ) + # check attributes + output = reformat( + tmp_file, + runner, + b"""
+
+ +
+
+""", + ) -# def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None: -# output = reformat( -# tmp_file, -# runner, -# b"""

-# some nice text asdf, ok -#

""", -# ) + assert ( + output.text + == """
+
+ +
+
+""" + ) -# assert output.exit_code == 0 -# # test added for https://github.com/Riverside-Healthcare/djLint/issues/189 -# output = reformat( -# tmp_file, -# runner, -# b""" -# hihi -#
-#

{{ _("Options") }}

-#
-# """) +def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""

+ some nice text asdf, ok +

""", + ) -# assert output.exit_code == 0 + assert output.exit_code == 0 + + # test added for https://github.com/Riverside-Healthcare/djLint/issues/189 + output = reformat( + tmp_file, + runner, + b""" + hihi +
+

{{ _("Options") }}

+
+""", + ) + + assert output.exit_code == 0 diff --git a/tests/test_html/test_tags.py b/tests/test_html/test_tags.py new file mode 100644 index 0000000..1873302 --- /dev/null +++ b/tests/test_html/test_tags.py @@ -0,0 +1,927 @@ +"""Djlint tests for tags. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_tags.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_tags.py::test_case_sensitive + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_case_sensitive(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# hello world +# """ +# ).strip() + +# html_out = ( +# """ +# hello world +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_close_at_start(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+# aaaaaaaaaa +# bbbbbbbbbb +# cccccccccc +#
+#
+# aaaaaaaaaa +# bbbbbbbbbbcccccccccc +#
+# """ +# ).strip() + +# html_out = ( +# """ +#
+# aaaaaaaaaa +# bbbbbbbbbb +# cccccccccc +#
+#
+# aaaaaaaaaa +# bbbbbbbbbbcccccccccc +#
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_custom_element(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_opening_at_end(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#

Want to write us a letter? Use ourmailing address.

+ +#

Want to write us a letter? Use ourmailing address.

+ +#

Want to write us a letter? Use ourmailing address.

+# """ +# ).strip() + +# html_out = ( +# """ +#

+# Want to write us a letter? Use ourmailing address. +#

+ +#

+# Want to write us a letter? Use ourmailing address. +#

+ +#

+# Want to write us a letter? Use ourmailing address. +#

+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_option(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_pre(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+# --------------------------------------------------------------------------------
+
+
+#                                       *         *       *
+#                                      **        **      ***
+#                                      **        **       *
+#    ****    ***  ****               ********  ********                   ***  ****
+#   * ***  *  **** **** *    ***    ********  ********  ***        ***     **** **** *
+#  *   ****    **   ****    * ***      **        **      ***      * ***     **   ****
+# **    **     **          *   ***     **        **       **     *   ***    **
+# **    **     **         **    ***    **        **       **    **    ***   **
+# **    **     **         ********     **        **       **    ********    **
+# **    **     **         *******      **        **       **    *******     **
+# **    **     **         **           **        **       **    **          **
+# *******      ***        ****    *    **        **       **    ****    *   ***
+# ******        ***        *******      **        **      *** *  *******     ***
+# **                        *****                          ***    *****
+# **
+# **
+#  **
+
+# --------------------------------------------------------------------------------
+# 
+#
+
+#         Text in a pre element
+
+#     is displayed in a fixed-width
+
+#    font, and it preserves
+
+#    both             spaces and
+
+#    line breaks
+
+# 
+#
     Foo     Bar     
+#
+#      Foo     Bar
+# 
+#
Foo     Bar
+# 
+#
+#      Foo     Bar
+#
+#
+# ___________________________
+# < I'm an expert in my field. >
+# ---------------------------
+#      \\   ^__^
+#       \\  (oo)\\_______
+#          (__)\\       )\\/\\
+#              ||----w |
+#              ||     ||
+# ___________________________
+#   
+#
+# A cow saying, "I'm an expert in my field." The cow is illustrated using preformatted text characters. +#
+#
+#
+#      Foo     Bar
+# 
+#
+#
+#
+#
+#
+#           ______
+#           STRING
+#           ______
+#         
+#
+#
+#
+#
+#

+
+# 
+ +#
+#

+#   
+ +#
+#   
+# 
+#
+ +# +#

+#

+#

+#

+#

+#

+#
+#
+#

long long long text long long long text long long long text long long long text
+#

long long long text long long long text long long long text long long long text
+ +# """ +# ).strip() + +# html_out = ( +# """ +#
+# --------------------------------------------------------------------------------
+
+
+#                                       *         *       *
+#                                      **        **      ***
+#                                      **        **       *
+#    ****    ***  ****               ********  ********                   ***  ****
+#   * ***  *  **** **** *    ***    ********  ********  ***        ***     **** **** *
+#  *   ****    **   ****    * ***      **        **      ***      * ***     **   ****
+# **    **     **          *   ***     **        **       **     *   ***    **
+# **    **     **         **    ***    **        **       **    **    ***   **
+# **    **     **         ********     **        **       **    ********    **
+# **    **     **         *******      **        **       **    *******     **
+# **    **     **         **           **        **       **    **          **
+# *******      ***        ****    *    **        **       **    ****    *   ***
+# ******        ***        *******      **        **      *** *  *******     ***
+# **                        *****                          ***    *****
+# **
+# **
+#  **
+
+# --------------------------------------------------------------------------------
+# 
+#
+
+#         Text in a pre element
+
+#     is displayed in a fixed-width
+
+#    font, and it preserves
+
+#    both             spaces and
+
+#    line breaks
+
+# 
+#
     Foo     Bar     
+#
+#      Foo     Bar
+# 
+#
+# Foo     Bar
+# 
+#
     Foo     Bar
+#
+#
+# ___________________________
+# < I'm an expert in my field. >
+# ---------------------------
+#      \\   ^__^
+#       \\  (oo)\\_______
+#          (__)\\       )\\/\\
+#              ||----w |
+#              ||     ||
+# ___________________________
+#     
+#
+# A cow saying, "I'm an expert in my field." The cow is illustrated using +# preformatted text characters. +#
+#
+#
+#      Foo     Bar
+# 
+#
+#
+#
+#
+#
+#           ______
+#           STRING
+#           ______
+#                 
+#
+#
+#
+#
+#

+
+# 
+ +#
+#

+#     
+#
+ +#
+#
+#   
+#     
+#
+ +# +#

+#

+#

+#

+#

+#

+#
+#
+#

long long long text long long long text long long long text long long long text
+#

long long long text long long long text long long long text long long long text
+# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_tags(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
string
+#
very very very very very very very very very very very very very very very very long string
+#
string
+#
string
+#
string
+#
very very very very very very very very very very very very very very very very long string
+#
string
+#
very very very very very very very very very very very very very very very very long string
+# +#
string
+#
string
string
+#
string
string
+#
string
string
+#
+#
+#
string
+#
+#
string
+#
+#
+ +#
string
+ +#
+#
+ +#
string
+ +#
string
+ +#
+#
    123
  • First
  • 456
  • Second
  • 789
+# *200 +# 123 +#
123456
+#

x

+#

x

+#

x

+# + +# | +# +#
+#

+ +# +#

+#

+ +# +#

+#

"" is the property bound title.

+#
  • 12345678901234567890123456789012345678901234567890123456789012345678901234567890
  • +#
    +# +# +# + +# +# +# + +# +# +# +#
    +# tag name in other namespace should also lower cased +#
    +# Lorem ipsum dolor sit amet, consectetur adipiscing elit, +# "seddoeiusmod". +#
    +#
    +# Lorem ipsum dolor sit amet, consectetur adipiscing elit, +# seddoeiusmod. +#
    +# +# +# +# +# + +# +# +# +#
    Should not insert empty line before this div
    + +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    string
    +#
    +# very very very very very very very very very very very very very very very +# very long string +#
    +#
    +# string +#
    +#
    +# string +#
    +#
    +# string +#
    +#
    +# very very very very very very very very very very very very very very very +# very long string +#
    +#
    +# string +#
    +#
    +# very very very very very very very very very very very very very very very +# very long string +#
    +# +#
    string
    +#
    +#
    string
    +#
    string
    +#
    +#
    +#
    string
    +#
    string
    +#
    +#
    +#
    string
    +#
    string
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    string
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    string
    +#
    +#
    +#
    string
    +#
    +#
    +#
    string
    + +#
    string
    +#
    +#
      +# 123 +#
    • First
    • +# 456 +#
    • Second
    • +# 789 +#
    +# *200 +# 123 +#
    123456
    +#

    x

    +#

    x

    +#

    x

    +# + +# +# | +# +#
    +# +#

    + +# +#

    +# +#

    + +# +#

    +#

    "" is the property bound title.

    +#
  • +# 12345678901234567890123456789012345678901234567890123456789012345678901234567890 +#
  • +#
    +# +# +# + +# +# +# + +# +# +# +#
    +# tag name in other namespace should also lower cased +#
    +# Lorem ipsum dolor sit amet, consectetur adipiscing elit, +# "seddoeiusmod". +#
    +#
    +# Lorem ipsum dolor sit amet, consectetur adipiscing elit, +# seddoeiusmod. +#
    +# +# +# +# +# + +# +# +# +#
    +#
    Should not insert empty line before this div
    + +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_tags2(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
    beforeafter
    + +#
    before
    summary long long long long details
    after
    + +#
    beforedialog long long long long long long long long after
    + +#
    beforeafter
    + +#
    beforeafter
    + +#
    beforeafter
    +# """ +# ).strip() + +# html_out = ( +# """ +#
    +# beforeafter +#
    + +#
    +# before +#
    +# summary long long long long +# details +#
    +# after +#
    + +#
    +# before +# dialog long long long long long long long long +# after +#
    + +#
    +# before +# +# after +#
    + +#
    +# beforeafter +#
    + +#
    beforeafter
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_textarea(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +# +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +# + +#
    +# """ +# ).strip() + +# html_out = ( +# """ +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +# +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +#
    +# + +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_unsupported(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#
    +# """ +# ).strip() + +# html_out = ( +# """ +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_text.py b/tests/test_html/test_text.py new file mode 100644 index 0000000..9146bdd --- /dev/null +++ b/tests/test_html/test_text.py @@ -0,0 +1,50 @@ +"""Djlint tests for text. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_text.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_text.py::test_tag_should_in_fill + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_tag_should_in_fill(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# foo bar foo bar +# foo bar foo bar foo bar foo bar foo bar +# foo bar foo bar +# +# """ +# ).strip() + +# html_out = ( +# """ +# foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo +# bar +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_whitespace.py b/tests/test_html/test_whitespace.py new file mode 100644 index 0000000..4ae747e --- /dev/null +++ b/tests/test_html/test_whitespace.py @@ -0,0 +1,784 @@ +"""Djlint tests for whitespace. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run: + + pytest tests/test_html/test_whitespace.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html/test_whitespace.py::test_break_tags + +""" + +# from typing import TextIO + +# from click.testing import CliRunner + +# from tests.conftest import reformat + + +# def test_break_tags(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# Lorem, ispum dolor sit amet. +#
    Lorem, ispum dolor sit amet.
    +#
    Lorem, ispum dolor sit amet.
    +# """ +# ).strip() + +# html_out = ( +# """ +# Lorem, ispum dolor sit amet. +#
    Lorem, ispum dolor sit amet.
    +#
    +#
    Lorem, ispum dolor sit amet.
    +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_display_inline_block(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +#
    +# +#
    +#
    +# +# +#
    +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +#
    +# +#
    +#
    +# +# +#
    +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_display_none(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# My tITlE +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# My tITlE +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_fill(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#

    +# about fedco bottom imageWe are a cooperative, one of the few seed companies so organized +# in the United States. Because we do not have an individual owner or beneficiary, +# profit is not our primary goal. Consumers own 60% of the cooperative and worker +# members 40%. Consumer and worker members share proportionately in the cooperative’s +# profits through our annual patronage dividends. +#

    +# """ +# ).strip() + +# html_out = ( +# """ +#

    +# about fedco bottom imageWe are a cooperative, one of the few seed companies so +# organized in the United States. Because we do not have an individual owner or +# beneficiary, profit is not our primary goal. Consumers own 60% of the +# cooperative and worker members 40%. Consumer and worker members share +# proportionately in the cooperative’s profits through our annual +# patronage dividends. +#

    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_inline_leading_trailing_spaces(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# 321 + +# 321 +# """ +# ).strip() + +# html_out = ( +# """ +# 321 + +# 321 +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_inline_nodes(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +#

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +# vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +# Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +# Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +# Sed eu scelerisque neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, vehicula +# euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +# conubia nostra, per inceptos himenaeos. Donec in ornare velit.

    +#

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +# vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +# Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +# Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +# Sed eu scelerisque neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, vehicula +# euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +# conubia nostra, per inceptos himenaeos. Donec in ornare velit.

    +# """ +# ).strip() + +# html_out = ( +# """ +#

    +# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa +# vel augue vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet +# urna consectetur dignissim. Sam vitae neque quis ex dapibus faucibus at sed +# ligula. Nulla sit amet aliquet nibh. Vestibulum at congue mi. Suspendisse +# vitae odio vitae massa hendrerit mattis sed eget dui. Sed eu scelerisque +# neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, +# vehicula euismod ante vel, ultricies eleifend dui. Class aptent taciti +# sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec +# in ornare velit. +#

    +#

    +# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa +# vel augue vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet +# urna consectetur dignissim. Sam vitae neque quis ex dapibus faucibus at sed +# ligula. Nulla sit amet aliquet nibh. Vestibulum at congue mi. Suspendisse +# vitae odio vitae massa hendrerit mattis sed eget dui. Sed eu scelerisque +# neque. Donec maximus rhoncus pellentesque. Aenean purus +# turpis, vehicula euismod ante vel, ultricies eleifend dui. Class aptent taciti +# sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec +# in ornare velit. +#

    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_nested_inline_without_whitespace(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# ( +# """ +# /ˌɪləˈnɔɪ/ +# ipsum +# """ +# ) +# .strip() +# .str.encode() +# ) + +# html_out = ( +# """ +# /ˌɪləˈnɔɪ/ +# ipsum +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_non_breaking_whitespace(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +# Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. +# +# Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. +# +# Prix : 32 € +# """ +# ).strip() + +# html_out = ( +# """ +# +# Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores +# voluptas quaerat ut qui sunt vitae error. +# +# Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. +# +# Prix : 32 € +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_18(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#
    +# """ +# ).strip() + +# html_out = ( +# """ +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_19(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#
    +# """ +# ).strip() + +# html_out = ( +# """ +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_20(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#
      
    +# """ +# ).strip() + +# html_out = ( +# """ +#
      
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_21(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#
       
    +# """ +# ).strip() + +# html_out = ( +# """ +#
       
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_22(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_23(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_24(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#    +# """ +# ).strip() + +# html_out = ( +# """ +#    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_25(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#     +# """ +# ).strip() + +# html_out = ( +# """ +#     +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_26(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_27(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_28(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#    +# """ +# ).strip() + +# html_out = ( +# """ +#    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_29(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#     +# """ +# ).strip() + +# html_out = ( +# """ +#     +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_30(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#   |   +# """ +# ).strip() + +# html_out = ( +# """ +#   |   +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_31(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +#

    X   or   Y

    X   or   Y

    +# """ +# ).strip() + +# html_out = ( +# """ +#

    X   or   Y

    +#

    X   or   Y

    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_2005(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +#
    beforeafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter
    +# +#
    before_afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter
    +# +#
    before afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter
    +# """ +# ).strip() + +# html_out = ( +# """ +# +#
    +# beforeafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter +#
    +# +#
    +# before_afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter +#
    +# +#
    +# before afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_snippet_2005_2(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = str.encode( +# """ +# +# +# +# +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_surrounding_linebreak(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# 123 +# +# 123 +# 123 +# +# +# 123 +# +#
    123
    +#
    +# 123
    +#
    123 +#
    +#
    +# 123 +#
    +# """ +# ).strip() + +# html_out = ( +# """ +# 123 +# 123 +# 123 +# 123 +#
    123
    +#
    123
    +#
    123
    +#
    123
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_table(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# +# +# +# +# +# +#
    ABC
    + +#
    ABC
    + +#
    A B C
    + +# +# +# +# +# +#
    +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# +# +# +# +# +# +#
    ABC
    + +# +# +# +# +# +# +# +# +#
    ABC
    + +# +# +# +# +# +# +# +# +#
    ABC
    + +# +# +# +# +#
    +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) + + +# def test_template(runner: CliRunner, tmp_file: TextIO) -> None: + +# html_in = ( +# b""" +# +# +# """ +# ).strip() + +# html_out = ( +# """ +# +# +# """ +# ).strip() + +# output = reformat(tmp_file, runner, html_in) diff --git a/tests/test_html/test_yaml.py b/tests/test_html/test_yaml.py index 1f81d03..005e748 100644 --- a/tests/test_html/test_yaml.py +++ b/tests/test_html/test_yaml.py @@ -1,11 +1,21 @@ """DjLint tests for yaml front matter. +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + run: pytest tests/test_html/test_yaml.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_html/test_yaml.py + pytest tests/test_html/test_yaml.py::test_custom_parser """ # pylint: disable=C0116 @@ -36,10 +46,8 @@ invalid: invalid: --- - - - - + + """ ) @@ -61,10 +69,8 @@ hello: world hello: world --- - - - - + + """ ) @@ -80,3 +86,113 @@ layout:
    """, ) assert output.exit_code == 0 + + +def test_custom_parser(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" +---mycustomparser +title: Hello +slug: home +--- +

    + Hello world!

    + """ + ).strip() + + html_out = """---mycustomparser +title: Hello +slug: home +--- +

    Hello world!

    +""" + + output = reformat(tmp_file, runner, html_in) + + assert output.text == html_out + + +def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" +--- +--- +

    + Hello world!

    + """ + ).strip() + + html_out = """--- +--- +

    Hello world!

    +""" + + output = reformat(tmp_file, runner, html_in) + assert output.text == html_out + + +def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" +--- +--- +
    +--- +
    + """ + ).strip() + + html_out = """--- +--- +
    ---
    +""" + + output = reformat(tmp_file, runner, html_in) + assert output.text == html_out + + +def test_issue_9042_no_empty_line(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" +--- +layout: foo +--- +Test abc. + """ + ).strip() + + html_out = """--- +layout: foo +--- +Test abc. +""" + + output = reformat(tmp_file, runner, html_in) + assert output.text == html_out + + +def test_issue_9042(runner: CliRunner, tmp_file: TextIO) -> None: + + html_in = ( + b""" +--- +layout: foo +--- +Test abc. + """ + ).strip() + + html_out = """--- +layout: foo +--- +Test abc. +""" + + output = reformat(tmp_file, runner, html_in) + assert output.text == html_out