@@ -200,9 +200,10 @@ def test_percent_escape(self):
200200 TemplateNode (
201201 {},
202202 [
203- Text ("""\n \n """ , (1 , 1 )),
204- Text ("""% some whatever.\n \n """ , (3 , 2 )),
205- Text ("% more some whatever\n " , (5 , 6 )),
203+ Text ("\n \n %" , (1 , 1 )),
204+ Text (" some whatever.\n \n " , (3 , 3 )),
205+ Text (" %" , (5 , 1 )),
206+ Text (" more some whatever\n " , (5 , 7 )),
206207 ControlLine ("if" , "if foo:" , False , (6 , 1 )),
207208 ControlLine ("if" , "endif" , True , (7 , 1 )),
208209 Text (" " , (8 , 1 )),
@@ -222,11 +223,12 @@ def test_percent_escape2(self):
222223 TemplateNode (
223224 {},
224225 [
225- Text ("% do something\n " , (1 , 2 )),
226- Text (
227- "%% do something\n if <some condition>:\n " , (2 , 2 )
228- ),
229- Text ("%%% do something\n " , (4 , 6 )),
226+ Text ("%" , (1 , 1 )),
227+ Text (" do something\n " , (1 , 3 )),
228+ Text ("%%" , (2 , 1 )),
229+ Text (" do something\n if <some condition>:\n " , (2 , 4 )),
230+ Text (" %%%" , (4 , 1 )),
231+ Text (" do something\n " , (4 , 9 )),
230232 ],
231233 ),
232234 )
@@ -245,15 +247,56 @@ def test_percent_escape_with_control_block(self):
245247 [
246248 Text ("\n " , (1 , 1 )),
247249 ControlLine ("for" , "for i in [1, 2, 3]:" , False , (2 , 1 )),
248- Text (" " , (3 , 1 )),
249- Text ("% do something " , (3 , 6 )),
250+ Text (" % " , (3 , 1 )),
251+ Text (" do something " , (3 , 7 )),
250252 Expression ("i" , [], (3 , 21 )),
251253 Text ("\n " , (3 , 25 )),
252254 ControlLine ("for" , "endfor" , True , (4 , 1 )),
253255 ],
254256 ),
255257 )
256258
259+ def test_inline_percent (self ):
260+ template = """
261+ %% foo
262+ bar %% baz
263+ """
264+ node = Lexer (template ).parse ()
265+ self ._compare (
266+ node ,
267+ TemplateNode (
268+ {},
269+ [Text ("\n %" , (1 , 1 )), Text (" foo\n bar %% baz\n " , (2 , 3 ))],
270+ ),
271+ )
272+
273+ def test_inline_percent_with_control_block (self ):
274+ template = """
275+ % for i in [1, 2, 3]:
276+ %% foo
277+ bar %% baz
278+ % endfor
279+ """
280+ node = Lexer (template ).parse ()
281+ self ._compare (
282+ node ,
283+ TemplateNode (
284+ {},
285+ [
286+ Text ("\n " , (1 , 1 )),
287+ ControlLine (
288+ "for" , "for i in [1, 2, 3]:" , False , (2 , 1 )
289+ ),
290+ Text ("%" , (3 , 1 )),
291+ Text (" foo\n bar " , (3 , 3 )),
292+ Text ("%" , (3 , 3 )),
293+ Text ("%" , (3 , 3 )),
294+ Text (" baz\n " , (4 , 7 )),
295+ ControlLine ("for" , "endfor" , True , (5 , 1 )),
296+ ],
297+ ),
298+ )
299+
257300 def test_old_multiline_comment (self ):
258301 template = """#*"""
259302 node = Lexer (template ).parse ()
0 commit comments