コード例 #1
0
    def test_can_append_array_with_valid_size_reference_and_inline(self):
        # Arrange:
        parser = StructParserFactory().create()

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

        # Assert:
        self.assertEqual(('Car', {
            'type':
            'struct',
            'layout': [{
                'disposition': 'inline',
                'type': 'Vehicle'
            }, {
                'name': 'foo'
            }, {
                'name': 'bar',
                'size': 'foo'
            }]
        }), result)
コード例 #2
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)
コード例 #3
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'})
コード例 #4
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'})
コード例 #5
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'})
コード例 #6
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'
                })
コード例 #7
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)
コード例 #8
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)
コード例 #9
0
    def test_can_append_array_with_numeric_size(self):
        # Arrange:
        parser = StructParserFactory().create()

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

        # Assert:
        self.assertEqual(
            ('Car', {
                'type': 'struct',
                'layout': [{
                    'name': 'foo'
                }, {
                    'name': 'bar',
                    'size': 10
                }]
            }), result)
コード例 #10
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)
コード例 #11
0
    def test_parser_exposes_custom_factories(self):
        # Act
        parser = StructParserFactory().create()

        # Assert
        self.assertEqual(4, len(parser.factories()))