def testJsonParsing(self): stream = 'some meaningful {"a": "b"} something else skippable {"c": "d"} end.' start = len('some meaningful ') self.assertTrue(JsonValueParser.is_applicable(stream[start]), 'Should be parsable.') _, value, _ = JsonValueParser.parse(start, stream) self.assertEqual(value, '{"a": "b"}') start = len('some meaningful {"a": "b"} something else skippable ') self.assertTrue(JsonValueParser.is_applicable(stream[start]), 'Should be parsable.') _, value, _ = JsonValueParser.parse(start, stream) self.assertEqual(value, '{"c": "d"}') start = len(stream) - 2 self.assertFalse(JsonValueParser.is_applicable(stream[start]), 'Should not be parsable.')
def testComplexJsonParsing(self): stream = 'some meaningful {"a": "b", "c": "d", "e": {"f": "g"}, "h": [1, 2]}' start = len('some meaningful ') self.assertTrue(JsonValueParser.is_applicable(stream[start]), 'Should be parsable.') _, value, _ = JsonValueParser.parse(start, stream) self.assertEqual(value, '{"a": "b", "c": "d", "e": {"f": "g"}, "h": [1, 2]}')
def testEndJsonParsing(self): stream = 'some meaningful {"a": "b"}' start = len('some meaningful ') self.assertTrue(JsonValueParser.is_applicable(stream[start]), 'Should be parsable.') _, value, _ = JsonValueParser.parse(start, stream) self.assertEqual(value, '{"a": "b"}')
def testIncompleteStringParsing(self): stream = 'some meaningful {"a":' start = len('some meaningful ') self.assertTrue(JsonValueParser.is_applicable(stream[start]), 'Should be parsable.') try: JsonValueParser.parse(start, stream) self.assertTrue(False, 'Parsing failure expected.') except content.ParseException: self.assertTrue(True)