pygments.rb 0.2.13 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +1 -0
  2. data/README.md +45 -19
  3. data/Rakefile +21 -11
  4. data/bench.rb +15 -48
  5. data/cache-lexers.rb +8 -0
  6. data/lexers +0 -0
  7. data/lib/pygments.rb +3 -6
  8. data/lib/pygments/mentos.py +343 -0
  9. data/lib/pygments/popen.rb +383 -0
  10. data/lib/pygments/version.rb +1 -1
  11. data/pygments.rb.gemspec +5 -4
  12. data/test/test_data.c +2581 -0
  13. data/test/test_data.py +514 -0
  14. data/test/test_data_generated +2582 -0
  15. data/test/test_pygments.rb +208 -84
  16. data/vendor/pygments-main/pygments/lexers/_mapping.py +1 -1
  17. data/vendor/pygments-main/pygments/lexers/shell.py +1 -1
  18. data/vendor/simplejson/.gitignore +10 -0
  19. data/vendor/simplejson/.travis.yml +5 -0
  20. data/vendor/simplejson/CHANGES.txt +291 -0
  21. data/vendor/simplejson/LICENSE.txt +19 -0
  22. data/vendor/simplejson/MANIFEST.in +5 -0
  23. data/vendor/simplejson/README.rst +19 -0
  24. data/vendor/simplejson/conf.py +179 -0
  25. data/vendor/simplejson/index.rst +628 -0
  26. data/vendor/simplejson/scripts/make_docs.py +18 -0
  27. data/vendor/simplejson/setup.py +104 -0
  28. data/vendor/simplejson/simplejson/__init__.py +510 -0
  29. data/vendor/simplejson/simplejson/_speedups.c +2745 -0
  30. data/vendor/simplejson/simplejson/decoder.py +425 -0
  31. data/vendor/simplejson/simplejson/encoder.py +567 -0
  32. data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
  33. data/vendor/simplejson/simplejson/scanner.py +77 -0
  34. data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
  35. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
  36. data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
  37. data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
  38. data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
  39. data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
  40. data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
  41. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
  42. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
  43. data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
  44. data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
  45. data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
  46. data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
  47. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
  48. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
  49. data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
  50. data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
  51. data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
  52. data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
  53. data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
  54. data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
  55. data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
  56. data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
  57. data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
  58. data/vendor/simplejson/simplejson/tool.py +39 -0
  59. metadata +80 -22
  60. data/ext/extconf.rb +0 -14
  61. data/ext/pygments.c +0 -466
  62. data/lib/pygments/c.rb +0 -54
  63. data/lib/pygments/ffi.rb +0 -155
  64. data/vendor/.gitignore +0 -1
@@ -0,0 +1,76 @@
1
+ from unittest import TestCase
2
+
3
+ import simplejson as json
4
+
5
+ # from http://json.org/JSON_checker/test/pass1.json
6
+ JSON = r'''
7
+ [
8
+ "JSON Test Pattern pass1",
9
+ {"object with 1 member":["array with 1 element"]},
10
+ {},
11
+ [],
12
+ -42,
13
+ true,
14
+ false,
15
+ null,
16
+ {
17
+ "integer": 1234567890,
18
+ "real": -9876.543210,
19
+ "e": 0.123456789e-12,
20
+ "E": 1.234567890E+34,
21
+ "": 23456789012E666,
22
+ "zero": 0,
23
+ "one": 1,
24
+ "space": " ",
25
+ "quote": "\"",
26
+ "backslash": "\\",
27
+ "controls": "\b\f\n\r\t",
28
+ "slash": "/ & \/",
29
+ "alpha": "abcdefghijklmnopqrstuvwyz",
30
+ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
31
+ "digit": "0123456789",
32
+ "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
33
+ "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
34
+ "true": true,
35
+ "false": false,
36
+ "null": null,
37
+ "array":[ ],
38
+ "object":{ },
39
+ "address": "50 St. James Street",
40
+ "url": "http://www.JSON.org/",
41
+ "comment": "// /* <!-- --",
42
+ "# -- --> */": " ",
43
+ " s p a c e d " :[1,2 , 3
44
+
45
+ ,
46
+
47
+ 4 , 5 , 6 ,7 ],
48
+ "compact": [1,2,3,4,5,6,7],
49
+ "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
50
+ "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
51
+ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
52
+ : "A key can be any string"
53
+ },
54
+ 0.5 ,98.6
55
+ ,
56
+ 99.44
57
+ ,
58
+
59
+ 1066
60
+
61
+
62
+ ,"rosebud"]
63
+ '''
64
+
65
+ class TestPass1(TestCase):
66
+ def test_parse(self):
67
+ # test in/out equivalence and parsing
68
+ res = json.loads(JSON)
69
+ out = json.dumps(res)
70
+ self.assertEquals(res, json.loads(out))
71
+ try:
72
+ json.dumps(res, allow_nan=False)
73
+ except ValueError:
74
+ pass
75
+ else:
76
+ self.fail("23456789012E666 should be out of range")
@@ -0,0 +1,14 @@
1
+ from unittest import TestCase
2
+ import simplejson as json
3
+
4
+ # from http://json.org/JSON_checker/test/pass2.json
5
+ JSON = r'''
6
+ [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
7
+ '''
8
+
9
+ class TestPass2(TestCase):
10
+ def test_parse(self):
11
+ # test in/out equivalence and parsing
12
+ res = json.loads(JSON)
13
+ out = json.dumps(res)
14
+ self.assertEquals(res, json.loads(out))
@@ -0,0 +1,20 @@
1
+ from unittest import TestCase
2
+
3
+ import simplejson as json
4
+
5
+ # from http://json.org/JSON_checker/test/pass3.json
6
+ JSON = r'''
7
+ {
8
+ "JSON Test Pattern pass3": {
9
+ "The outermost value": "must be an object or array.",
10
+ "In this test": "It is an object."
11
+ }
12
+ }
13
+ '''
14
+
15
+ class TestPass3(TestCase):
16
+ def test_parse(self):
17
+ # test in/out equivalence and parsing
18
+ res = json.loads(JSON)
19
+ out = json.dumps(res)
20
+ self.assertEquals(res, json.loads(out))
@@ -0,0 +1,67 @@
1
+ from unittest import TestCase
2
+
3
+ import simplejson as json
4
+
5
+ class JSONTestObject:
6
+ pass
7
+
8
+
9
+ class RecursiveJSONEncoder(json.JSONEncoder):
10
+ recurse = False
11
+ def default(self, o):
12
+ if o is JSONTestObject:
13
+ if self.recurse:
14
+ return [JSONTestObject]
15
+ else:
16
+ return 'JSONTestObject'
17
+ return json.JSONEncoder.default(o)
18
+
19
+
20
+ class TestRecursion(TestCase):
21
+ def test_listrecursion(self):
22
+ x = []
23
+ x.append(x)
24
+ try:
25
+ json.dumps(x)
26
+ except ValueError:
27
+ pass
28
+ else:
29
+ self.fail("didn't raise ValueError on list recursion")
30
+ x = []
31
+ y = [x]
32
+ x.append(y)
33
+ try:
34
+ json.dumps(x)
35
+ except ValueError:
36
+ pass
37
+ else:
38
+ self.fail("didn't raise ValueError on alternating list recursion")
39
+ y = []
40
+ x = [y, y]
41
+ # ensure that the marker is cleared
42
+ json.dumps(x)
43
+
44
+ def test_dictrecursion(self):
45
+ x = {}
46
+ x["test"] = x
47
+ try:
48
+ json.dumps(x)
49
+ except ValueError:
50
+ pass
51
+ else:
52
+ self.fail("didn't raise ValueError on dict recursion")
53
+ x = {}
54
+ y = {"a": x, "b": x}
55
+ # ensure that the marker is cleared
56
+ json.dumps(y)
57
+
58
+ def test_defaultrecursion(self):
59
+ enc = RecursiveJSONEncoder()
60
+ self.assertEquals(enc.encode(JSONTestObject), '"JSONTestObject"')
61
+ enc.recurse = True
62
+ try:
63
+ enc.encode(JSONTestObject)
64
+ except ValueError:
65
+ pass
66
+ else:
67
+ self.fail("didn't raise ValueError on default recursion")
@@ -0,0 +1,117 @@
1
+ import sys
2
+ from unittest import TestCase
3
+
4
+ import simplejson as json
5
+ import simplejson.decoder
6
+
7
+ class TestScanString(TestCase):
8
+ def test_py_scanstring(self):
9
+ self._test_scanstring(simplejson.decoder.py_scanstring)
10
+
11
+ def test_c_scanstring(self):
12
+ if not simplejson.decoder.c_scanstring:
13
+ return
14
+ self._test_scanstring(simplejson.decoder.c_scanstring)
15
+
16
+ def _test_scanstring(self, scanstring):
17
+ self.assertEquals(
18
+ scanstring('"z\\ud834\\udd20x"', 1, None, True),
19
+ (u'z\U0001d120x', 16))
20
+
21
+ if sys.maxunicode == 65535:
22
+ self.assertEquals(
23
+ scanstring(u'"z\U0001d120x"', 1, None, True),
24
+ (u'z\U0001d120x', 6))
25
+ else:
26
+ self.assertEquals(
27
+ scanstring(u'"z\U0001d120x"', 1, None, True),
28
+ (u'z\U0001d120x', 5))
29
+
30
+ self.assertEquals(
31
+ scanstring('"\\u007b"', 1, None, True),
32
+ (u'{', 8))
33
+
34
+ self.assertEquals(
35
+ scanstring('"A JSON payload should be an object or array, not a string."', 1, None, True),
36
+ (u'A JSON payload should be an object or array, not a string.', 60))
37
+
38
+ self.assertEquals(
39
+ scanstring('["Unclosed array"', 2, None, True),
40
+ (u'Unclosed array', 17))
41
+
42
+ self.assertEquals(
43
+ scanstring('["extra comma",]', 2, None, True),
44
+ (u'extra comma', 14))
45
+
46
+ self.assertEquals(
47
+ scanstring('["double extra comma",,]', 2, None, True),
48
+ (u'double extra comma', 21))
49
+
50
+ self.assertEquals(
51
+ scanstring('["Comma after the close"],', 2, None, True),
52
+ (u'Comma after the close', 24))
53
+
54
+ self.assertEquals(
55
+ scanstring('["Extra close"]]', 2, None, True),
56
+ (u'Extra close', 14))
57
+
58
+ self.assertEquals(
59
+ scanstring('{"Extra comma": true,}', 2, None, True),
60
+ (u'Extra comma', 14))
61
+
62
+ self.assertEquals(
63
+ scanstring('{"Extra value after close": true} "misplaced quoted value"', 2, None, True),
64
+ (u'Extra value after close', 26))
65
+
66
+ self.assertEquals(
67
+ scanstring('{"Illegal expression": 1 + 2}', 2, None, True),
68
+ (u'Illegal expression', 21))
69
+
70
+ self.assertEquals(
71
+ scanstring('{"Illegal invocation": alert()}', 2, None, True),
72
+ (u'Illegal invocation', 21))
73
+
74
+ self.assertEquals(
75
+ scanstring('{"Numbers cannot have leading zeroes": 013}', 2, None, True),
76
+ (u'Numbers cannot have leading zeroes', 37))
77
+
78
+ self.assertEquals(
79
+ scanstring('{"Numbers cannot be hex": 0x14}', 2, None, True),
80
+ (u'Numbers cannot be hex', 24))
81
+
82
+ self.assertEquals(
83
+ scanstring('[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]', 21, None, True),
84
+ (u'Too deep', 30))
85
+
86
+ self.assertEquals(
87
+ scanstring('{"Missing colon" null}', 2, None, True),
88
+ (u'Missing colon', 16))
89
+
90
+ self.assertEquals(
91
+ scanstring('{"Double colon":: null}', 2, None, True),
92
+ (u'Double colon', 15))
93
+
94
+ self.assertEquals(
95
+ scanstring('{"Comma instead of colon", null}', 2, None, True),
96
+ (u'Comma instead of colon', 25))
97
+
98
+ self.assertEquals(
99
+ scanstring('["Colon instead of comma": false]', 2, None, True),
100
+ (u'Colon instead of comma', 25))
101
+
102
+ self.assertEquals(
103
+ scanstring('["Bad value", truth]', 2, None, True),
104
+ (u'Bad value', 12))
105
+
106
+ def test_issue3623(self):
107
+ self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
108
+ "xxx")
109
+ self.assertRaises(UnicodeDecodeError,
110
+ json.encoder.encode_basestring_ascii, "xx\xff")
111
+
112
+ def test_overflow(self):
113
+ # Python 2.5 does not have maxsize
114
+ maxsize = getattr(sys, 'maxsize', sys.maxint)
115
+ self.assertRaises(OverflowError, json.decoder.scanstring, "xxx",
116
+ maxsize + 1)
117
+
@@ -0,0 +1,42 @@
1
+ import textwrap
2
+ from unittest import TestCase
3
+
4
+ import simplejson as json
5
+
6
+
7
+ class TestSeparators(TestCase):
8
+ def test_separators(self):
9
+ h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
10
+ {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
11
+
12
+ expect = textwrap.dedent("""\
13
+ [
14
+ [
15
+ "blorpie"
16
+ ] ,
17
+ [
18
+ "whoops"
19
+ ] ,
20
+ [] ,
21
+ "d-shtaeou" ,
22
+ "d-nthiouh" ,
23
+ "i-vhbjkhnth" ,
24
+ {
25
+ "nifty" : 87
26
+ } ,
27
+ {
28
+ "field" : "yes" ,
29
+ "morefield" : false
30
+ }
31
+ ]""")
32
+
33
+
34
+ d1 = json.dumps(h)
35
+ d2 = json.dumps(h, indent=' ', sort_keys=True, separators=(' ,', ' : '))
36
+
37
+ h1 = json.loads(d1)
38
+ h2 = json.loads(d2)
39
+
40
+ self.assertEquals(h1, h)
41
+ self.assertEquals(h2, h)
42
+ self.assertEquals(d2, expect)
@@ -0,0 +1,20 @@
1
+ from unittest import TestCase
2
+
3
+ from simplejson import encoder, scanner
4
+
5
+ def has_speedups():
6
+ return encoder.c_make_encoder is not None
7
+
8
+ class TestDecode(TestCase):
9
+ def test_make_scanner(self):
10
+ if not has_speedups():
11
+ return
12
+ self.assertRaises(AttributeError, scanner.c_make_scanner, 1)
13
+
14
+ def test_make_encoder(self):
15
+ if not has_speedups():
16
+ return
17
+ self.assertRaises(TypeError, encoder.c_make_encoder,
18
+ None,
19
+ "\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
20
+ None)
@@ -0,0 +1,49 @@
1
+ import unittest
2
+ from StringIO import StringIO
3
+
4
+ import simplejson as json
5
+
6
+ class TestTuples(unittest.TestCase):
7
+ def test_tuple_array_dumps(self):
8
+ t = (1, 2, 3)
9
+ expect = json.dumps(list(t))
10
+ # Default is True
11
+ self.assertEqual(expect, json.dumps(t))
12
+ self.assertEqual(expect, json.dumps(t, tuple_as_array=True))
13
+ self.assertRaises(TypeError, json.dumps, t, tuple_as_array=False)
14
+ # Ensure that the "default" does not get called
15
+ self.assertEqual(expect, json.dumps(t, default=repr))
16
+ self.assertEqual(expect, json.dumps(t, tuple_as_array=True, default=repr))
17
+ # Ensure that the "default" gets called
18
+ self.assertEqual(
19
+ json.dumps(repr(t)),
20
+ json.dumps(t, tuple_as_array=False, default=repr))
21
+
22
+ def test_tuple_array_dump(self):
23
+ t = (1, 2, 3)
24
+ expect = json.dumps(list(t))
25
+ # Default is True
26
+ sio = StringIO()
27
+ json.dump(t, sio)
28
+ self.assertEqual(expect, sio.getvalue())
29
+ sio = StringIO()
30
+ json.dump(t, sio, tuple_as_array=True)
31
+ self.assertEqual(expect, sio.getvalue())
32
+ self.assertRaises(TypeError, json.dump, t, StringIO(), tuple_as_array=False)
33
+ # Ensure that the "default" does not get called
34
+ sio = StringIO()
35
+ json.dump(t, sio, default=repr)
36
+ self.assertEqual(expect, sio.getvalue())
37
+ sio = StringIO()
38
+ json.dump(t, sio, tuple_as_array=True, default=repr)
39
+ self.assertEqual(expect, sio.getvalue())
40
+ # Ensure that the "default" gets called
41
+ sio = StringIO()
42
+ json.dump(t, sio, tuple_as_array=False, default=repr)
43
+ self.assertEqual(
44
+ json.dumps(repr(t)),
45
+ sio.getvalue())
46
+
47
+ class TestNamedTuple(unittest.TestCase):
48
+ def test_namedtuple_dump(self):
49
+ pass
@@ -0,0 +1,109 @@
1
+ from unittest import TestCase
2
+
3
+ import simplejson as json
4
+
5
+ class TestUnicode(TestCase):
6
+ def test_encoding1(self):
7
+ encoder = json.JSONEncoder(encoding='utf-8')
8
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
9
+ s = u.encode('utf-8')
10
+ ju = encoder.encode(u)
11
+ js = encoder.encode(s)
12
+ self.assertEquals(ju, js)
13
+
14
+ def test_encoding2(self):
15
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
16
+ s = u.encode('utf-8')
17
+ ju = json.dumps(u, encoding='utf-8')
18
+ js = json.dumps(s, encoding='utf-8')
19
+ self.assertEquals(ju, js)
20
+
21
+ def test_encoding3(self):
22
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
23
+ j = json.dumps(u)
24
+ self.assertEquals(j, '"\\u03b1\\u03a9"')
25
+
26
+ def test_encoding4(self):
27
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
28
+ j = json.dumps([u])
29
+ self.assertEquals(j, '["\\u03b1\\u03a9"]')
30
+
31
+ def test_encoding5(self):
32
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
33
+ j = json.dumps(u, ensure_ascii=False)
34
+ self.assertEquals(j, u'"' + u + u'"')
35
+
36
+ def test_encoding6(self):
37
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
38
+ j = json.dumps([u], ensure_ascii=False)
39
+ self.assertEquals(j, u'["' + u + u'"]')
40
+
41
+ def test_big_unicode_encode(self):
42
+ u = u'\U0001d120'
43
+ self.assertEquals(json.dumps(u), '"\\ud834\\udd20"')
44
+ self.assertEquals(json.dumps(u, ensure_ascii=False), u'"\U0001d120"')
45
+
46
+ def test_big_unicode_decode(self):
47
+ u = u'z\U0001d120x'
48
+ self.assertEquals(json.loads('"' + u + '"'), u)
49
+ self.assertEquals(json.loads('"z\\ud834\\udd20x"'), u)
50
+
51
+ def test_unicode_decode(self):
52
+ for i in range(0, 0xd7ff):
53
+ u = unichr(i)
54
+ #s = '"\\u{0:04x}"'.format(i)
55
+ s = '"\\u%04x"' % (i,)
56
+ self.assertEquals(json.loads(s), u)
57
+
58
+ def test_object_pairs_hook_with_unicode(self):
59
+ s = u'{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
60
+ p = [(u"xkd", 1), (u"kcw", 2), (u"art", 3), (u"hxm", 4),
61
+ (u"qrt", 5), (u"pad", 6), (u"hoy", 7)]
62
+ self.assertEqual(json.loads(s), eval(s))
63
+ self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
64
+ od = json.loads(s, object_pairs_hook=json.OrderedDict)
65
+ self.assertEqual(od, json.OrderedDict(p))
66
+ self.assertEqual(type(od), json.OrderedDict)
67
+ # the object_pairs_hook takes priority over the object_hook
68
+ self.assertEqual(json.loads(s,
69
+ object_pairs_hook=json.OrderedDict,
70
+ object_hook=lambda x: None),
71
+ json.OrderedDict(p))
72
+
73
+
74
+ def test_default_encoding(self):
75
+ self.assertEquals(json.loads(u'{"a": "\xe9"}'.encode('utf-8')),
76
+ {'a': u'\xe9'})
77
+
78
+ def test_unicode_preservation(self):
79
+ self.assertEquals(type(json.loads(u'""')), unicode)
80
+ self.assertEquals(type(json.loads(u'"a"')), unicode)
81
+ self.assertEquals(type(json.loads(u'["a"]')[0]), unicode)
82
+
83
+ def test_ensure_ascii_false_returns_unicode(self):
84
+ # http://code.google.com/p/simplejson/issues/detail?id=48
85
+ self.assertEquals(type(json.dumps([], ensure_ascii=False)), unicode)
86
+ self.assertEquals(type(json.dumps(0, ensure_ascii=False)), unicode)
87
+ self.assertEquals(type(json.dumps({}, ensure_ascii=False)), unicode)
88
+ self.assertEquals(type(json.dumps("", ensure_ascii=False)), unicode)
89
+
90
+ def test_ensure_ascii_false_bytestring_encoding(self):
91
+ # http://code.google.com/p/simplejson/issues/detail?id=48
92
+ doc1 = {u'quux': 'Arr\xc3\xaat sur images'}
93
+ doc2 = {u'quux': u'Arr\xeat sur images'}
94
+ doc_ascii = '{"quux": "Arr\\u00eat sur images"}'
95
+ doc_unicode = u'{"quux": "Arr\xeat sur images"}'
96
+ self.assertEquals(json.dumps(doc1), doc_ascii)
97
+ self.assertEquals(json.dumps(doc2), doc_ascii)
98
+ self.assertEquals(json.dumps(doc1, ensure_ascii=False), doc_unicode)
99
+ self.assertEquals(json.dumps(doc2, ensure_ascii=False), doc_unicode)
100
+
101
+ def test_ensure_ascii_linebreak_encoding(self):
102
+ # http://timelessrepo.com/json-isnt-a-javascript-subset
103
+ s1 = u'\u2029\u2028'
104
+ s2 = s1.encode('utf8')
105
+ expect = '"\\u2029\\u2028"'
106
+ self.assertEquals(json.dumps(s1), expect)
107
+ self.assertEquals(json.dumps(s2), expect)
108
+ self.assertEquals(json.dumps(s1, ensure_ascii=False), expect)
109
+ self.assertEquals(json.dumps(s2, ensure_ascii=False), expect)