def test_single_backslash(self): for inp, exp in [ ('\\', ''), ('\\ ', ' '), ('a\\', 'a'), ('\\a', 'a'), ('a\\b\\c\\d', 'abcd') ]: assert_equals(unescape(inp), exp, inp)
def test_multiple_backslash(self): for inp, exp in [ ('\\\\', '\\'), ('\\\\\\', '\\'), ('\\\\\\\\', '\\\\'), ('x\\\\x', 'x\\x'), ('x\\\\\\x', 'x\\x'), ('x\\\\\\\\x', 'x\\\\x') ]: assert_equals(unescape(inp), exp, inp)
def test_tab(self): for inp, exp in [ ('\\t', '\t'), ('\\\\t', '\\t'), ('\\\\\\t', '\\\t'), ('\\t ', '\t '), ('\\\\t ', '\\t '), ('\\\\\\t ', '\\\t '), ('\\tx', '\tx'), ('\\\\tx', '\\tx'), ('\\\\\\tx', '\\\tx'), ('\\t x', '\t x'), ('\\\\t x', '\\t x'), ('\\\\\\t x', '\\\t x') ]: assert_equals(unescape(inp), exp, inp)
def test_cr(self): for inp, exp in [ ('\\r', '\r'), ('\\\\r', '\\r'), ('\\\\\\r', '\\\r'), ('\\r ', '\r '), ('\\\\r ', '\\r '), ('\\\\\\r ', '\\\r '), ('\\rx', '\rx'), ('\\\\rx', '\\rx'), ('\\\\\\rx', '\\\rx'), ('\\r x', '\r x'), ('\\\\r x', '\\r x'), ('\\\\\\r x', '\\\r x') ]: assert_equals(unescape(inp), exp, inp)
def test_lf(self): for inp, exp in [ ('\\n', '\n'), ('\\\\n', '\\n'), ('\\\\\\n', '\\\n'), ('\\n ', '\n'), ('\\\\n ', '\\n '), ('\\\\\\n ', '\\\n'), ('\\nx', '\nx'), ('\\\\nx', '\\nx'), ('\\\\\\nx', '\\\nx'), ('\\n x', '\nx'), ('\\\\n x', '\\n x'), ('\\\\\\n x', '\\\nx') ]: assert_equals(unescape(inp), exp, "'%s'" % inp)
def assert_unescape(inp, exp): assert_equals(unescape(inp), exp, repr(inp))
def test_no_unescape(self): for inp in [ 'no escapes', '' ]: assert_equals(unescape(inp), inp)