Changeset 4340:c8c62d8675cb in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/15/11 11:15:57 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Simplify codepoint test in misc.javaexpr(). Add tests.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/ll/misc.py

    r4338 r4340  
    522522            except KeyError: 
    523523                oc = ord(c) 
    524                 v.append(u"\\u{:04x}".format(oc) if oc >= 128 or oc <= 31 else c) 
     524                v.append(c if 32 <= oc < 128 else u"\\u{:04x}".format(oc)) 
    525525        return u'"{}"'.format(u"".join(v)) 
    526526    elif isinstance(obj, datetime.datetime): # check ``datetime`` before ``date``, as ``datetime`` is a subclass of ``date`` 
  • test/test_misc.py

    r4319 r4340  
    276276    assert '"\'"' == misc.javaexpr("'") 
    277277    assert '"\\n"' == misc.javaexpr("\n") 
     278    assert '"\\r"' == misc.javaexpr("\r") 
     279    assert '"\\t"' == misc.javaexpr("\t") 
     280    assert '"\\f"' == misc.javaexpr("\f") 
     281    assert '"\\b"' == misc.javaexpr("\b") 
    278282    assert '"\\""' == misc.javaexpr('"') 
     283    assert '"\\u0000"' == misc.javaexpr("\x00") 
    279284    assert '"\\u00ff"' == misc.javaexpr(u"\xff") 
    280285    assert '"\\u20ac"' == misc.javaexpr(u"\u20ac")