Пример #1
0
    def test_recursive_type(self):
        variable_length_integer = Choice('variable length integer', [])
        variable_length_integer.children = [
            Sequence('final byte:', [
                Field(None, length=1, constraints=[Equals(0)]),
                Field('value:', length=7)],
                value=parse('${value:}')),
            Sequence('intermediate byte:', [
                Field(None, length=1, constraints=[Equals(1)]),
                Field('value:', length=7),
                Child('next:', variable_length_integer)],
                value=parse('(${value:} << 7) + ${next:}'))]

        params = ExpressionParameters([variable_length_integer])
        range = EntryValueType(variable_length_integer).range(params)
        self.assertEqual(None, range.min)
        self.assertEqual(None, range.max)
Пример #2
0
    def test_unknown_range(self):
        # In this case 'intermediate byte:' has an unknown range, while
        # 'final byte:' has a known range. We should attempt to solve
        # the smallest range first...
        variable_length_integer = Choice('variable length integer', [])
        variable_length_integer.children = [
            Sequence('final byte:', [
                Field(None, length=1, constraints=[Equals(0)]),
                Field('value:', length=7)],
                value=parse('${value:}')),
            Sequence('intermediate byte:', [
                Field(None, length=1, constraints=[Equals(1)]),
                Field('least significant:', length=7),
                Child('most significant:', variable_length_integer)],
                value=parse('(${most significant:} * 128) + ${least significant:}'),
            constraints=[Minimum(0)])]

        self.assertEqual({'${most significant:}':1, '${least significant:}':0},
                _solve(variable_length_integer, 1, 128))
        self.assertEqual({'${most significant:}':1, '${least significant:}':1},
                _solve(variable_length_integer, 1, 129))