示例#1
0
    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.')
示例#2
0
    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]}')
示例#3
0
    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"}')
示例#4
0
    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"}')
示例#5
0
    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]}')
示例#6
0
    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.')
示例#7
0
    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)
示例#8
0
    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)