gecko/python/simplejson-2.1.1/simplejson/tests/test_fail.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

91 lines
3.5 KiB
Python

from unittest import TestCase
import simplejson as json
# Fri Dec 30 18:57:26 2005
JSONDOCS = [
# http://json.org/JSON_checker/test/fail1.json
'"A JSON payload should be an object or array, not a string."',
# http://json.org/JSON_checker/test/fail2.json
'["Unclosed array"',
# http://json.org/JSON_checker/test/fail3.json
'{unquoted_key: "keys must be quoted}',
# http://json.org/JSON_checker/test/fail4.json
'["extra comma",]',
# http://json.org/JSON_checker/test/fail5.json
'["double extra comma",,]',
# http://json.org/JSON_checker/test/fail6.json
'[ , "<-- missing value"]',
# http://json.org/JSON_checker/test/fail7.json
'["Comma after the close"],',
# http://json.org/JSON_checker/test/fail8.json
'["Extra close"]]',
# http://json.org/JSON_checker/test/fail9.json
'{"Extra comma": true,}',
# http://json.org/JSON_checker/test/fail10.json
'{"Extra value after close": true} "misplaced quoted value"',
# http://json.org/JSON_checker/test/fail11.json
'{"Illegal expression": 1 + 2}',
# http://json.org/JSON_checker/test/fail12.json
'{"Illegal invocation": alert()}',
# http://json.org/JSON_checker/test/fail13.json
'{"Numbers cannot have leading zeroes": 013}',
# http://json.org/JSON_checker/test/fail14.json
'{"Numbers cannot be hex": 0x14}',
# http://json.org/JSON_checker/test/fail15.json
'["Illegal backslash escape: \\x15"]',
# http://json.org/JSON_checker/test/fail16.json
'["Illegal backslash escape: \\\'"]',
# http://json.org/JSON_checker/test/fail17.json
'["Illegal backslash escape: \\017"]',
# http://json.org/JSON_checker/test/fail18.json
'[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]',
# http://json.org/JSON_checker/test/fail19.json
'{"Missing colon" null}',
# http://json.org/JSON_checker/test/fail20.json
'{"Double colon":: null}',
# http://json.org/JSON_checker/test/fail21.json
'{"Comma instead of colon", null}',
# http://json.org/JSON_checker/test/fail22.json
'["Colon instead of comma": false]',
# http://json.org/JSON_checker/test/fail23.json
'["Bad value", truth]',
# http://json.org/JSON_checker/test/fail24.json
"['single quote']",
# http://code.google.com/p/simplejson/issues/detail?id=3
u'["A\u001FZ control characters in string"]',
]
SKIPS = {
1: "why not have a string payload?",
18: "spec doesn't specify any nesting limitations",
}
class TestFail(TestCase):
def test_failures(self):
for idx, doc in enumerate(JSONDOCS):
idx = idx + 1
if idx in SKIPS:
json.loads(doc)
continue
try:
json.loads(doc)
except json.JSONDecodeError:
pass
else:
#self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
self.fail("Expected failure for fail%d.json: %r" % (idx, doc))
def test_array_decoder_issue46(self):
# http://code.google.com/p/simplejson/issues/detail?id=46
for doc in [u'[,]', '[,]']:
try:
json.loads(doc)
except json.JSONDecodeError, e:
self.assertEquals(e.pos, 1)
self.assertEquals(e.lineno, 1)
self.assertEquals(e.colno, 1)
except Exception, e:
self.fail("Unexpected exception raised %r %s" % (e, e))
else:
self.fail("Unexpected success parsing '[,]'")