From: David Kerkeslager Date: Fri, 14 Apr 2017 16:16:51 +0000 (-0400) Subject: Consume leading whitespace in lists and dictionaries X-Git-Url: https://code.kerkeslager.com/?a=commitdiff_plain;h=84cf65f13614f1ba0ef1b37217a71b46a3b8827a;p=ton Consume leading whitespace in lists and dictionaries --- diff --git a/don/string.py b/don/string.py index 46f5a83..0162d42 100644 --- a/don/string.py +++ b/don/string.py @@ -168,6 +168,7 @@ def _make_utf_parser(encoding): return utf_parser def _make_consume_constant_parser(constant): + @_consume_leading_whitespace def consume_character_parser(s): if s.startswith(constant): return _shared.ParseResult( diff --git a/test_don.py b/test_don.py index cc04df3..0e35e91 100644 --- a/test_don.py +++ b/test_don.py @@ -308,6 +308,12 @@ class TestStringDeserialize(unittest.TestCase): string.deserialize("[1i8,2i8,3i8,4i8,5i8]"), ) + def test_deserializes_list_with_leading_whitespace(self): + self.assertEqual( + [1,2,3,4,5], + string.deserialize(" \t\n[ \t\n1i8 \t\n, \t\n2i8 \t\n, \t\n3i8 \t\n, \t\n4i8 \t\n, \t\n5i8 \t\n]"), + ) + def test_deserializes_dictionary(self): self.assertEqual( collections.OrderedDict([ @@ -317,4 +323,13 @@ class TestStringDeserialize(unittest.TestCase): string.deserialize('{"foo"utf8:1i32,"bar"utf8:"baz"utf8}'), ) + def test_deserializes_dictionary_with_leading_whitespace(self): + self.assertEqual( + collections.OrderedDict([ + ('foo', 1), + ('bar', 'baz'), + ]), + string.deserialize(' \t\n{ \t\n"foo"utf8 \t\n: \t\n1i32 \t\n, \t\n"bar"utf8 \t\n: \t\n"baz"utf8 \t\n}'), + ) + unittest.main()