root/livinglogic.python.xist/test/test_ul4.py @ 3711:a539aff0e476

Revision 3711:a539aff0e476, 37.8 KB (checked in by Walter Doerwald <walter@…>, 10 years ago)

Add a reversed function to UL4 (issue #5). Bump file format version.

Line 
1#! /usr/bin/env/python
2# -*- coding: utf-8 -*-
3
4## Copyright 2009 by LivingLogic AG, Bayreuth/Germany
5## Copyright 2009 by Walter Dörwald
6##
7## All Rights Reserved
8##
9## See ll/__init__.py for the license
10
11
12import re, datetime, StringIO
13
14import py.test
15
16from ll import ul4c
17
18
19def check(result, source, **variables):
20    # Check with template compiled from source
21    t1 = ul4c.compile(source)
22    s1 = unicode(t1)
23    assert result == t1.renders(**variables)
24
25    # Check with template loaded again via the string interface
26    t2 = ul4c.loads(t1.dumps())
27    s2 = unicode(t2)
28    assert result == t2.renders(**variables)
29
30    # Check with template loaded again via the stream interface
31    stream = StringIO.StringIO()
32    t1.dump(stream)
33    stream.seek(0)
34    t3 = ul4c.load(stream)
35    s3 = unicode(t3)
36    assert result == t3.renders(**variables)
37    assert s1 == s2 == s3
38
39
40def checkle(result, source, **variables):
41    # Check with template compiled from source
42    t1 = ul4c.compile(source)
43    s1 = unicode(t1)
44    assert result <= t1.renders(**variables)
45
46    # Check with template loaded again via the string interface
47    t2 = ul4c.loads(t1.dumps())
48    s2 = unicode(t2)
49    assert result <= t2.renders(**variables)
50
51    # Check with template loaded again via the stream interface
52    stream = StringIO.StringIO()
53    t1.dump(stream)
54    stream.seek(0)
55    t3 = ul4c.load(stream)
56    s3 = unicode(t3)
57    assert result <= t3.renders(**variables)
58    assert s1 == s2 == s3
59
60
61def checkcompileerror(msg, source):
62    try:
63        ul4c.compile(source)
64    except Exception, exc:
65        assert re.search(msg, str(exc)) is not None
66    else:
67        py.test.fail("Didn't raise exception")
68
69
70def checkrunerror(msg, source, **variables):
71    # Check with template compiled from source
72    t1 = ul4c.compile(source)
73    s1 = unicode(t1)
74    try:
75        t1.renders(**variables)
76    except Exception, exc:
77        assert re.search(msg, "%s.%s: %s" % (exc.__class__.__module__, exc.__class__.__name__, exc)) is not None
78    else:
79        py.test.fail("Didn't raise exception")
80
81    # Check with template loaded again via the string interface
82    t2 = ul4c.loads(t1.dumps())
83    s2 = unicode(t2)
84    try:
85        t2.renders(**variables)
86    except Exception, exc:
87        assert re.search(msg, "%s.%s: %s" % (exc.__class__.__module__, exc.__class__.__name__, exc)) is not None
88    else:
89        py.test.fail("Didn't raise exception")
90
91    # Check with template loaded again via the stream interface
92    stream = StringIO.StringIO()
93    t1.dump(stream)
94    stream.seek(0)
95    t3 = ul4c.load(stream)
96    s3 = unicode(t3)
97    try:
98        t3.renders(**variables)
99    except Exception, exc:
100        assert re.search(msg, "%s.%s: %s" % (exc.__class__.__module__, exc.__class__.__name__, exc)) is not None
101    else:
102        py.test.fail("Didn't raise exception")
103    assert s1 == s2 == s3
104
105
106def test_text():
107    check(u'gurk', u'gurk')
108    check(u'g\xfcrk', u'g\xfcrk')
109
110
111def test_none():
112    check('', u'<?print None?>')
113
114    check('no', u'<?if None?>yes<?else?>no<?end if?>')
115
116
117def test_false():
118    check('False', u'<?print False?>')
119
120    check('no', u'<?if False?>yes<?else?>no<?end if?>')
121
122
123def test_true():
124    check('True', u'<?print True?>')
125
126    check('yes', u'<?if True?>yes<?else?>no<?end if?>')
127
128
129def test_int():
130    check('0', u'<?print 0?>')
131    check('42', u'<?print 42?>')
132    check('-42', u'<?print -42?>')
133    check('255', u'<?print 0xff?>')
134    check('255', u'<?print 0Xff?>')
135    check('-255', u'<?print -0xff?>')
136    check('-255', u'<?print -0Xff?>')
137    check('63', u'<?print 0o77?>')
138    check('63', u'<?print 0O77?>')
139    check('-63', u'<?print -0o77?>')
140    check('-63', u'<?print -0O77?>')
141    check('7', u'<?print 0b111?>')
142    check('7', u'<?print 0B111?>')
143    check('-7', u'<?print -0b111?>')
144    check('-7', u'<?print -0B111?>')
145
146    check('no', u'<?if 0?>yes<?else?>no<?end if?>')
147    check('yes', u'<?if 1?>yes<?else?>no<?end if?>')
148    check('yes', u'<?if -1?>yes<?else?>no<?end if?>')
149
150
151def test_float():
152    check('0.0', u'<?print 0.?>')
153    check('42.0', u'<?print 42.?>')
154    check('-42.0', u'<?print -42.?>')
155    check('1e+42', u'<?print 1E42?>')
156    check('1e+42', u'<?print 1e42?>')
157    check('-1e+42', u'<?print -1E42?>')
158    check('-1e+42', u'<?print -1e42?>')
159
160    check('no', u'<?if 0.?>yes<?else?>no<?end if?>')
161    check('yes', u'<?if 1.?>yes<?else?>no<?end if?>')
162    check('yes', u'<?if -1.?>yes<?else?>no<?end if?>')
163
164
165def test_string():
166    check('foo', u'<?print "foo"?>')
167    check('\n', u'<?print "\\n"?>')
168    check('\r', u'<?print "\\r"?>')
169    check('\t', u'<?print "\\t"?>')
170    check('\f', u'<?print "\\f"?>')
171    check('\b', u'<?print "\\b"?>')
172    check('\a', u'<?print "\\a"?>')
173    check('\x1b', u'<?print "\\e"?>')
174    check('"', u'<?print "\\""?>')
175    check("'", u'<?print "\\\'"?>')
176    check(u'\u20ac', u'<?print "\u20ac"?>')
177    check(u'\xff', u'<?print "\\xff"?>')
178    check(u'\u20ac', u'''<?print "\\u20ac"?>''')
179    checkcompileerror("Unterminated string", u'<?print "?>')
180    check("\\xxx", u'<?print "\\xxx"?>')
181    check("a\nb", u'<?print "a\nb"?>')
182
183    check('no', u'<?if ""?>yes<?else?>no<?end if?>')
184    check('yes', u'<?if "foo"?>yes<?else?>no<?end if?>')
185
186
187def test_date():
188    check('2000-02-29T00:00:00', u'<?print 2000-02-29T.isoformat()?>')
189    check('2000-02-29T12:34:00', u'<?print 2000-02-29T12:34.isoformat()?>')
190    check('2000-02-29T12:34:56', u'<?print 2000-02-29T12:34:56.isoformat()?>')
191    check('2000-02-29T12:34:56.987654', u'<?print 2000-02-29T12:34:56.987654.isoformat()?>')
192    check('yes', u'<?if 2000-02-29T12:34:56.987654?>yes<?else?>no<?end if?>')
193
194
195def test_color():
196    check('255,255,255,255', u'<?code c = #fff?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>')
197    check('255,255,255,255', u'<?code c = #ffffff?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>')
198    check('18,52,86,255', u'<?code c = #123456?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>')
199    check('17,34,51,68', u'<?code c = #1234?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>')
200    check('18,52,86,120', u'<?code c = #12345678?><?print c[0]?>,<?print c[1]?>,<?print c[2]?>,<?print c[3]?>')
201    check('yes', u'<?if #fff?>yes<?else?>no<?end if?>')
202
203
204def test_list():
205    check('', u'<?for item in []?><?print item?>;<?end for?>')
206    check('1;', u'<?for item in [1]?><?print item?>;<?end for?>')
207    check('1;', u'<?for item in [1,]?><?print item?>;<?end for?>')
208    check('1;2;', u'<?for item in [1, 2]?><?print item?>;<?end for?>')
209    check('1;2;', u'<?for item in [1, 2,]?><?print item?>;<?end for?>')
210    check('no', u'<?if []?>yes<?else?>no<?end if?>')
211    check('yes', u'<?if [1]?>yes<?else?>no<?end if?>')
212
213
214def test_dict():
215    check('', u'<?for (key, value) in {}.items()?><?print key?>:<?print value?>\n<?end for?>')
216    check('1:2\n', u'<?for (key, value) in {1:2}.items()?><?print key?>:<?print value?>\n<?end for?>')
217    check('1:2\n', u'<?for (key, value) in {1:2,}.items()?><?print key?>:<?print value?>\n<?end for?>')
218    # With duplicate keys, later ones simply overwrite earlier ones
219    check('1:3\n', u'<?for (key, value) in {1:2, 1: 3}.items()?><?print key?>:<?print value?>\n<?end for?>')
220    # Test **
221    check('1:2\n', u'<?for (key, value) in {**{1:2}}.items()?><?print key?>:<?print value?>\n<?end for?>')
222    check('1:4\n', u'<?for (key, value) in {1:1, **{1:2}, 1:3, **{1:4}}.items()?><?print key?>:<?print value?>\n<?end for?>')
223    check('no', u'<?if {}?>yes<?else?>no<?end if?>')
224    check('yes', u'<?if {1:2}?>yes<?else?>no<?end if?>')
225
226
227def test_code_storevar():
228    check('42', u'<?code x = 42?><?print x?>')
229    check('xyzzy', u'<?code x = "xyzzy"?><?print x?>')
230
231
232def test_code_addvar():
233    check('40', u'<?code x = 17?><?code x += 23?><?print x?>')
234    check('xyzzy', u'<?code x = "xyz"?><?code x += "zy"?><?print x?>')
235
236
237def test_code_subvar():
238    check('-6', u'<?code x = 17?><?code x -= 23?><?print x?>')
239
240
241def test_code_mulvar():
242    check('391', u'<?code x = 17?><?code x *= 23?><?print x?>')
243    check(17*'xyzzy', u'<?code x = 17?><?code x *= "xyzzy"?><?print x?>')
244    check(17*'xyzzy', u'<?code x = "xyzzy"?><?code x *= 17?><?print x?>')
245
246
247def test_code_floordivvar():
248    check('2', u'<?code x = 5?><?code x //= 2?><?print x?>')
249    check('-3', u'<?code x = -5?><?code x //= 2?><?print x?>')
250
251
252def test_code_truedivvar():
253    check('2.5', u'<?code x = 5?><?code x /= 2?><?print x?>')
254    check('-2.5', u'<?code x = -5?><?code x /= 2?><?print x?>')
255
256
257def test_code_modvar():
258    check('4', u'<?code x = 1729?><?code x %= 23?><?print x?>')
259
260
261def test_code_delvar():
262    checkrunerror('KeyError', u'<?code x = 1729?><?code del x?><?print x?>')
263
264
265def test_for_string():
266    check('', u'<?for c in data?>(<?print c?>)<?end for?>', data="")
267    check('(g)(u)(r)(k)', u'<?for c in data?>(<?print c?>)<?end for?>', data="gurk")
268
269
270def test_for_list():
271    check('', u'<?for c in data?>(<?print c?>)<?end for?>', data="")
272    check('(g)(u)(r)(k)', u'<?for c in data?>(<?print c?>)<?end for?>', data=["g", "u", "r", "k"])
273
274
275def test_for_dict():
276    check('', u'<?for c in data?>(<?print c?>)<?end for?>', data={})
277    check('(a)(b)(c)', u'<?for c in sorted(data)?>(<?print c?>)<?end for?>', data=dict(a=1, b=2, c=3))
278
279
280def test_for_nested():
281    check('[(1)(2)][(3)(4)]', u'<?for list in data?>[<?for n in list?>(<?print n?>)<?end for?>]<?end for?>', data=[[1, 2], [3, 4]])
282
283
284def test_for_unpacking():
285    data = [
286        ("spam", "eggs", 17),
287        ("gurk", "hurz", 23),
288        ("hinz", "kunz", 42)
289    ]
290    check('(spam)(gurk)(hinz)', u'<?for (a,) in data?>(<?print a?>)<?end for?>', data=data)
291    check('(spam,eggs)(gurk,hurz)(hinz,kunz)', u'<?for (a, b) in data?>(<?print a?>,<?print b?>)<?end for?>', data=data)
292    check('(spam,eggs,17)(gurk,hurz,23)(hinz,kunz,42)', u'<?for (a, b, c) in data?>(<?print a?>,<?print b?>,<?print c?>)<?end for?>', data=data)
293
294
295def test_break():
296    check('1, 2, ', u'<?for i in [1,2,3]?><?print i?>, <?if i==2?><?break?><?end if?><?end for?>')
297
298
299def test_break_nested():
300    check('1, 1, 2, 1, 2, 3, ', u'<?for i in [1,2,3,4]?><?for j in [1,2,3,4]?><?print j?>, <?if j>=i?><?break?><?end if?><?end for?><?if i>=3?><?break?><?end if?><?end for?>')
301
302
303def test_continue():
304    check('1, 3, ', u'<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?print i?>, <?end for?>')
305
306
307def test_continue_nested():
308    check('1, 3, \n1, 3, \n', u'<?for i in [1,2,3]?><?if i==2?><?continue?><?end if?><?for j in [1,2,3]?><?if j==2?><?continue?><?end if?><?print j?>, <?end for?>\n<?end for?>')
309
310
311def test_if():
312    check('42', u'<?if data?><?print data?><?end if?>', data=42)
313
314
315def test_else():
316    check('42', u'<?if data?><?print data?><?else?>no<?end if?>', data=42)
317    check('no', u'<?if data?><?print data?><?else?>no<?end if?>', data=0)
318
319
320def test_block_errors():
321    checkcompileerror("in u?.<.for x in data.>..*block unclosed", u'<?for x in data?>')
322    checkcompileerror("endif doesn't match any if", u'<?for x in data?><?end if?>')
323    checkcompileerror("not in any block", u'<?end?>')
324    checkcompileerror("not in any block", u'<?end for?>')
325    checkcompileerror("not in any block", u'<?end if?>')
326    checkcompileerror("else doesn't match any if", u'<?else?>')
327    checkcompileerror("in u?.<.if data.>..*block unclosed", u'<?if data?>')
328    checkcompileerror("in u?.<.if data.>..*block unclosed", u'<?if data?><?else?>')
329    checkcompileerror("duplicate else", u'<?if data?><?else?><?else?>')
330    checkcompileerror("else already seen in elif", u'<?if data?><?else?><?elif data?>')
331    checkcompileerror("else already seen in elif", u'<?if data?><?elif data?><?elif data?><?else?><?elif data?>')
332
333
334def test_empty():
335    checkcompileerror("expression required", u'<?print?>')
336    checkcompileerror("expression required", u'<?if?>')
337    checkcompileerror("expression required", u'<<?if x?><?elif?><?end if?>')
338    checkcompileerror("loop expression required", u'<?for?>')
339    checkcompileerror("statement required", u'<?code?>')
340    checkcompileerror("render statement required", u'<?render?>')
341
342
343def test_add():
344    check('42', u'<?print 21+21?>')
345    check('42', u'<?code x=21?><?code y=21?><?print x+y?>')
346    check('foobar', u'<?code x="foo"?><?code y="bar"?><?print x+y?>')
347    check('(f)(o)(o)(b)(a)(r)', u'<?for i in data.foo+data.bar?>(<?print i?>)<?end for?>', data=dict(foo="foo", bar="bar"))
348
349
350def test_sub():
351    check('0', u'<?print 21-21?>')
352    check('0', u'<?code x=21?><?code y=21?><?print x-y?>')
353
354
355
356def test_mul():
357    check(str(17*23), u'<?print 17*23?>')
358    check(str(17*23), u'<?code x=17?><?code y=23?><?print x*y?>')
359    check(17*"foo", u'<?print 17*"foo"?>')
360    check(17*"foo", u'<?code x=17?><?code y="foo"?><?print x*y?>')
361    check("foo"*17, u'<?code x="foo"?><?code y=17?><?print x*y?>')
362    check("foo"*17, u'<?print "foo"*17?>')
363    check("(foo)(bar)(foo)(bar)(foo)(bar)", u'<?for i in 3*data?>(<?print i?>)<?end for?>', data=["foo", "bar"])
364
365
366def test_truediv():
367    check("0.5", u'<?print 1/2?>')
368    check("0.5", u'<?code x=1?><?code y=2?><?print x/y?>')
369
370
371def test_floordiv():
372    check("0", u'<?print 1//2?>')
373    check("0", u'<?code x=1?><?code y=2?><?print x//y?>')
374
375
376def test_mod():
377    check(str(42%17), u'<?print 42%17?>')
378    check(str(42%17), u'<?code x=42?><?code y=17?><?print x%y?>')
379
380
381def test_eq():
382    check("False", u'<?print 17==23?>')
383    check("True", u'<?print 17==17?>')
384    check("False", u'<?print x==23?>', x=17)
385    check("True", u'<?print x==23?>', x=23)
386
387
388def test_ne():
389    check("True", u'<?print 17!=23?>')
390    check("False", u'<?print 17!=17?>')
391    check("True", u'<?print x!=23?>', x=17)
392    check("False", u'<?print x!=23?>', x=23)
393
394
395def test_lt():
396    check("True", u'<?print 1<2?>')
397    check("False", u'<?print 2<2?>')
398    check("False", u'<?print 3<2?>')
399    check("True", u'<?print x<2?>', x=1)
400    check("False", u'<?print x<2?>', x=2)
401    check("False", u'<?print x<2?>', x=3)
402
403
404def test_le():
405    check("True", u'<?print 1<=2?>')
406    check("True", u'<?print 2<=2?>')
407    check("False", u'<?print 3<=2?>')
408    check("True", u'<?print x<=2?>', x=1)
409    check("True", u'<?print x<=2?>', x=2)
410    check("False", u'<?print x<=2?>', x=3)
411
412
413def test_gt():
414    check("False", u'<?print 1>2?>')
415    check("False", u'<?print 2>2?>')
416    check("True", u'<?print 3>2?>')
417    check("False", u'<?print x>2?>', x=1)
418    check("False", u'<?print x>2?>', x=2)
419    check("True", u'<?print x>2?>', x=3)
420
421
422def test_and():
423    check("False", u'<?print x and y?>', x=False, y=False)
424    check("False", u'<?print x and y?>', x=False, y=True)
425    check("0", u'<?print x and y?>', x=0, y=True)
426
427
428def test_or():
429    check("False", u'<?print x or y?>', x=False, y=False)
430    check("True", u'<?print x or y?>', x=False, y=True)
431    check("42", u'<?print x or y?>', x=42, y=True)
432
433
434def test_not():
435    check("True", u'<?print not x?>', x=False)
436    check("False", u'<?print not x?>', x=42)
437
438
439def test_ge():
440    check("False", u'<?print 1>=2?>')
441    check("True", u'<?print 2>=2?>')
442    check("True", u'<?print 3>=2?>')
443    check("False", u'<?print x>=2?>', x=1)
444    check("True", u'<?print x>=2?>', x=2)
445    check("True", u'<?print x>=2?>', x=3)
446
447
448def test_getitem():
449    check("u", u"<?print 'gurk'[1]?>")
450    check("u", u"<?print x[1]?>", x="gurk")
451    check("u", u"<?print 'gurk'[-3]?>")
452    check("u", u"<?print x[-3]?>", x="gurk")
453    checkcompileerror("IndexError", u"<?print 'gurk'[4]?>")
454    checkrunerror("IndexError", u"<?print x[4]?>", x="gurk")
455    checkcompileerror("IndexError", u"<?print 'gurk'[-5]?>")
456    checkrunerror("IndexError", u"<?print x[-5]?>", x="gurk")
457
458
459def test_getslice12():
460    check("ur", u"<?print 'gurk'[1:3]?>")
461    check("ur", u"<?print x[1:3]?>", x="gurk")
462    check("ur", u"<?print 'gurk'[-3:-1]?>")
463    check("ur", u"<?print x[-3:-1]?>", x="gurk")
464    check("", u"<?print 'gurk'[4:10]?>")
465    check("", u"<?print x[4:10]?>", x="gurk")
466    check("", u"<?print 'gurk'[-10:-5]?>")
467    check("", u"<?print x[-10:-5]?>", x="gurk")
468
469
470def test_getslice1():
471    check("urk", u"<?print 'gurk'[1:]?>")
472    check("urk", u"<?print x[1:]?>", x="gurk")
473    check("urk", u"<?print 'gurk'[-3:]?>")
474    check("urk", u"<?print x[-3:]?>", x="gurk")
475    check("", u"<?print 'gurk'[4:]?>")
476    check("", u"<?print x[4:]?>", x="gurk")
477    check("gurk", u"<?print 'gurk'[-10:]?>")
478    check("gurk", u"<?print x[-10:]?>", x="gurk")
479
480
481def test_getslice2():
482    check("gur", u"<?print 'gurk'[:3]?>")
483    check("gur", u"<?print x[:3]?>", x="gurk")
484    check("gur", u"<?print 'gurk'[:-1]?>")
485    check("gur", u"<?print x[:-1]?>", x="gurk")
486    check("gurk", u"<?print 'gurk'[:10]?>")
487    check("gurk", u"<?print x[:10]?>", x="gurk")
488    check("", u"<?print 'gurk'[:-5]?>")
489    check("", u"<?print x[:-5]?>", x="gurk")
490
491
492def test_nested():
493    sc = u"4"
494    sv = u"x"
495    n = 4
496    for i in xrange(8): # when using 10 compiling the variable will run out of registers
497        sc = u"(%s)+(%s)" % (sc, sc)
498        sv = u"(%s)+(%s)" % (sv, sv)
499        n = n+n
500    check(str(n), u'<?print %s?>' % sc)
501    check(str(n), u'<?code x=4?><?print %s?>' % sv)
502
503
504def test_precedence():
505    check("14", u'<?print 2+3*4?>')
506    check("20", u'<?print (2+3)*4?>')
507    check("10", u'<?print -2+-3*-4?>')
508    check("14", u'<?print --2+--3*--4?>')
509    check("14", u'<?print (-(-2))+(-((-3)*-(-4)))?>')
510    check("42", u'<?print 2*data.value?>', data=dict(value=21))
511    check("42", u'<?print data.value[0]?>', data=dict(value=[42]))
512    check("42", u'<?print data[0].value?>', data=[dict(value=42)])
513    check("42", u'<?print data[0][0][0]?>', data=[[[42]]])
514    check("42", u'<?print data.value.value[0]?>', data=dict(value=dict(value=[42])))
515    check("42", u'<?print data.value.value[0].value.value[0]?>', data=dict(value=dict(value=[dict(value=dict(value=[42]))])))
516
517
518def test_bracket():
519    sc = u"4"
520    sv = u"x"
521    for i in xrange(10):
522        sc = u"(%s)" % sc
523        sv = u"(%s)" % sv
524
525    check("4", u'<?print %s?>' % sc)
526    check("4", u'<?code x=4?><?print %s?>' % sv)
527
528
529def test_function_now():
530    checkrunerror("function u?'now' unknown", u"<?print now(1)?>")
531    checkrunerror("function u?'now' unknown", u"<?print now(1, 2)?>")
532    now = unicode(datetime.datetime.now())
533    checkle(now, u"<?print now()?>")
534
535
536def test_function_vars():
537    checkrunerror("function u?'vars' unknown", "<?print vars(1)?>")
538    checkrunerror("function u?'vars' unknown", "<?print vars(1, 2)?>")
539    check("yes", u"<?if 'spam' in vars()?>yes<?else?>no<?end if?>", spam="eggs")
540
541
542def test_function_xmlescape():
543    checkrunerror("function u?'xmlescape' unknown", u"<?print xmlescape()?>")
544    checkrunerror("function u?'xmlescape' unknown", u"<?print xmlescape(1, 2)?>")
545    check("&lt;&gt;&amp;&#39;&quot;gurk", u"<?print xmlescape(data)?>", data='<>&\'"gurk')
546
547
548def test_function_csv():
549    checkrunerror("function u?'csv' unknown", u"<?print csv()?>")
550    checkrunerror("function u?'csv' unknown", u"<?print csv(1, 2)?>")
551    check("", u"<?print csv(data)?>", data=None)
552    check("False", u"<?print csv(data)?>", data=False)
553    check("True", u"<?print csv(data)?>", data=True)
554    check("42", u"<?print csv(data)?>", data=42)
555    # no check for float
556    check("abc", u"<?print csv(data)?>", data="abc")
557    check('"a,b,c"', u"<?print csv(data)?>", data="a,b,c")
558    check('"a""b""c"', u"<?print csv(data)?>", data='a"b"c')
559    check('"a\nb\nc"', u"<?print csv(data)?>", data="a\nb\nc")
560
561
562def test_function_json():
563    checkrunerror("function u?'json' unknown", u"<?print json()?>")
564    checkrunerror("function u?'json' unknown", u"<?print json(1, 2)?>")
565    check("null", u"<?print json(data)?>", data=None)
566    check("false", u"<?print json(data)?>", data=False)
567    check("true", u"<?print json(data)?>", data=True)
568    check("42", u"<?print json(data)?>", data=42)
569    # no check for float
570    check('"abc"', u"<?print json(data)?>", data="abc")
571    check('[1, 2, 3]', u"<?print json(data)?>", data=[1, 2, 3])
572    check('{"one": 1}', u"<?print json(data)?>", data={"one": 1})
573
574
575def test_function_str():
576    checkrunerror("function u?'str' unknown", u"<?print str()?>")
577    checkrunerror("function u?'str' unknown", u"<?print str(1, 2)?>")
578    check("", u"<?print str(data)?>", data=None)
579    check("True", u"<?print str(data)?>", data=True)
580    check("False", u"<?print str(data)?>", data=False)
581    check("42", u"<?print str(data)?>", data=42)
582    check("4.2", u"<?print str(data)?>", data=4.2)
583    check("foo", u"<?print str(data)?>", data="foo")
584
585
586def test_function_int():
587    checkrunerror("function u?'int' unknown", u"<?print int()?>")
588    checkrunerror("function u?'int' unknown", u"<?print int(1, 2, 3)?>")
589    checkrunerror("int\\(\\) argument must be a string or a number, not 'NoneType'", u"<?print int(data)?>", data=None)
590    check("1", u"<?print int(data)?>", data=True)
591    check("0", u"<?print int(data)?>", data=False)
592    check("42", u"<?print int(data)?>", data=42)
593    check("4", u"<?print int(data)?>", data=4.2)
594    check("42", u"<?print int(data)?>", data="42")
595    check("66", u"<?print int(data, 16)?>", data="42")
596    checkrunerror("invalid literal for int\\(\\) with base 10: 'foo'", u"<?print int(data)?>", data="foo")
597
598
599def test_function_len():
600    checkrunerror("function u?'len' unknown", u"<?print len()?>")
601    checkrunerror("function u?'len' unknown", u"<?print len(1, 2)?>")
602    checkrunerror("object of type 'NoneType' has no len", u"<?print len(data)?>", data=None)
603    checkrunerror("object of type 'bool' has no len", u"<?print len(data)?>", data=True)
604    checkrunerror("object of type 'bool' has no len", u"<?print len(data)?>", data=False)
605    checkrunerror("object of type 'int' has no len", u"<?print len(data)?>", data=42)
606    checkrunerror("object of type 'float' has no len", u"<?print len(data)?>", data=4.2)
607    check("42", u"<?print len(data)?>", data=42*"?")
608    check("42", u"<?print len(data)?>", data=42*[None])
609    check("42", u"<?print len(data)?>", data=dict.fromkeys(xrange(42)))
610
611
612def test_function_enumerate():
613    checkrunerror("function u?'enumerate' unknown", u"<?print enumerate()?>")
614    checkrunerror("function u?'enumerate' unknown", u"<?print enumerate(1, 2)?>")
615    code = u"<?for (i, value) in enumerate(data)?><?print i?>:<?print value?>\n<?end for?>"
616    checkrunerror("'NoneType' object is not iterable", code, data=None)
617    checkrunerror("'bool' object is not iterable", code, data=True)
618    checkrunerror("'bool' object is not iterable", code, data=False)
619    checkrunerror("'int' object is not iterable", code, data=42)
620    checkrunerror("'float' object is not iterable", code, data=4.2)
621    check("0:f\n1:o\n2:o\n", code, data="foo")
622    check("0:foo\n1:bar\n", code, data=["foo", "bar"])
623    check("0:foo\n", code, data=dict(foo=True))
624
625
626def test_function_isnone():
627    checkrunerror("function u?'isnone' unknown", u"<?print isnone()?>")
628    checkrunerror("function u?'isnone' unknown", u"<?print isnone(1, 2)?>")
629    code = u"<?print isnone(data)?>"
630    check("True", code, data=None)
631    check("False", code, data=True)
632    check("False", code, data=False)
633    check("False", code, data=42)
634    check("False", code, data=4.2)
635    check("False", code, data="foo")
636    check("False", code, data=datetime.datetime.now())
637    check("False", code, data=())
638    check("False", code, data=[])
639    check("False", code, data={})
640    check("False", code, data=ul4c.compile(u""))
641
642
643def test_function_isbool():
644    checkrunerror("function u?'isbool' unknown", u"<?print isbool()?>")
645    checkrunerror("function u?'isbool' unknown", u"<?print isbool(1, 2)?>")
646    code = u"<?print isbool(data)?>"
647    check("False", code, data=None)
648    check("True", code, data=True)
649    check("True", code, data=False)
650    check("False", code, data=42)
651    check("False", code, data=4.2)
652    check("False", code, data="foo")
653    check("False", code, data=datetime.datetime.now())
654    check("False", code, data=())
655    check("False", code, data=[])
656    check("False", code, data={})
657    check("False", code, data=ul4c.compile(u""))
658
659
660def test_function_isint():
661    checkrunerror("function u?'isint' unknown", u"<?print isint()?>")
662    checkrunerror("function u?'isint' unknown", u"<?print isint(1, 2)?>")
663    code = u"<?print isint(data)?>"
664    check("False", code, data=None)
665    check("False", code, data=True)
666    check("False", code, data=False)
667    check("True", code, data=42)
668    check("False", code, data=4.2)
669    check("False", code, data="foo")
670    check("False", code, data=datetime.datetime.now())
671    check("False", code, data=())
672    check("False", code, data=[])
673    check("False", code, data={})
674    check("False", code, data=ul4c.compile(u""))
675
676
677def test_function_isfloat():
678    checkrunerror("function u?'isfloat' unknown", u"<?print isfloat()?>")
679    checkrunerror("function u?'isfloat' unknown", u"<?print isfloat(1, 2)?>")
680    code = u"<?print isfloat(data)?>"
681    check("False", code, data=None)
682    check("False", code, data=True)
683    check("False", code, data=False)
684    check("False", code, data=42)
685    check("True", code, data=4.2)
686    check("False", code, data="foo")
687    check("False", code, data=datetime.datetime.now())
688    check("False", code, data=())
689    check("False", code, data=[])
690    check("False", code, data={})
691    check("False", code, data=ul4c.compile(u""))
692
693
694def test_function_isstr():
695    checkrunerror("function u?'isstr' unknown", u"<?print isstr()?>")
696    checkrunerror("function u?'isstr' unknown", u"<?print isstr(1, 2)?>")
697    code = u"<?print isstr(data)?>"
698    check("False", code, data=None)
699    check("False", code, data=True)
700    check("False", code, data=False)
701    check("False", code, data=42)
702    check("False", code, data=4.2)
703    check("True", code, data="foo")
704    check("False", code, data=datetime.datetime.now())
705    check("False", code, data=())
706    check("False", code, data=[])
707    check("False", code, data={})
708    check("False", code, data=ul4c.compile(u""))
709
710
711def test_function_isdate():
712    checkrunerror("function u?'isdate' unknown", u"<?print isdate()?>")
713    checkrunerror("function u?'isdate' unknown", u"<?print isdate(1, 2)?>")
714    code = u"<?print isdate(data)?>"
715    check("False", code, data=None)
716    check("False", code, data=True)
717    check("False", code, data=False)
718    check("False", code, data=42)
719    check("False", code, data=4.2)
720    check("False", code, data="foo")
721    check("True", code, data=datetime.datetime.now())
722    check("False", code, data=())
723    check("False", code, data=[])
724    check("False", code, data={})
725    check("False", code, data=ul4c.compile(u""))
726
727
728def test_function_islist():
729    checkrunerror("function u?'islist' unknown", u"<?print islist()?>")
730    checkrunerror("function u?'islist' unknown", u"<?print islist(1, 2)?>")
731    code = u"<?print islist(data)?>"
732    check("False", code, data=None)
733    check("False", code, data=True)
734    check("False", code, data=False)
735    check("False", code, data=42)
736    check("False", code, data=4.2)
737    check("False", code, data="foo")
738    check("False", code, data=datetime.datetime.now())
739    check("True", code, data=())
740    check("True", code, data=[])
741    check("False", code, data={})
742    check("False", code, data=ul4c.compile(u""))
743
744
745def test_function_isdict():
746    checkrunerror("function u?'isdict' unknown", u"<?print isdict()?>")
747    checkrunerror("function u?'isdict' unknown", u"<?print isdict(1, 2)?>")
748    code = u"<?print isdict(data)?>"
749    check("False", code, data=None)
750    check("False", code, data=True)
751    check("False", code, data=False)
752    check("False", code, data=42)
753    check("False", code, data=4.2)
754    check("False", code, data="foo")
755    check("False", code, data=datetime.datetime.now())
756    check("False", code, data=())
757    check("False", code, data=[])
758    check("True", code, data={})
759    check("False", code, data=ul4c.compile(u""))
760
761
762def test_function_istemplate():
763    checkrunerror("function u?'istemplate' unknown", u"<?print istemplate()?>")
764    checkrunerror("function u?'istemplate' unknown", u"<?print istemplate(1, 2)?>")
765    code = u"<?print istemplate(data)?>"
766    check("False", code, data=None)
767    check("False", code, data=True)
768    check("False", code, data=False)
769    check("False", code, data=42)
770    check("False", code, data=4.2)
771    check("False", code, data="foo")
772    check("False", code, data=datetime.datetime.now())
773    check("False", code, data=())
774    check("False", code, data=[])
775    check("False", code, data={})
776    check("True", code, data=ul4c.compile(u""))
777
778
779def test_function_get():
780    checkrunerror("function u?'get' unknown", u"<?print get()?>")
781    check("", u"<?print get('x')?>")
782    check("42", u"<?print get('x')?>", x=42)
783    check("17", u"<?print get('x', 17)?>")
784    check("42", u"<?print get('x', 17)?>", x=42)
785
786
787def test_function_repr():
788    checkrunerror("function u?'repr' unknown", u"<?print repr()?>")
789    checkrunerror("function u?'repr' unknown", u"<?print repr(1, 2)?>")
790    code = u"<?print repr(data)?>"
791    check("None", code, data=None)
792    check("True", code, data=True)
793    check("False", code, data=False)
794    check("42", code, data=42)
795    # no test for float
796    check("'foo'", code, data="foo")
797    # no test for tuples, lists and dicts
798
799
800def test_function_chr():
801    checkrunerror("function u?'chr' unknown", u"<?print chr()?>")
802    checkrunerror("function u?'chr' unknown", u"<?print chr(1, 2)?>")
803    code = u"<?print chr(data)?>"
804    check("\x00", code, data=0)
805    check("a", code, data=ord("a"))
806    check(u"\u20ac", code, data=0x20ac)
807
808
809def test_function_ord():
810    checkrunerror("function u?'ord' unknown", u"<?print ord()?>")
811    checkrunerror("function u?'ord' unknown", u"<?print ord(1, 2)?>")
812    code = u"<?print ord(data)?>"
813    check("0", code, data="\x00")
814    check(str(ord("a")), code, data="a")
815    check(str(0x20ac), code, data=u"\u20ac")
816
817
818def test_function_hex():
819    checkrunerror("function u?'hex' unknown", u"<?print hex()?>")
820    checkrunerror("function u?'hex' unknown", u"<?print hex(1, 2)?>")
821    code = u"<?print hex(data)?>"
822    check("0x0", code, data=0)
823    check("0xff", code, data=0xff)
824    check("0xffff", code, data=0xffff)
825    check("-0xffff", code, data=-0xffff)
826
827
828def test_function_oct():
829    checkrunerror("function u?'oct' unknown", u"<?print oct()?>")
830    checkrunerror("function u?'oct' unknown", u"<?print oct(1, 2)?>")
831    code = u"<?print oct(data)?>"
832    check("0o0", code, data=0)
833    check("0o77", code, data=077)
834    check("0o7777", code, data=07777)
835    check("-0o7777", code, data=-07777)
836
837
838def test_function_bin():
839    checkrunerror("function u?'bin' unknown", u"<?print bin()?>")
840    checkrunerror("function u?'bin' unknown", u"<?print bin(1, 2)?>")
841    code = u"<?print bin(data)?>"
842    check("0b0", code, data=0)
843    check("0b11", code, data=3)
844    check("-0b1111", code, data=-15)
845
846
847def test_function_sorted():
848    checkrunerror("function u?'sorted' unknown", u"<?print sorted()?>")
849    checkrunerror("function u?'sorted' unknown", u"<?print sorted(1, 2)?>")
850    code = u"<?for i in sorted(data)?><?print i?><?end for?>"
851    check("gkru", code, data="gurk")
852    check("24679", code, data="92746")
853    check("012", code, data={0: "zero", 1: "one", 2: "two"})
854
855
856def test_function_range():
857    checkrunerror("function u?'sorted' unknown", u"<?print sorted()?>")
858    code = u"<?for i in range(data)?><?print i?><?end for?>"
859    check("", code, data=-10)
860    check("", code, data=0)
861    check("0", code, data=1)
862    check("01234", code, data=5)
863    code = u"<?for i in range(data[0], data[1])?><?print i?><?end for?>"
864    check("", code, data=[0, -10])
865    check("", code, data=[0, 0])
866    check("01234", code, data=[0, 5])
867    check("-5-4-3-2-101234", code, data=[-5, 5])
868    code = u"<?for i in range(data[0], data[1], data[2])?><?print i?><?end for?>"
869    check("", code, data=[0, -10, 1])
870    check("", code, data=[0, 0, 1])
871    check("02468", code, data=[0, 10, 2])
872    check("", code, data=[0, 10, -2])
873    check("108642", code, data=[10, 0, -2])
874    check("", code, data=[10, 0, 2])
875
876
877def test_function_zip():
878    checkrunerror("function u?'zip' unknown", u"<?print zip()?>")
879    checkrunerror("function u?'zip' unknown", u"<?print zip(1)?>")
880    code = u"<?for (ix, iy) in zip(x, y)?><?print ix?>-<?print iy?>;<?end for?>"
881    check("", code, x=[], y=[])
882    check("1-3;2-4;", code, x=[1, 2], y=[3, 4])
883    check("1-4;2-5;", code, x=[1, 2, 3], y=[4, 5])
884    code = u"<?for (ix, iy, iz) in zip(x, y, z)?><?print ix?>-<?print iy?>+<?print iz?>;<?end for?>"
885    check("", code, x=[], y=[], z=[])
886    check("1-3+5;2-4+6;", code, x=[1, 2], y=[3, 4], z=[5, 6])
887    check("1-4+6;", code, x=[1, 2, 3], y=[4, 5], z=[6])
888
889
890def test_function_type():
891    checkrunerror("function u?'type' unknown", u"<?print type()?>")
892    checkrunerror("function u?'type' unknown", u"<?print type(1, 2)?>")
893    code = u"<?print type(x)?>"
894    check("none", code, x=None)
895    check("bool", code, x=False)
896    check("bool", code, x=True)
897    check("int", code, x=42)
898    check("int", code, x=42L)
899    check("float", code, x=4.2)
900    check("str", code, x="foo")
901    check("str", code, x=u"foo")
902    check("date", code, x=datetime.datetime.now())
903    check("date", code, x=datetime.date.today())
904    check("list", code, x=(1, 2))
905    check("list", code, x=[1, 2])
906    check("dict", code, x={1: 2})
907    check("template", code, x=ul4c.compile(""))
908    check("", code, x=1j)
909
910
911def test_function_reversed():
912    checkrunerror("function u?'reversed' unknown", u"<?print reversed()?>")
913    checkrunerror("function u?'reversed' unknown", u"<?print reversed(1, 2)?>")
914    code = u"<?for i in reversed(x)?>(<?print i?>)<?end for?>"
915    check("(3)(2)(1)", code, x="123")
916    check("(3)(2)(1)", code, x=[1, 2, 3])
917    check("(3)(2)(1)", code, x=(1, 2, 3))
918
919
920def test_method_upper():
921    check("GURK", u"<?print 'gurk'.upper()?>")
922
923
924def test_method_lower():
925    check("gurk", u"<?print 'GURK'.lower()?>")
926
927
928def test_method_capitalize():
929    check("Gurk", u"<?print 'gURK'.capitalize()?>")
930
931
932def test_method_startswith():
933    check("True", u"<?print 'gurkhurz'.startswith('gurk')?>")
934    check("False", u"<?print 'gurkhurz'.startswith('hurz')?>")
935
936
937def test_method_endswith():
938    check("True", u"<?print 'gurkhurz'.endswith('hurz')?>")
939    check("False", u"<?print 'gurkhurz'.endswith('gurk')?>")
940
941
942def test_method_strip():
943    check("gurk", r"<?print ' \t\r\ngurk \t\r\n'.strip()?>")
944    check("gurk", r"<?print 'xyzzygurkxyzzy'.strip('xyz')?>")
945
946
947def test_method_lstrip():
948    check("gurk \t\r\n", ur"<?print ' \t\r\ngurk \t\r\n'.lstrip()?>")
949    check("gurkxyzzy", ur"<?print 'xyzzygurkxyzzy'.lstrip('xyz')?>")
950
951
952def test_method_rstrip():
953    check(" \t\r\ngurk", ur"<?print ' \t\r\ngurk \t\r\n'.rstrip()?>")
954    check("xyzzygurk", ur"<?print 'xyzzygurkxyzzy'.rstrip('xyz')?>")
955
956
957def test_method_split():
958    check("(g)(u)(r)(k)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split()?>(<?print item?>)<?end for?>")
959    check("(g)(u \t\r\nr \t\r\nk \t\r\n)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.split(None, 1)?>(<?print item?>)<?end for?>")
960    check("()(g)(u)(r)(k)()", ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx')?>(<?print item?>)<?end for?>")
961    check("()(g)(uxxrxxkxx)", ur"<?for item in 'xxgxxuxxrxxkxx'.split('xx', 2)?>(<?print item?>)<?end for?>")
962
963
964def test_method_rsplit():
965    check("(g)(u)(r)(k)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit()?>(<?print item?>)<?end for?>")
966    check("( \t\r\ng \t\r\nu \t\r\nr)(k)", ur"<?for item in ' \t\r\ng \t\r\nu \t\r\nr \t\r\nk \t\r\n'.rsplit(None, 1)?>(<?print item?>)<?end for?>")
967    check("()(g)(u)(r)(k)()", ur"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx')?>(<?print item?>)<?end for?>")
968    check("(xxgxxuxxr)(k)()", ur"<?for item in 'xxgxxuxxrxxkxx'.rsplit('xx', 2)?>(<?print item?>)<?end for?>")
969
970
971def test_method_replace():
972    check('goork', ur"<?print 'gurk'.replace('u', 'oo')?>")
973
974
975def test_method_render():
976    t = ul4c.compile(u'(<?print data?>)')
977    check('(GURK)', u"<?print t.render(data='gurk').upper()?>", t=t)
978    check('(GURK)', u"<?print t.render(**{'data': 'gurk'}).upper()?>", t=t)
979
980    t = ul4c.compile(u'(gurk)')
981    check('(GURK)', u"<?print t.render().upper()?>", t=t)
982
983
984def test_method_format():
985    now = datetime.datetime.now()
986    format = "%Y-%m-%d %H:%M:%S"
987    check(now.strftime(format), ur"<?print data.format('%s')?>" % format, data=now)
988    check('987654', u'<?print 2000-02-29T12:34:56.987654.format("%f")?>')
989
990
991def test_method_isoformat():
992    now = datetime.datetime.now()
993    check(now.isoformat(), ur"<?print data.isoformat()?>", data=now)
994
995
996def test_method_get():
997    check("42", u"<?print {}.get('foo', 42)?>")
998    check("17", u"<?print {'foo': 17}.get('foo', 42)?>")
999    check("", u"<?print {}.get('foo')?>")
1000    check("17", u"<?print {'foo': 17}.get('foo')?>")
1001
1002
1003def test_method_r_g_b_a():
1004    check('0x11', u'<?code c = #123?><?print hex(c.r())?>')
1005    check('0x22', u'<?code c = #123?><?print hex(c.g())?>')
1006    check('0x33', u'<?code c = #123?><?print hex(c.b())?>')
1007    check('0xff', u'<?code c = #123?><?print hex(c.a())?>')
1008
1009
1010def test_method_hls():
1011    check('0', u'<?code c = #fff?><?print int(c.hls()[0])?>')
1012    check('1', u'<?code c = #fff?><?print int(c.hls()[1])?>')
1013    check('0', u'<?code c = #fff?><?print int(c.hls()[2])?>')
1014
1015
1016def test_method_hlsa():
1017    check('0', u'<?code c = #fff?><?print int(c.hlsa()[0])?>')
1018    check('1', u'<?code c = #fff?><?print int(c.hlsa()[1])?>')
1019    check('0', u'<?code c = #fff?><?print int(c.hlsa()[2])?>')
1020    check('1', u'<?code c = #fff?><?print int(c.hlsa()[3])?>')
1021
1022
1023def test_method_hsv():
1024    check('0', u'<?code c = #fff?><?print int(c.hsv()[0])?>')
1025    check('0', u'<?code c = #fff?><?print int(c.hsv()[1])?>')
1026    check('1', u'<?code c = #fff?><?print int(c.hsv()[2])?>')
1027
1028
1029def test_method_hsva():
1030    check('0', u'<?code c = #fff?><?print int(c.hsva()[0])?>')
1031    check('0', u'<?code c = #fff?><?print int(c.hsva()[1])?>')
1032    check('1', u'<?code c = #fff?><?print int(c.hsva()[2])?>')
1033    check('1', u'<?code c = #fff?><?print int(c.hsva()[3])?>')
1034
1035
1036def test_method_lum():
1037    check('True', u'<?print #fff.lum() == 1?>')
1038
1039
1040def test_method_withlum():
1041    check('#fff', u'<?print #000.withlum(1)?>')
1042
1043
1044def test_method_witha():
1045    check('#0063a82a', u'<?print repr(#0063a8.witha(42))?>')
1046
1047
1048def test_render():
1049    t = ul4c.compile(u'<?print prefix?><?print data?><?print suffix?>')
1050    check('(f)(o)(o)', u'<?for c in data?><?render t(data=c, prefix="(", suffix=")")?><?end for?>', t=t, data='foo')
1051    check('(f)(o)(o)', u'<?for c in data?><?render t(data=c, **{"prefix": "(", "suffix": ")"})?><?end for?>', t=t, data='foo')
1052
1053
1054def test_render_var():
1055    t = ul4c.compile(u'<?code x += 1?><?print x?>')
1056    check('42,43,42', u'<?print x?>,<?render t(x=x)?>,<?print x?>', t=t, x=42)
1057
1058
1059def test_parse():
1060    check('42', u'<?print data.Noner?>', data=dict(Noner=42))
1061
1062
1063def test_nested_exceptions():
1064    tmpl1 = ul4c.compile(u"<?print 2*x?>")
1065    tmpl2 = ul4c.compile(u"<?render tmpl1(x=x)?>")
1066    tmpl3 = ul4c.compile(u"<?render tmpl2(tmpl1=tmpl1, x=x)?>")
1067
1068    checkrunerror(r"TypeError .*render tmpl3.*render tmpl2.*render tmpl1.*print 2.*unsupported operand type", u"<?render tmpl3(tmpl1=tmpl1, tmpl2=tmpl2, x=x)?>", tmpl1=tmpl1, tmpl2=tmpl2, tmpl3=tmpl3, x=None)
1069
1070
1071def test_note():
1072    check("foo", u"f<?note This is?>o<?note a comment?>o")
1073
1074
1075def universaltemplate():
1076    return ul4c.compile("""
1077        text
1078        <?code x = 'gurk'?>
1079        <?code x = 42?>
1080        <?code x = 4.2?>
1081        <?code x = None?>
1082        <?code x = False?>
1083        <?code x = True?>
1084        <?code x = 2009-01-04T?>
1085        <?code x = #0063a8?>
1086        <?code x = [42]?>
1087        <?code x = {"fortytwo": 42}?>
1088        <?code x = {**{"fortytwo": 42}}?>
1089        <?code x = y?>
1090        <?code x += 42?>
1091        <?code x -= 42?>
1092        <?code x *= 42?>
1093        <?code x /= 42?>
1094        <?code x //= 42?>
1095        <?code x %= 42?>
1096        <?code del x?>
1097        <?print x.gurk?>
1098        <?print x["gurk"]?>
1099        <?print x[1:2]?>
1100        <?print x[1:]?>
1101        <?print x[:2]?>
1102        <?printx x?>
1103        <?for x in "12"?><?print x?><?break?><?continue?><?end for?>
1104        <?print not x?>
1105        <?print -x?>
1106        <?print x in y?>
1107        <?print x not in y?>
1108        <?print x==y?>
1109        <?print x!=y?>
1110        <?print x<y?>
1111        <?print x<=y?>
1112        <?print x>y?>
1113        <?print x>=y?>
1114        <?print x+y?>
1115        <?print x*y?>
1116        <?print x/y?>
1117        <?print x//y?>
1118        <?print x and y?>
1119        <?print x or y?>
1120        <?print x % y?>
1121        <?print now()?>
1122        <?print repr(1)?>
1123        <?print range(1, 2)?>
1124        <?print range(1, 2, 3)?>
1125        <?print rgb(1, 2, 3, 4)?>
1126        <?print x.r()?>
1127        <?print x.find(1)?>
1128        <?print x.find(1, 2)?>
1129        <?print x.find(1, 2, 3)?>
1130        <?if x?>gurk<?elif y?>hurz<?else?>hinz<?end if?>
1131        <?render x(a=1, b=2)?>
1132    """)
1133
1134
1135def test_strtemplate():
1136    t = universaltemplate()
1137    str(t)
1138
1139
1140def test_pythonsource():
1141    t = universaltemplate()
1142    t.pythonsource()
1143    t.pythonsource("template")
1144
1145
1146def test_pythonfunction():
1147    t = universaltemplate()
1148    t.pythonfunction()
Note: See TracBrowser for help on using the browser.