PageRenderTime 342ms CodeModel.GetById 90ms app.highlight 5ms RepoModel.GetById 167ms app.codeStats 0ms

/Lib/json/tests/test_encode_basestring_ascii.py

http://unladen-swallow.googlecode.com/
Python | 35 lines | 30 code | 5 blank | 0 comment | 2 complexity | a87549d76fc7646bade74465a21cea20 MD5 | raw file
 1from unittest import TestCase
 2
 3import json.encoder
 4
 5CASES = [
 6    (u'/\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\x08\x0c\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?', '"/\\\\\\"\\ucafe\\ubabe\\uab98\\ufcde\\ubcda\\uef4a\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"'),
 7    (u'\u0123\u4567\u89ab\ucdef\uabcd\uef4a', '"\\u0123\\u4567\\u89ab\\ucdef\\uabcd\\uef4a"'),
 8    (u'controls', '"controls"'),
 9    (u'\x08\x0c\n\r\t', '"\\b\\f\\n\\r\\t"'),
10    (u'{"object with 1 member":["array with 1 element"]}', '"{\\"object with 1 member\\":[\\"array with 1 element\\"]}"'),
11    (u' s p a c e d ', '" s p a c e d "'),
12    (u'\U0001d120', '"\\ud834\\udd20"'),
13    (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
14    ('\xce\xb1\xce\xa9', '"\\u03b1\\u03a9"'),
15    (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
16    ('\xce\xb1\xce\xa9', '"\\u03b1\\u03a9"'),
17    (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
18    (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
19    (u"`1~!@#$%^&*()_+-={':[,]}|;.</>?", '"`1~!@#$%^&*()_+-={\':[,]}|;.</>?"'),
20    (u'\x08\x0c\n\r\t', '"\\b\\f\\n\\r\\t"'),
21    (u'\u0123\u4567\u89ab\ucdef\uabcd\uef4a', '"\\u0123\\u4567\\u89ab\\ucdef\\uabcd\\uef4a"'),
22]
23
24class TestEncodeBaseStringAscii(TestCase):
25    def test_py_encode_basestring_ascii(self):
26        self._test_encode_basestring_ascii(json.encoder.py_encode_basestring_ascii)
27
28    def test_c_encode_basestring_ascii(self):
29        self._test_encode_basestring_ascii(json.encoder.c_encode_basestring_ascii)
30
31    def _test_encode_basestring_ascii(self, encode_basestring_ascii):
32        fname = encode_basestring_ascii.__name__
33        for input_string, expect in CASES:
34            result = encode_basestring_ascii(input_string)
35            self.assertEquals(result, expect)