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

Method _test_scanstring

simplejson/tests/test_scanstring.py:27–137  ·  view source on GitHub ↗
(self, scanstring)

Source from the content-addressed store, hash-verified

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(
66 scanstring('{"Extra comma": true,}', 2, None, True),
67 (u'Extra comma', 14))
68
69 self.assertEqual(
70 scanstring('{"Extra value after close": true} "misplaced quoted value"', 2, None, True),
71 (u'Extra value after close', 26))
72
73 self.assertEqual(
74 scanstring('{"Illegal expression": 1 + 2}', 2, None, True),
75 (u'Illegal expression', 21))
76
77 self.assertEqual(
78 scanstring('{"Illegal invocation": alert()}', 2, None, True),
79 (u'Illegal invocation', 21))
80
81 self.assertEqual(
82 scanstring('{"Numbers cannot have leading zeroes": 013}', 2, None, True),
83 (u'Numbers cannot have leading zeroes', 37))
84

Callers 2

test_py_scanstringMethod · 0.95
test_c_scanstringMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected