diff --git a/.gitignore b/.gitignore index 870312a..99bce08 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ .tox/ .cache/ .vscode +.venv \ No newline at end of file diff --git a/mako/testing/helpers.py b/mako/testing/helpers.py index bd5d21c..5ae9d38 100644 --- a/mako/testing/helpers.py +++ b/mako/testing/helpers.py @@ -20,11 +20,7 @@ def result_lines(result): def result_raw_lines(result): - return [ - x - for x in re.split(r"\r?\n", result) - if x.strip() != "" - ] + return [x for x in re.split(r"\r?\n", result) if x.strip() != ""] def make_path( diff --git a/my/test.py b/my/test.py new file mode 100644 index 0000000..9bcc2d3 --- /dev/null +++ b/my/test.py @@ -0,0 +1,56 @@ +from mako.template import Template +from mako.lexer import Lexer +from mako.testing.helpers import result_raw_lines + + +# t = Template("""%% do something +# %%% do something +# if : +# %%%% do something +# """) + + +t = Template( + """ +% for i in [1, 2, 3]: + %% do something ${i} +% endfor +""" +) +t = """ +% for i in [1, 2, 3]: + %% do something ${i} +% endfor +""" +# print(result_raw_lines(t.render())) +print(Lexer(t).parse()) +# import re + +# pat = re.compile( +# r""" +# (.*?) # anything, followed by: +# ( +# (?<=\n)((?:\n ", - (2, 2)), + Text( + "%% do something\nif :\n ", (2, 2) + ), Text("%%% do something\n ", (4, 6)), ], ), @@ -242,13 +243,14 @@ def test_percent_escape_with_control_block(self): TemplateNode( {}, [ - Text('\n', (1, 1)), - ControlLine('for', 'for i in [1, 2, 3]:', False, (2, 1)), - Text(' ', (3, 1)), - Text('% do something ', (3, 6)), - Expression('i', [], (3, 21)), - Text('\n', (3, 25)), - ControlLine('for', 'endfor', True, (4, 1))] + Text("\n", (1, 1)), + ControlLine("for", "for i in [1, 2, 3]:", False, (2, 1)), + Text(" ", (3, 1)), + Text("% do something ", (3, 6)), + Expression("i", [], (3, 21)), + Text("\n", (3, 25)), + ControlLine("for", "endfor", True, (4, 1)), + ], ), ) diff --git a/test/test_template.py b/test/test_template.py index 3df7ada..79017f7 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -14,7 +14,8 @@ from mako.testing.config import config from mako.testing.fixtures import TemplateTest from mako.testing.helpers import flatten_result -from mako.testing.helpers import result_lines, result_raw_lines +from mako.testing.helpers import result_lines +from mako.testing.helpers import result_raw_lines class ctx: @@ -1671,11 +1672,13 @@ def test_future_import(self): class EscapeTest(TemplateTest): def test_percent_escape(self): - t = Template("""%% do something + t = Template( + """%% do something %%% do something if : %%%% do something -""") +""" + ) assert result_raw_lines(t.render()) == [ "% do something", "%% do something", @@ -1684,11 +1687,13 @@ def test_percent_escape(self): ] def test_percent_escape2(self): - t = Template(""" + t = Template( + """ % for i in [1, 2, 3]: %% do something ${i} % endfor -""") +""" + ) assert result_raw_lines(t.render()) == [ " % do something 1", " % do something 2",