-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compare actual with expected tokenization in unittests
This guarantees that DjHTML is exactly behaving as expected, even if a tokenization mishap doesn't result in changed indentation. An added bonus is that by tracking these files in Git, we will notice changes in tokenization immediately. The initial token files were generated by the supplied `generate_tokens.py` script.
- Loading branch information
Showing
8 changed files
with
1,296 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Generate *.tokens files from *.html files in the suite directory. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from djhtml.modes import DjHTML | ||
|
||
DIR = Path(__file__).parent / "suite" | ||
|
||
for filename in DIR.iterdir(): | ||
if filename.suffix == ".html": | ||
with open(DIR / filename) as html: | ||
with open(DIR / (filename.stem + ".tokens"), "w") as f: | ||
f.write(DjHTML(html.read()).debug()) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' The example from the README ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text('<', mode=DjHTML), Text('div ', mode=InsideHTMLTag, absolute=5), Text('class=', mode=InsideHTMLTag, absolute=5), Text('"', mode=InsideHTMLTag, absolute=12)]) | ||
Line([Text(' ', mode=InsideHTMLTag, absolute=12), Open('{#', mode=DjTXT, ignore=True), Text(' fmt:off #}', mode=Comment, ignore=True)], ignore=True) | ||
Line([Text(' ,-._|\\', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' / .\\', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' \\_,--._/', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' ', mode=Comment, ignore=True), Close('{# fmt:on #}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([Text(' ', mode=InsideHTMLTag, absolute=12), Text('"', mode=InsideHTMLTag, absolute=11), Text('/>', mode=DjHTML)], offset=11) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Basic everyday Django template ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text('{% load static %}', mode=DjTXT)]) | ||
Line([Open('{% block content %}', mode=DjTXT)]) | ||
Line([Text(' ', mode=DjHTML), Open('{% if request.user.is_authenticated %}', mode=DjTXT, level=1)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('h1', mode=InsideHTMLTag, absolute=4), Open('>', mode=DjHTML, level=2), Text('Welcome, ', mode=DjHTML), Text('{{ request.user }}', mode=DjHTML), Close('</h1>', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), CloseAndOpen('{% else %}', mode=DjTXT, level=1)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('a ', mode=InsideHTMLTag, absolute=3), Text('href=', mode=InsideHTMLTag, absolute=3), Text('"', mode=InsideHTMLTag, absolute=9), Text("{% url 'login' %}", mode=DjTXT, absolute=9), Text('"', mode=InsideHTMLTag, absolute=8), Open('>', mode=DjHTML, level=2), Text('Click here to login', mode=DjHTML), Close('</a>', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('{% endif %}', mode=DjTXT)], level=1) | ||
Line([Close('{% endblock %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Django tags within <style> ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text('<', mode=DjHTML), Text('style', mode=InsideHTMLTag, absolute=7), Open('>', mode=DjHTML)]) | ||
Line([Text(' a ', mode=DjCSS), Open('{', mode=DjCSS, level=1)], level=1) | ||
Line([Text(' ', mode=DjCSS), Open('{% block color %}', mode=DjTXT, level=2)], level=2) | ||
Line([Text(' ', mode=DjCSS), Text('color: ', mode=DjCSS), Text('red', mode=DjCSS, absolute=7), Text(';', mode=DjCSS)], level=3) | ||
Line([Text(' ', mode=DjCSS), Close('{% endblock %}', mode=DjTXT)], level=2) | ||
Line([Text(' ', mode=DjCSS), Close('}', mode=DjCSS)], level=1) | ||
Line([Close('</style>', mode=DjHTML)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Django tags within <script> ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text('<', mode=DjHTML), Text('script', mode=InsideHTMLTag, absolute=8), Open('>', mode=DjHTML)]) | ||
Line([Text(' $', mode=DjJS), Open('(', mode=DjJS, level=1), Text('function', mode=DjJS), Open('(', mode=DjJS, level=1), Close(')', mode=DjJS), Text(' ', mode=DjJS), Open('{', mode=DjJS, level=1)], level=1) | ||
Line([Text(' ', mode=DjJS), Open('{% if verbose %}', mode=DjTXT, level=2)], level=2) | ||
Line([Text(' console.log', mode=DjJS), Open('(', mode=DjJS, level=3), Text('"Hi mom!"', mode=DjJS), Close(')', mode=DjJS), Text(';', mode=DjJS)], level=3) | ||
Line([Text(' ', mode=DjJS), Close('{% endif %}', mode=DjTXT)], level=2) | ||
Line([Text(' ', mode=DjJS), Close('}', mode=DjJS), Close(')', mode=DjJS), Text(';', mode=DjJS)], level=1) | ||
Line([Close('</script>', mode=DjHTML)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Multiline comment ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% comment %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([Text(' ,-._|\\', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' / .\\', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' \\_,--._/', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Close('{% endcomment %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Verbatim block ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% verbatim %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([Text(' ,-._|\\', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' / .\\', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Text(' \\_,--._/', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Close('{% endverbatim %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Multiline comment with optional comment ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% comment "Yo dawg" %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([Text(' I heard you like comments', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Close('{% endcomment %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Various spacings ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{%comment %}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([Text(' %}', mode=Comment, ignore=True)], level=1, ignore=True) | ||
Line([Close('{% endcomment%}', mode=DjTXT, ignore=True)], ignore=True) | ||
Line([Open('{%if%}', mode=DjTXT)]) | ||
Line([Text(' ', mode=DjHTML), Open('{%block content %}', mode=DjTXT, level=1)], level=1) | ||
Line([Text(' Yuck!', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('{% endblock%}', mode=DjTXT)], level=1) | ||
Line([Close('{% endif %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Inconsistent nesting ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% block %}', mode=DjTXT)]) | ||
Line([Text(' 1', mode=DjHTML)], level=1) | ||
Line([Text(' ', mode=DjHTML), Open('{% with %}', mode=DjTXT, level=1)], level=1) | ||
Line([Text(' 2', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('{% endblock %}', mode=DjTXT)], level=1) | ||
Line([Text(' 1', mode=DjHTML)], level=1) | ||
Line([Close('{% endwith %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Tags that both dedent and indent ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% blocktrans count count=queryset.count %}', mode=DjTXT)]) | ||
Line([Text(' There is 1 item.', mode=DjHTML)], level=1) | ||
Line([CloseAndOpen('{% plural %}', mode=DjTXT)]) | ||
Line([Text(' There are ', mode=DjHTML), Text('{{ count }}', mode=DjHTML), Text(' items.', mode=DjHTML)], level=1) | ||
Line([Close('{% endblocktrans %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' None of this should be indented ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% if %}', mode=DjTXT)]) | ||
Line([CloseAndOpen('{% elif %}', mode=DjTXT)]) | ||
Line([CloseAndOpen('{% else %}', mode=DjTXT)]) | ||
Line([Close('{% endif %}', mode=DjTXT)]) | ||
Line([Open('{% for %}', mode=DjTXT)]) | ||
Line([CloseAndOpen('{% empty %}', mode=DjTXT)]) | ||
Line([Close('{% endfor %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Template tag directly following tag name ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text('<', mode=DjHTML), Text('a', mode=InsideHTMLTag, absolute=3), Open('{% if %}', mode=DjTXT, absolute=3), Text(' ', mode=InsideHTMLTag, absolute=3), Text('class=', mode=InsideHTMLTag, absolute=3), Text('"', mode=InsideHTMLTag, absolute=18), Text('"', mode=InsideHTMLTag, absolute=17), Close('{% endif %}', mode=DjTXT, absolute=3), Open('>', mode=DjHTML)]) | ||
Line([Text(' Click here!', mode=DjHTML)], level=1) | ||
Line([Close('</a>', mode=DjHTML)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Ambiguous video tag from django-embed-video ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% video form.instance.video as my_video %}', mode=DjTXT)]) | ||
Line([Text(' ', mode=DjHTML), Text("{% video my_video '360 x 200' %}", mode=DjTXT)], level=1) | ||
Line([Close('{% endvideo %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Match the tag, the whole tag, and nothing but the tag ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% component_block "instruction" border_top=True header="Login" %}', mode=DjTXT)]) | ||
Line([Text(' ', mode=DjHTML), Open('{% slot "body" %}', mode=DjTXT, level=1)], level=1) | ||
Line([Text(' ', mode=DjHTML), Open('{% with "login --token="|add:token as content %}', mode=DjTXT, level=2)], level=2) | ||
Line([Text(' ', mode=DjHTML), Text('{% component "copy_field" field_selector="token-field" content=content %}', mode=DjTXT)], level=3) | ||
Line([Text(' ', mode=DjHTML), Close('{% endwith %}', mode=DjTXT)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('{% endslot %}', mode=DjTXT)], level=1) | ||
Line([Close('{% endcomponent_block %}', mode=DjTXT)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(" Don't indent template variables ", mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text("{{ '<b>' if condition }}", mode=DjHTML)]) | ||
Line([Text('some text', mode=DjHTML)]) | ||
Line([Text("{{ '</b>' if condition }}", mode=DjHTML)]) | ||
Line([Text('more text', mode=DjHTML)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Unless they span multiple lines ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Text("{{ '", mode=DjHTML), Text('<', mode=DjHTML), Text('b', mode=InsideHTMLTag, absolute=7), Open('>', mode=DjHTML), Text("'", mode=DjHTML)]) | ||
Line([Text(' if condition }}', mode=DjHTML)], level=1) | ||
Line([Text(' some text', mode=DjHTML)], level=1) | ||
Line([Text(" {{ '", mode=DjHTML), Close('</b>', mode=DjHTML)], level=1) | ||
Line([Text('if condition }}', mode=DjHTML)]) | ||
Line([Text('more text', mode=DjHTML)]) | ||
Line([]) | ||
Line([]) | ||
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' The example from issue #78 ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True) | ||
Line([Open('{% block main %}', mode=DjTXT)]) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('section', mode=InsideHTMLTag, absolute=9), Open('>', mode=DjHTML, level=1)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('div', mode=InsideHTMLTag, absolute=5), Open('>', mode=DjHTML, level=2)], level=2) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('div', mode=InsideHTMLTag, absolute=5), Open('>', mode=DjHTML, level=3)], level=3) | ||
Line([Text(' ', mode=DjHTML), Text('{% placeholder "placeholder1" %}', mode=DjTXT)], level=4) | ||
Line([Text(' ', mode=DjHTML), Close('</div>', mode=DjHTML)], level=3) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('div', mode=InsideHTMLTag, absolute=5), Open('>', mode=DjHTML, level=3)], level=3) | ||
Line([Text(' ', mode=DjHTML), Open('{% placeholder "placeholder2" or %}', mode=DjTXT, level=4)], level=4) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('img ', mode=InsideHTMLTag, absolute=5), Text('src=', mode=InsideHTMLTag, absolute=5), Text('"', mode=InsideHTMLTag, absolute=10), Text('"', mode=InsideHTMLTag, absolute=9), Text(' ', mode=InsideHTMLTag, absolute=5), Text('alt=', mode=InsideHTMLTag, absolute=5), Text('"', mode=InsideHTMLTag, absolute=17), Text('"', mode=InsideHTMLTag, absolute=16), Text(' ', mode=InsideHTMLTag, absolute=5), Text('/>', mode=DjHTML)], level=5) | ||
Line([Text(' ', mode=DjHTML), Close('{% endplaceholder %}', mode=DjTXT)], level=4) | ||
Line([Text(' ', mode=DjHTML), Close('</div>', mode=DjHTML)], level=3) | ||
Line([Text(' ', mode=DjHTML), Close('</div>', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('</section>', mode=DjHTML)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('section', mode=InsideHTMLTag, absolute=9), Open('>', mode=DjHTML, level=1)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('div', mode=InsideHTMLTag, absolute=5), Open('>', mode=DjHTML, level=2)], level=2) | ||
Line([Text(' ', mode=DjHTML), Text('{% placeholder "placeholder3" %}', mode=DjTXT)], level=3) | ||
Line([Text(' ', mode=DjHTML), Close('</div>', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('</section>', mode=DjHTML)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('section', mode=InsideHTMLTag, absolute=9), Open('>', mode=DjHTML, level=1)], level=1) | ||
Line([Text(' ', mode=DjHTML), Text('<', mode=DjHTML), Text('div', mode=InsideHTMLTag, absolute=5), Open('>', mode=DjHTML, level=2)], level=2) | ||
Line([Text(' ', mode=DjHTML), Text('{% placeholder "placeholder4" %}', mode=DjTXT)], level=3) | ||
Line([Text(' ', mode=DjHTML), Close('</div>', mode=DjHTML)], level=2) | ||
Line([Text(' ', mode=DjHTML), Close('</section>', mode=DjHTML)], level=1) | ||
Line([Close('{% endblock %}', mode=DjTXT)]) | ||
Line([]) |
Oops, something went wrong.