@@ -200,9 +200,11 @@ 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 ("%" , (1 , 1 )),
205+ Text (" some whatever.\n \n " , (3 , 3 )),
206+ Text ("%" , (3 , 3 )),
207+ Text (" more some whatever\n " , (5 , 7 )),
206208 ControlLine ("if" , "if foo:" , False , (6 , 1 )),
207209 ControlLine ("if" , "endif" , True , (7 , 1 )),
208210 Text (" " , (8 , 1 )),
@@ -222,11 +224,12 @@ def test_percent_escape2(self):
222224 TemplateNode (
223225 {},
224226 [
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 )),
227+ Text ("%" , (1 , 1 )),
228+ Text (" do something\n " , (1 , 3 )),
229+ Text ("%%" , (1 , 3 )),
230+ Text (" do something\n if <some condition>:\n " , (2 , 4 )),
231+ Text ("%%%" , (2 , 4 )),
232+ Text (" do something\n " , (4 , 9 )),
230233 ],
231234 ),
232235 )
@@ -246,14 +249,63 @@ def test_percent_escape_with_control_block(self):
246249 Text ("\n " , (1 , 1 )),
247250 ControlLine ("for" , "for i in [1, 2, 3]:" , False , (2 , 1 )),
248251 Text (" " , (3 , 1 )),
249- Text ("% do something " , (3 , 6 )),
252+ Text ("%" , (3 , 1 )),
253+ Text (" do something " , (3 , 7 )),
250254 Expression ("i" , [], (3 , 21 )),
251255 Text ("\n " , (3 , 25 )),
252256 ControlLine ("for" , "endfor" , True , (4 , 1 )),
253257 ],
254258 ),
255259 )
256260
261+ def test_inline_percent (self ):
262+ template = """
263+ %% foo
264+ bar %% baz
265+ """
266+ node = Lexer (template ).parse ()
267+ self ._compare (
268+ node ,
269+ TemplateNode (
270+ {},
271+ [
272+ Text ("\n " , (1 , 1 )),
273+ Text ("%" , (1 , 1 )),
274+ Text (" foo\n bar " , (2 , 3 )),
275+ Text ("%" , (2 , 3 )),
276+ Text ("%" , (2 , 3 )),
277+ Text (" baz\n " , (3 , 7 )),
278+ ],
279+ ),
280+ )
281+
282+ def test_inline_percent_with_control_block (self ):
283+ template = """
284+ % for i in [1, 2, 3]:
285+ %% foo
286+ bar %% baz
287+ % endfor
288+ """
289+ node = Lexer (template ).parse ()
290+ self ._compare (
291+ node ,
292+ TemplateNode (
293+ {},
294+ [
295+ Text ("\n " , (1 , 1 )),
296+ ControlLine (
297+ "for" , "for i in [1, 2, 3]:" , False , (2 , 1 )
298+ ),
299+ Text ("%" , (3 , 1 )),
300+ Text (" foo\n bar " , (3 , 3 )),
301+ Text ("%" , (3 , 3 )),
302+ Text ("%" , (3 , 3 )),
303+ Text (" baz\n " , (4 , 7 )),
304+ ControlLine ("for" , "endfor" , True , (5 , 1 )),
305+ ],
306+ ),
307+ )
308+
257309 def test_old_multiline_comment (self ):
258310 template = """#*"""
259311 node = Lexer (template ).parse ()
0 commit comments