예제 #1
0
    def test_can_append_scalar_conditional(self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})
        parser.append({
            'name': 'bar',
            'condition': 'foo',
            'condition_value': 'red'
        })
        result = parser.commit()

        # Assert:
        self.assertEqual(('Car', {
            'type':
            'struct',
            'layout': [{
                'name': 'foo'
            }, {
                'name': 'bar',
                'condition': 'foo',
                'condition_value': 'red'
            }]
        }), result)
예제 #2
0
    def test_cannot_append_array_with_invalid_size_reference(self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})

        # Assert:
        with self.assertRaises(CatsParseException):
            parser.append({'name': 'bar', 'size': 'fob'})
예제 #3
0
    def test_cannot_append_multiple_properties_with_same_name_and_disposition(
            self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})
        parser.append({'name': 'bar'})

        # Assert:
        with self.assertRaises(CatsParseException):
            parser.append({'name': 'foo'})
예제 #4
0
    def test_cannot_append_scalar_with_invalid_condition_reference(self):
        for condition in ['baz', '10']:
            # Arrange:
            parser = StructParserFactory().create()

            # Act:
            parser.process_line('struct Car')
            parser.append({'name': 'foo'})

            # Assert:
            with self.assertRaises(CatsParseException):
                parser.append({
                    'name': 'bar',
                    'condition': condition,
                    'condition_value': 'red'
                })
예제 #5
0
    def test_can_append_array_with_fill_disposition_last(self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})
        parser.append({'name': 'cat', 'disposition': 'fill'})
        result = parser.commit()

        # Assert:
        self.assertEqual(('Car', {
            'type':
            'struct',
            'layout': [{
                'name': 'foo'
            }, {
                'name': 'cat',
                'disposition': 'fill'
            }]
        }), result)
예제 #6
0
    def test_can_append_unnamed_descriptor(self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'disposition': 'inline', 'type': 'Foo'})
        parser.append({'name': 'foo'})
        result = parser.commit()

        # Assert:
        self.assertEqual(('Car', {
            'type':
            'struct',
            'layout': [{
                'disposition': 'inline',
                'type': 'Foo'
            }, {
                'name': 'foo'
            }]
        }), result)
예제 #7
0
    def test_can_append_array_with_valid_size_reference(self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})
        parser.append({'name': 'bar', 'size': 'foo'})
        result = parser.commit()

        # Assert:
        self.assertEqual(
            ('Car', {
                'type': 'struct',
                'layout': [{
                    'name': 'foo'
                }, {
                    'name': 'bar',
                    'size': 'foo'
                }]
            }), result)
예제 #8
0
    def test_can_append_multiple_properties_with_same_name_and_different_disposition(
            self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})
        parser.append({'name': 'foo', 'disposition': 'const'})
        result = parser.commit()

        # Assert:
        self.assertEqual(('Car', {
            'type':
            'struct',
            'layout': [{
                'name': 'foo'
            }, {
                'name': 'foo',
                'disposition': 'const'
            }]
        }), result)
예제 #9
0
    def test_cannot_append_property_after_array_with_fill_disposition(self):
        # Arrange:
        parser = StructParserFactory().create()

        # Act:
        parser.process_line('struct Car')
        parser.append({'name': 'foo'})
        parser.append({'name': 'cat', 'disposition': 'fill'})

        # Assert:
        with self.assertRaises(CatsParseException):
            parser.append({'name': 'bar'})