Navigation Menu

Skip to content

Commit

Permalink
Added more tests for correct and incorrect array decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Tarnstrom committed Aug 14, 2012
1 parent a16f229 commit 684a4ab
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions tests/tests.py
Expand Up @@ -496,7 +496,7 @@ def test_decodeNumericIntNeg(self):
input = "-31337"
self.assertEquals (-31337, ujson.decode(input))

@unittest.skipIf(_python_ver(3), "No exception in Python 3")
#@unittest.skipIf(_python_ver(3), "No exception in Python 3")
def test_encodeUnicode4BytesUTF8Fail(self):
input = "\xfd\xbf\xbf\xbf\xbf\xbf"
try:
Expand Down Expand Up @@ -701,6 +701,51 @@ def toDict(self):
dec = ujson.decode(output)
self.assertEquals(dec, d)

def test_decodeArrayTrailingCommaFail(self):
input = "[31337,]"
try:
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"

def test_decodeArrayLeadingCommaFail(self):
input = "[,31337]"
try:
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"

def test_decodeArrayOnlyCommaFail(self):
input = "[,]"
try:
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"

def test_decodeArrayUnmatchedBracketFail(self):
input = "[]]"
try:
ujson.decode(input)
except ValueError:
pass
else:
assert False, "expected ValueError"

def test_decodeArrayEmpty(self):
input = "[]"
ujson.decode(input)

def test_decodeArrayOneItem(self):
input = "[31337]"
ujson.decode(input)


"""
def test_decodeNumericIntFrcOverflow(self):
input = "X.Y"
Expand All @@ -723,17 +768,21 @@ def test_decodeStringUTF8(self):
input = "someutfcharacters"
raise NotImplementedError("Implement this test!")
"""
if __name__ == "__main__":
unittest.main()

"""
# Use this to look for memory leaks
if __name__ == '__main__':
from guppy import hpy
hp = hpy()
hp.setrelheap()
while True:
unittest.main()
try:
unittest.main()
except SystemExit:
pass
heap = hp.heapu()
print heap
print heap
"""

0 comments on commit 684a4ab

Please sign in to comment.