MCPcopy Create free account
hub / github.com/simplejson/simplejson / TestScanString

Class TestScanString

simplejson/tests/test_scanstring.py:8–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6from simplejson.compat import b, PY3
7
8class TestScanString(TestCase):
9 # The bytes type is intentionally not used in most of these tests
10 # under Python 3 because the decoder immediately coerces to str before
11 # calling scanstring. In Python 2 we are testing the code paths
12 # for both unicode and str.
13 #
14 # The reason this is done is because Python 3 would require
15 # entirely different code paths for parsing bytes and str.
16 #
17 def test_py_scanstring(self):
18 self._test_scanstring(simplejson.decoder.py_scanstring)
19
20 def test_c_scanstring(self):
21 if not simplejson.decoder.c_scanstring:
22 return
23 self._test_scanstring(simplejson.decoder.c_scanstring)
24
25 self.assertTrue(isinstance(simplejson.decoder.c_scanstring('""', 0)[0], str))
26
27 def _test_scanstring(self, scanstring):
28 if sys.maxunicode == 65535:
29 self.assertEqual(
30 scanstring(u'"z\U0001d120x"', 1, None, True),
31 (u'z\U0001d120x', 6))
32 else:
33 self.assertEqual(
34 scanstring(u'"z\U0001d120x"', 1, None, True),
35 (u'z\U0001d120x', 5))
36
37 self.assertEqual(
38 scanstring('"\\u007b"', 1, None, True),
39 (u'{', 8))
40
41 self.assertEqual(
42 scanstring('"A JSON payload should be an object or array, not a string."', 1, None, True),
43 (u'A JSON payload should be an object or array, not a string.', 60))
44
45 self.assertEqual(
46 scanstring('["Unclosed array"', 2, None, True),
47 (u'Unclosed array', 17))
48
49 self.assertEqual(
50 scanstring('["extra comma",]', 2, None, True),
51 (u'extra comma', 14))
52
53 self.assertEqual(
54 scanstring('["double extra comma",,]', 2, None, True),
55 (u'double extra comma', 21))
56
57 self.assertEqual(
58 scanstring('["Comma after the close"],', 2, None, True),
59 (u'Comma after the close', 24))
60
61 self.assertEqual(
62 scanstring('["Extra close"]]', 2, None, True),
63 (u'Extra close', 14))
64
65 self.assertEqual(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…