Beispiel #1
0
    def test_can_be_created_from_a_list_of_statements(self):
        s1 = Add(Integer(8), Integer(10))
        s2 = Mul(Integer(18), Integer(1))
        body = [
            s1,
            s2,
        ]

        b1 = Block(body)
        b1.statements.should.contain(s1)
        b1.statements.should.contain(s2)
Beispiel #2
0
    def add_klass(self, klass):
        has_constructor = False

        for funktion in self.functions:
            has_constructor |= funktion.is_constructor
            klass.add_function(funktion)

        if not has_constructor:
            default_constructor = Funktion('init',
                                           params=[],
                                           body=Block(),
                                           is_constructor=True)
            klass.body.statements.append(default_constructor)
            klass.add_function(default_constructor)

        self.classes.append(klass)
        self.functions = []
        return klass
Beispiel #3
0
 def test_has_a_block(self):
     prog = parse("1 + 1")
     prog.block.should.equal(Block(Add(Integer(1), Integer(1))))
Beispiel #4
0
 def test_cant_be_created_with_empty_statement(self):
     b1 = Block()
     # noinspection PyStatementEffect
     b1.statements.should.be.empty
Beispiel #5
0
 def test_can_be_created_from_single_statement(self):
     body = Add(Integer(8), Integer(10))
     b1 = Block(body)
     b1.statements.should.contain(body)
Beispiel #6
0
    def test_works_for_programs(self):
        p1 = Program(Block(Add(Integer(8), Integer(10))))
        p2 = Program(Block(Add(Integer(8), Integer(10))))

        # noinspection PyUnresolvedReferences
        p1.should.be.equal(p2)
Beispiel #7
0
 def block(self, *args):
     statements_excluding_token = [
         arg for arg in args if arg and not isinstance(arg, Token)
     ]
     return Block(statements_excluding_token)