Changeset 4321:a60b7ad1de5e in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/08/11 14:09:55 (9 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix many bugs found when running the test suite with UL4 templates compiled to Java.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/ll/ul4c.py

    r4319 r4321  
    19291929        self._usereg(opcode.r1) 
    19301930    def _dispatch_gt(self, opcode): 
    1931         self._do(u"r{op.r1} = !com.livinglogic.ul4.Utils.gt(r{op.r2}, r{op.r3});".format(op=opcode)) 
     1931        self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.gt(r{op.r2}, r{op.r3});".format(op=opcode)) 
    19321932        self._usereg(opcode.r1) 
    19331933    def _dispatch_ge(self, opcode): 
    1934         self._do(u"r{op.r1} = !com.livinglogic.ul4.Utils.ge(r{op.r2}, r{op.r3});".format(op=opcode)) 
     1934        self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.ge(r{op.r2}, r{op.r3});".format(op=opcode)) 
    19351935        self._usereg(opcode.r1) 
    19361936    def _dispatch_add(self, opcode): 
     
    19691969        self._usereg(opcode.r1) 
    19701970    def _dispatch_callfunc1(self, opcode): 
    1971         if opcode.arg in {"xmlescape", "csv", "repr", "enumerate", "chr", "ord", "hex", "oct", "bin", "sorted", "range", "type", "json", "reversed", "randrange", "randchoice", "abs"}: 
     1971        if opcode.arg in {"xmlescape", "csv", "repr", "enumerate", "chr", "ord", "hex", "oct", "bin", "sorted", "range", "type", "json", "reversed", "randrange", "randchoice", "abs", "str"}: 
    19721972            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.{op.arg}(r{op.r2});".format(op=opcode)) 
    1973         elif opcode.arg == "str": 
    1974             self._do(u"r{op.r1} = org.apache.commons.lang.ObjectUtils.toString(r{op.r2});".format(op=opcode)) 
    19751973        elif opcode.arg == "int": 
    19761974            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.toInteger(r{op.r2});".format(op=opcode)) 
     
    20122010            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.toInteger(r{op.r2}, r{op.r3});".format(op=opcode)) 
    20132011        elif opcode.arg == "get": 
    2014             self._do(u"r{op.r1} = {var}.containsKey(r{op.r2}) ? {var}.get(r{op.r2}) : r{op.r3};".format(op=opcode.r1, var=self._stack[-1].variables)) 
     2012            self._do(u"r{op.r1} = {var}.containsKey(r{op.r2}) ? {var}.get(r{op.r2}) : r{op.r3};".format(op=opcode, var=self._stack[-1].variables)) 
    20152013        else: 
    20162014            raise UnknownFunctionError(opcode.arg) 
     
    20292027        self._usereg(opcode.r1) 
    20302028    def _dispatch_callmeth0(self, opcode): 
    2031         if opcode.arg in {"split", "strip", "lstrip", "rstrip", "upper", "lower", "capitalize", "items", "isoformat", "mimeformat", "day", "month", "year", "hour", "minute", "second", "microsecond", "weekday", "yearday"}: 
     2029        if opcode.arg in {"split", "rsplit", "strip", "lstrip", "rstrip", "upper", "lower", "capitalize", "items", "isoformat", "mimeformat", "day", "month", "year", "hour", "minute", "second", "microsecond", "weekday", "yearday"}: 
    20322030            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.{op.arg}(r{op.r2});".format(op=opcode)) 
    20332031        elif opcode.arg in {"r", "g", "b", "a"}: 
     
    20372035        elif opcode.arg == "lum": 
    20382036            self._do(u"r{op.r1} = ((com.livinglogic.ul4.Color)r{op.r2}).lum();".format(op=opcode)) 
     2037        elif opcode.arg == "render": 
     2038            self._do(u"r{op.r1} = ((com.livinglogic.ul4.Template)r{op.r2}).renders(null);".format(op=opcode)) 
    20392039        else: 
    20402040            raise UnknownMethodError(opcode.arg) 
    20412041        self._usereg(opcode.r1) 
    20422042    def _dispatch_callmeth1(self, opcode): 
    2043         if opcode.arg in {"split", "rsplit", "strip", "lstrip", "rstrip", "startswith", "endswith", "find", "rfind", "format", "withlum", "witha"}: 
     2043        if opcode.arg in {"join", "split", "rsplit", "strip", "lstrip", "rstrip", "startswith", "endswith", "find", "rfind", "format", "withlum", "witha"}: 
    20442044            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.{op.arg}(r{op.r2}, r{op.r3});".format(op=opcode)) 
    20452045        elif opcode.arg == "get": 
     
    20492049        self._usereg(opcode.r1) 
    20502050    def _dispatch_callmeth2(self, opcode): 
    2051         if opcode.arg in {"split", "rsplit", "find", "replace"}: 
     2051        if opcode.arg in {"split", "rsplit", "find", "rfind", "replace"}: 
    20522052            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.{op.arg}(r{op.r2}, r{op.r3}, r{op.r4});".format(op=opcode)) 
    20532053        elif opcode.arg == "get": 
     
    20572057        self._usereg(opcode.r1) 
    20582058    def _dispatch_callmeth3(self, opcode): 
    2059         if opcode.arg == "find": 
    2060             self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.find(r{op.r2}, r{op.r3}, r{op.r4}, r{op.r5});".format(op=opcode)) 
     2059        if opcode.arg in {"find", "rfind"}: 
     2060            self._do(u"r{op.r1} = com.livinglogic.ul4.Utils.{op.arg}(r{op.r2}, r{op.r3}, r{op.r4}, r{op.r5});".format(op=opcode)) 
    20612061        else: 
    20622062            raise UnknownMethodError(opcode.arg) 
     
    28072807        elif value is False: 
    28082808            return False_(start, end) 
    2809         elif isinstance(value, int): 
     2809        elif isinstance(value, (int, long)): 
    28102810            return Int(start, end, value) 
    28112811        elif isinstance(value, float): 
  • test/test_ul4.py

    r4319 r4321  
    239239    assert u'\xff' == r(u'<?print "\\xff"?>') 
    240240    assert u'\u20ac' == r(u'''<?print "\\u20ac"?>''') 
    241     assert "\\xxx" == r(u'<?print "\\xxx"?>') 
    242241    assert "a\nb" == r(u'<?print "a\nb"?>') 
    243242 
     
    446445@with_all_renderers 
    447446def test_add(r): 
    448     assert '42' == r(u'<?print 21+21?>') 
    449     assert '42' == r(u'<?code x=21?><?code y=21?><?print x+y?>') 
     447    values = (17, 23, 1., -1.) 
     448    for x in values: 
     449        for y in values: 
     450            assert x + y == eval(r(u'<?print x + y?>', x=x, y=y)) # Using ``eval`` avoid problem with the nonexistant int/float distinction in JS 
    450451    assert 'foobar' == r(u'<?code x="foo"?><?code y="bar"?><?print x+y?>') 
    451452    assert '(f)(o)(o)(b)(a)(r)' == r(u'<?for i in data.foo+data.bar?>(<?print i?>)<?end for?>', data=dict(foo="foo", bar="bar")) 
     
    454455@with_all_renderers 
    455456def test_sub(r): 
    456     assert '0' == r(u'<?print 21-21?>') 
    457     assert '0' == r(u'<?code x=21?><?code y=21?><?print x-y?>') 
     457    values = (17, 23, 1., -1.) 
     458    for x in values: 
     459        for y in values: 
     460            assert x - y == eval(r(u'<?print x - y?>', x=x, y=y)) 
    458461 
    459462 
    460463@with_all_renderers 
    461464def test_mul(r): 
    462     assert str(17*23) == r(u'<?print 17*23?>') 
    463     assert str(17*23) == r(u'<?code x=17?><?code y=23?><?print x*y?>') 
     465    values = (17, 23, 1., -1.) 
     466    for x in values: 
     467        for y in values: 
     468            assert x * y == eval(r(u'<?print x * y?>', x=x, y=y)) 
    464469    assert 17*"foo" == r(u'<?print 17*"foo"?>') 
    465470    assert 17*"foo" == r(u'<?code x=17?><?code y="foo"?><?print x*y?>') 
     
    483488@with_all_renderers 
    484489def test_mod(r): 
    485     assert str(42%17) == r(u'<?print 42%17?>') 
    486     assert str(42%17) == r(u'<?code x=42?><?code y=17?><?print x%y?>') 
     490    values = (17, 23, 17., 23.) 
     491    for x in values: 
     492        for y in values: 
     493            assert x % y == eval(r(u'<?print {} % {}?>'.format(x, y))) 
     494            assert x % y == eval(r(u'<?print x % y?>', x=x, y=y)) 
    487495 
    488496 
    489497@with_all_renderers 
    490498def test_eq(r): 
    491     assert "False" == r(u'<?print 17==23?>') 
    492     assert "True" == r(u'<?print 17==17?>') 
    493     assert "False" == r(u'<?print x==23?>', x=17) 
    494     assert "True" == r(u'<?print x==23?>', x=23) 
     499    values = (17, 23, 17., 23.) 
     500    for x in values: 
     501        for y in values: 
     502            assert str(x == y) == r(u'<?print {} == {}?>'.format(x, y)) 
     503            assert str(x == y) == r(u'<?print x == y?>', x=x, y=y) 
    495504 
    496505 
    497506@with_all_renderers 
    498507def test_ne(r): 
    499     assert "True" == r(u'<?print 17!=23?>') 
    500     assert "False" == r(u'<?print 17!=17?>') 
    501     assert "True" == r(u'<?print x!=23?>', x=17) 
    502     assert "False" == r(u'<?print x!=23?>', x=23) 
     508    values = (17, 23, 17., 23.) 
     509    for x in values: 
     510        for y in values: 
     511            assert str(x != y) == r(u'<?print {} != {}?>'.format(x, y)) 
     512            assert str(x != y) == r(u'<?print x != y?>', x=x, y=y) 
    503513 
    504514 
    505515@with_all_renderers 
    506516def test_lt(r): 
    507     assert "True" == r(u'<?print 1<2?>') 
    508     assert "False" == r(u'<?print 2<2?>') 
    509     assert "False" == r(u'<?print 3<2?>') 
    510     assert "True" == r(u'<?print x<2?>', x=1) 
    511     assert "False" == r(u'<?print x<2?>', x=2) 
    512     assert "False" == r(u'<?print x<2?>', x=3) 
     517    values = (17, 23, 17., 23.) 
     518    for x in values: 
     519        for y in values: 
     520            assert str(x < y) == r(u'<?print {} < {}?>'.format(x, y)) 
     521            assert str(x < y) == r(u'<?print x < y?>', x=x, y=y) 
    513522 
    514523 
    515524@with_all_renderers 
    516525def test_le(r): 
    517     assert "True" == r(u'<?print 1<=2?>') 
    518     assert "True" == r(u'<?print 2<=2?>') 
    519     assert "False" == r(u'<?print 3<=2?>') 
    520     assert "True" == r(u'<?print x<=2?>', x=1) 
    521     assert "True" == r(u'<?print x<=2?>', x=2) 
    522     assert "False" == r(u'<?print x<=2?>', x=3) 
     526    values = (17, 23, 17., 23.) 
     527    for x in values: 
     528        for y in values: 
     529            assert str(x <= y) == r(u'<?print {} <= {}?>'.format(x, y)) 
     530            assert str(x <= y) == r(u'<?print x <= y?>', x=x, y=y) 
    523531 
    524532 
    525533@with_all_renderers 
    526534def test_gt(r): 
    527     assert "False" == r(u'<?print 1>2?>') 
    528     assert "False" == r(u'<?print 2>2?>') 
    529     assert "True" == r(u'<?print 3>2?>') 
    530     assert "False" == r(u'<?print x>2?>', x=1) 
    531     assert "False" == r(u'<?print x>2?>', x=2) 
    532     assert "True" == r(u'<?print x>2?>', x=3) 
     535    values = (17, 23, 17., 23.) 
     536    for x in values: 
     537        for y in values: 
     538            assert str(x > y) == r(u'<?print {} > {}?>'.format(x, y)) 
     539            assert str(x > y) == r(u'<?print x > y?>', x=x, y=y) 
    533540 
    534541 
    535542@with_all_renderers 
    536543def test_ge(r): 
    537     assert "False" == r(u'<?print 1>=2?>') 
    538     assert "True" == r(u'<?print 2>=2?>') 
    539     assert "True" == r(u'<?print 3>=2?>') 
    540     assert "False" == r(u'<?print x>=2?>', x=1) 
    541     assert "True" == r(u'<?print x>=2?>', x=2) 
    542     assert "True" == r(u'<?print x>=2?>', x=3) 
     544    values = (17, 23, 17., 23.) 
     545    for x in values: 
     546        for y in values: 
     547            assert str(x >= y) == r(u'<?print {} >= {}?>'.format(x, y)) 
     548            assert str(x >= y) == r(u'<?print x >= y?>', x=x, y=y) 
    543549 
    544550 
     
    809815    with raises("int.*unknown"): 
    810816        r(u"<?print int(1, 2, 3)?>") 
    811     with raises("int\\(\\) argument must be a string or a number"): 
     817    with raises("int\\(\\) argument must be a string or a number|int\\(null\\) not supported"): 
    812818        r(u"<?print int(data)?>", data=None) 
    813     with raises("invalid literal for int"): 
     819    with raises("invalid literal for int|NumberFormatException"): 
    814820        r(u"<?print int(data)?>", data="foo") 
    815821    assert "1" == r(u"<?print int(data)?>", data=True) 
     
    829835    with raises("float.*unknown"): 
    830836        r(u"<?print float(1, 2, 3)?>") 
    831     with raises("float\\(\\) argument must be a string or a number|Can't convert null to a float"): 
     837    with raises("float\\(\\) argument must be a string or a number|float\\(null\\) not supported"): 
    832838        r(code, data=None) 
    833839    assert "4.2" == r(code, data=4.2) 
     
    851857    with raises("len.*unknown"): 
    852858        r(u"<?print len(1, 2)?>") 
    853     with raises("has no len\\(\\)"): 
     859    with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    854860        r(code, data=None) 
    855     with raises("has no len\\(\\)"): 
     861    with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    856862        r(code, data=True) 
    857     with raises("has no len\\(\\)"): 
     863    with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    858864        r(code, data=False) 
    859     with raises("has no len\\(\\)"): 
     865    with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    860866        r(code, data=42) 
    861     with raises("has no len\\(\\)"): 
     867    with raises("has no len\\(\\)|len\\(.*\\) not supported"): 
    862868        r(code, data=4.2) 
    863869    assert "42" == r(code, data=42*"?") 
     
    873879    with raises("enumerate.*unknown"): 
    874880        r(u"<?print enumerate(1, 2)?>") 
    875     with raises("is not iterable"): 
     881    with raises("is not iterable|iter\\(.*\\) not supported"): 
    876882        r(code, data=None) 
    877     with raises("is not iterable"): 
     883    with raises("is not iterable|iter\\(.*\\) not supported"): 
    878884        r(code, data=True) 
    879     with raises("is not iterable"): 
     885    with raises("is not iterable|iter\\(.*\\) not supported"): 
    880886        r(code, data=False) 
    881     with raises("is not iterable"): 
     887    with raises("is not iterable|iter\\(.*\\) not supported"): 
    882888        r(code, data=42) 
    883     with raises("is not iterable"): 
     889    with raises("is not iterable|iter\\(.*\\) not supported"): 
    884890        r(code, data=4.2) 
    885891    assert "0:f\n1:o\n2:o\n" == r(code, data="foo") 
     
    16001606 
    16011607    if r is not renderjs: 
    1602         msg = "TypeError .*render tmpl3.*render tmpl2.*render tmpl1.*print 2.*unsupported operand type" 
     1608        msg = "TypeError .*render tmpl3.*render tmpl2.*render tmpl1.*print 2.*unsupported operand type|.* \\* .* not supported" 
    16031609        with raises(msg): 
    16041610            r(u"<?render tmpl3(tmpl1=tmpl1, tmpl2=tmpl2, x=x)?>", tmpl1=tmpl1, tmpl2=tmpl2, tmpl3=tmpl3, x=None)