Fix localization.
[clinton/xbmc-groove.git] / resources / lib / simplejson / tests / test_scanstring.py
CommitLineData
8817bb2e 1import sys
8817bb2e 2from unittest import TestCase
3
4import simplejson as json
5import simplejson.decoder
6
7class 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")