Skip to content

Commit

Permalink
Add greedy exhaustion tests
Browse files Browse the repository at this point in the history
Originally written by Daniel Foerster, adjusted by Rodrigo Tobar to
reflect current situation of object building, and help clarifying what
is causing issues in #15.
  • Loading branch information
pydsigner authored and rtobar committed Nov 26, 2019
1 parent d754f9e commit eb63625
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@
'''
NUMBERS_JSON = b'[1, 1.0, 1E2]'
SURROGATE_PAIRS_JSON = br'"\uD83D\uDCA9"'
PARTIAL_ARRAY_JSONS = [
(b'[1,', 1),
(b'[1, 2 ', 1, 2),
(b'[1, "abc"', 1, 'abc'),
(b'[{"abc": [0, 1]}', {'abc': [0, 1]}),
(b'[{"abc": [0, 1]},', {'abc': [0, 1]}),
]


class Parse(object):
Expand Down Expand Up @@ -256,6 +263,13 @@ def test_string_stream(self):
self.assertEqual(len(warns), 1)
self.assertEqual(DeprecationWarning, warns[0].category)

def test_item_building_greediness(self):
for json in PARTIAL_ARRAY_JSONS:
json, expected_items = json[0], json[1:]
iterable = self.backend.items(BytesIO(json), 'item')
for expected_item in expected_items:
self.assertEqual(expected_item, next(iterable))

# Generating real TestCase classes for each importable backend
for name in ['python', 'yajl', 'yajl2', 'yajl2_cffi', 'yajl2_c']:
try:
Expand Down

0 comments on commit eb63625

Please sign in to comment.