gecko/python/simplejson-2.1.1/simplejson/tests/test_scanstring.py
Gregory Szorc 944423d6ec Bug 777068 - Move simplejson to python/; r=glandium
--HG--
rename : other-licenses/simplejson-2.1.1/CHANGES.txt => python/simplejson-2.1.1/CHANGES.txt
rename : other-licenses/simplejson-2.1.1/LICENSE.txt => python/simplejson-2.1.1/LICENSE.txt
rename : other-licenses/simplejson-2.1.1/PKG-INFO => python/simplejson-2.1.1/PKG-INFO
rename : other-licenses/simplejson-2.1.1/conf.py => python/simplejson-2.1.1/conf.py
rename : other-licenses/simplejson-2.1.1/docs/_sources/index.txt => python/simplejson-2.1.1/docs/_sources/index.txt
rename : other-licenses/simplejson-2.1.1/docs/_static/contents.png => python/simplejson-2.1.1/docs/_static/contents.png
rename : other-licenses/simplejson-2.1.1/docs/_static/default.css => python/simplejson-2.1.1/docs/_static/default.css
rename : other-licenses/simplejson-2.1.1/docs/_static/doctools.js => python/simplejson-2.1.1/docs/_static/doctools.js
rename : other-licenses/simplejson-2.1.1/docs/_static/file.png => python/simplejson-2.1.1/docs/_static/file.png
rename : other-licenses/simplejson-2.1.1/docs/_static/interface.js => python/simplejson-2.1.1/docs/_static/interface.js
rename : other-licenses/simplejson-2.1.1/docs/_static/jquery.js => python/simplejson-2.1.1/docs/_static/jquery.js
rename : other-licenses/simplejson-2.1.1/docs/_static/minus.png => python/simplejson-2.1.1/docs/_static/minus.png
rename : other-licenses/simplejson-2.1.1/docs/_static/navigation.png => python/simplejson-2.1.1/docs/_static/navigation.png
rename : other-licenses/simplejson-2.1.1/docs/_static/plus.png => python/simplejson-2.1.1/docs/_static/plus.png
rename : other-licenses/simplejson-2.1.1/docs/_static/pygments.css => python/simplejson-2.1.1/docs/_static/pygments.css
rename : other-licenses/simplejson-2.1.1/docs/_static/rightsidebar.css => python/simplejson-2.1.1/docs/_static/rightsidebar.css
rename : other-licenses/simplejson-2.1.1/docs/_static/searchtools.js => python/simplejson-2.1.1/docs/_static/searchtools.js
rename : other-licenses/simplejson-2.1.1/docs/_static/sphinxdoc.css => python/simplejson-2.1.1/docs/_static/sphinxdoc.css
rename : other-licenses/simplejson-2.1.1/docs/_static/stickysidebar.css => python/simplejson-2.1.1/docs/_static/stickysidebar.css
rename : other-licenses/simplejson-2.1.1/docs/_static/traditional.css => python/simplejson-2.1.1/docs/_static/traditional.css
rename : other-licenses/simplejson-2.1.1/docs/genindex.html => python/simplejson-2.1.1/docs/genindex.html
rename : other-licenses/simplejson-2.1.1/docs/index.html => python/simplejson-2.1.1/docs/index.html
rename : other-licenses/simplejson-2.1.1/docs/objects.inv => python/simplejson-2.1.1/docs/objects.inv
rename : other-licenses/simplejson-2.1.1/docs/search.html => python/simplejson-2.1.1/docs/search.html
rename : other-licenses/simplejson-2.1.1/docs/searchindex.js => python/simplejson-2.1.1/docs/searchindex.js
rename : other-licenses/simplejson-2.1.1/docs/searchindex.json => python/simplejson-2.1.1/docs/searchindex.json
rename : other-licenses/simplejson-2.1.1/ez_setup.py => python/simplejson-2.1.1/ez_setup.py
rename : other-licenses/simplejson-2.1.1/index.rst => python/simplejson-2.1.1/index.rst
rename : other-licenses/simplejson-2.1.1/scripts/make_docs.py => python/simplejson-2.1.1/scripts/make_docs.py
rename : other-licenses/simplejson-2.1.1/setup.cfg => python/simplejson-2.1.1/setup.cfg
rename : other-licenses/simplejson-2.1.1/setup.py => python/simplejson-2.1.1/setup.py
rename : other-licenses/simplejson-2.1.1/simplejson/__init__.py => python/simplejson-2.1.1/simplejson/__init__.py
rename : other-licenses/simplejson-2.1.1/simplejson/_speedups.c => python/simplejson-2.1.1/simplejson/_speedups.c
rename : other-licenses/simplejson-2.1.1/simplejson/decoder.py => python/simplejson-2.1.1/simplejson/decoder.py
rename : other-licenses/simplejson-2.1.1/simplejson/encoder.py => python/simplejson-2.1.1/simplejson/encoder.py
rename : other-licenses/simplejson-2.1.1/simplejson/ordered_dict.py => python/simplejson-2.1.1/simplejson/ordered_dict.py
rename : other-licenses/simplejson-2.1.1/simplejson/scanner.py => python/simplejson-2.1.1/simplejson/scanner.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/__init__.py => python/simplejson-2.1.1/simplejson/tests/__init__.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_check_circular.py => python/simplejson-2.1.1/simplejson/tests/test_check_circular.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_decimal.py => python/simplejson-2.1.1/simplejson/tests/test_decimal.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_decode.py => python/simplejson-2.1.1/simplejson/tests/test_decode.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_default.py => python/simplejson-2.1.1/simplejson/tests/test_default.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_dump.py => python/simplejson-2.1.1/simplejson/tests/test_dump.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_encode_basestring_ascii.py => python/simplejson-2.1.1/simplejson/tests/test_encode_basestring_ascii.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_encode_for_html.py => python/simplejson-2.1.1/simplejson/tests/test_encode_for_html.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_fail.py => python/simplejson-2.1.1/simplejson/tests/test_fail.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_float.py => python/simplejson-2.1.1/simplejson/tests/test_float.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_indent.py => python/simplejson-2.1.1/simplejson/tests/test_indent.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_pass1.py => python/simplejson-2.1.1/simplejson/tests/test_pass1.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_pass2.py => python/simplejson-2.1.1/simplejson/tests/test_pass2.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_pass3.py => python/simplejson-2.1.1/simplejson/tests/test_pass3.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_recursion.py => python/simplejson-2.1.1/simplejson/tests/test_recursion.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_scanstring.py => python/simplejson-2.1.1/simplejson/tests/test_scanstring.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_separators.py => python/simplejson-2.1.1/simplejson/tests/test_separators.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_speedups.py => python/simplejson-2.1.1/simplejson/tests/test_speedups.py
rename : other-licenses/simplejson-2.1.1/simplejson/tests/test_unicode.py => python/simplejson-2.1.1/simplejson/tests/test_unicode.py
rename : other-licenses/simplejson-2.1.1/simplejson/tool.py => python/simplejson-2.1.1/simplejson/tool.py
2012-07-26 13:07:28 -07:00

118 lines
4.0 KiB
Python

import sys
from unittest import TestCase
import simplejson as json
import simplejson.decoder
class TestScanString(TestCase):
def test_py_scanstring(self):
self._test_scanstring(simplejson.decoder.py_scanstring)
def test_c_scanstring(self):
if not simplejson.decoder.c_scanstring:
return
self._test_scanstring(simplejson.decoder.c_scanstring)
def _test_scanstring(self, scanstring):
self.assertEquals(
scanstring('"z\\ud834\\udd20x"', 1, None, True),
(u'z\U0001d120x', 16))
if sys.maxunicode == 65535:
self.assertEquals(
scanstring(u'"z\U0001d120x"', 1, None, True),
(u'z\U0001d120x', 6))
else:
self.assertEquals(
scanstring(u'"z\U0001d120x"', 1, None, True),
(u'z\U0001d120x', 5))
self.assertEquals(
scanstring('"\\u007b"', 1, None, True),
(u'{', 8))
self.assertEquals(
scanstring('"A JSON payload should be an object or array, not a string."', 1, None, True),
(u'A JSON payload should be an object or array, not a string.', 60))
self.assertEquals(
scanstring('["Unclosed array"', 2, None, True),
(u'Unclosed array', 17))
self.assertEquals(
scanstring('["extra comma",]', 2, None, True),
(u'extra comma', 14))
self.assertEquals(
scanstring('["double extra comma",,]', 2, None, True),
(u'double extra comma', 21))
self.assertEquals(
scanstring('["Comma after the close"],', 2, None, True),
(u'Comma after the close', 24))
self.assertEquals(
scanstring('["Extra close"]]', 2, None, True),
(u'Extra close', 14))
self.assertEquals(
scanstring('{"Extra comma": true,}', 2, None, True),
(u'Extra comma', 14))
self.assertEquals(
scanstring('{"Extra value after close": true} "misplaced quoted value"', 2, None, True),
(u'Extra value after close', 26))
self.assertEquals(
scanstring('{"Illegal expression": 1 + 2}', 2, None, True),
(u'Illegal expression', 21))
self.assertEquals(
scanstring('{"Illegal invocation": alert()}', 2, None, True),
(u'Illegal invocation', 21))
self.assertEquals(
scanstring('{"Numbers cannot have leading zeroes": 013}', 2, None, True),
(u'Numbers cannot have leading zeroes', 37))
self.assertEquals(
scanstring('{"Numbers cannot be hex": 0x14}', 2, None, True),
(u'Numbers cannot be hex', 24))
self.assertEquals(
scanstring('[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]', 21, None, True),
(u'Too deep', 30))
self.assertEquals(
scanstring('{"Missing colon" null}', 2, None, True),
(u'Missing colon', 16))
self.assertEquals(
scanstring('{"Double colon":: null}', 2, None, True),
(u'Double colon', 15))
self.assertEquals(
scanstring('{"Comma instead of colon", null}', 2, None, True),
(u'Comma instead of colon', 25))
self.assertEquals(
scanstring('["Colon instead of comma": false]', 2, None, True),
(u'Colon instead of comma', 25))
self.assertEquals(
scanstring('["Bad value", truth]', 2, None, True),
(u'Bad value', 12))
def test_issue3623(self):
self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
"xxx")
self.assertRaises(UnicodeDecodeError,
json.encoder.encode_basestring_ascii, "xx\xff")
def test_overflow(self):
# Python 2.5 does not have maxsize
maxsize = getattr(sys, 'maxsize', sys.maxint)
self.assertRaises(OverflowError, json.decoder.scanstring, "xxx",
maxsize + 1)