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)
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
def test_has_a_block(self): prog = parse("1 + 1") prog.block.should.equal(Block(Add(Integer(1), Integer(1))))
def test_cant_be_created_with_empty_statement(self): b1 = Block() # noinspection PyStatementEffect b1.statements.should.be.empty
def test_can_be_created_from_single_statement(self): body = Add(Integer(8), Integer(10)) b1 = Block(body) b1.statements.should.contain(body)
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)
def block(self, *args): statements_excluding_token = [ arg for arg in args if arg and not isinstance(arg, Token) ] return Block(statements_excluding_token)