mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue 6105: json encoder to respect iteration order of its inputs.
This commit is contained in:
parent
0ffaaa634d
commit
c8d952dfe4
2 changed files with 30 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
|||
from unittest import TestCase
|
||||
|
||||
import json.encoder
|
||||
from json import dumps
|
||||
from collections import OrderedDict
|
||||
|
||||
CASES = [
|
||||
('/\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\x08\x0c\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?', '"/\\\\\\"\\ucafe\\ubabe\\uab98\\ufcde\\ubcda\\uef4a\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"'),
|
||||
|
@ -35,3 +37,9 @@ class TestEncodeBaseStringAscii(TestCase):
|
|||
self.assertEquals(result, expect,
|
||||
'{0!r} != {1!r} for {2}({3!r})'.format(
|
||||
result, expect, fname, input_string))
|
||||
|
||||
def test_ordered_dict(self):
|
||||
# See issue 6105
|
||||
items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
|
||||
s = json.dumps(OrderedDict(items))
|
||||
self.assertEqual(s, '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue