Exemplo n.º 1
0
    def test_compile_array_with_simple_arg(self):
        signature = b'as'
        call_arg = [b"arg_1", b"arg_2"]

        off, func = compile_array(signature)

        self.assertEqual(signature, off)
        self.assertEqual(func(call_arg), [
            (ord(b'a'), signature[1:]),
            (ord(b's'), b"arg_1"),
            (ord(b's'), b"arg_2"),
            (-1, None),
        ])
Exemplo n.º 2
0
    def test_compile_array_of_structs(self):
        signature = b'a(ss)'
        call_arg = [(b"arg_1", b"arg_2"), (b"arg_a", b"arg_b")]

        off, func = compile_array(signature)

        self.assertEqual(signature, off)
        self.assertEqual(func(call_arg), [
            (ord(b'a'), signature[1:]),
            (ord(b'r'), b'ss'),
            (ord(b's'), b"arg_1"),
            (ord(b's'), b"arg_2"),
            (-1, None),
            (ord(b'r'), b'ss'),
            (ord(b's'), b"arg_a"),
            (ord(b's'), b"arg_b"),
            (-1, None),
            (-1, None),
        ])
Exemplo n.º 3
0
    def test_compile_double_array(self):
        signature = b'aas'
        call_arg = [[b"arg_1", b"arg_2"], [b"arg_a", b"arg_b"]]

        off, func = compile_array(signature)

        self.assertEqual(signature, off)
        self.assertEqual(func(call_arg), [
            (ord(b'a'), signature[1:]),
            (ord(b'a'), b's'),
            (ord(b's'), b"arg_1"),
            (ord(b's'), b"arg_2"),
            (-1, None),
            (ord(b'a'), b's'),
            (ord(b's'), b"arg_a"),
            (ord(b's'), b"arg_b"),
            (-1, None),
            (-1, None),
        ])