Exemplo n.º 1
0
    def test_can_check_used_assignment(self):
        handler = CodeHandler()
        handler.varis = dict(a=0)
        handler.get_declared().clear()
        handler.add_declared("a", Block("a := 1"))

        block = Block('fmt.Println(a)')
        handler.scan_used([block])

        self.assertEqual(len(list(handler.get_params())), 1)
        self.assertTrue("a" in handler.get_params())
Exemplo n.º 2
0
    def test_is_used_assignment_need_compile_would_return_true(self):
        handler = CodeHandler()

        declared_block = Block("a := 1")
        block = Block("a.get()")

        handler._blocks.append(declared_block)
        handler._blocks.append(block)
        handler.add_declared("a", declared_block)

        result = handler.need_compile(block)

        self.assertTrue(result)
Exemplo n.º 3
0
    def test_is_need_compile_would_return_true_if_not_assignment_code(self):
        handler = CodeHandler()

        declared_block = Block("var a string")
        block = Block("fmt.Println(a)")

        handler._blocks.append(declared_block)
        handler._blocks.append(block)
        handler.add_declared("a", declared_block)
        handler.assignment_manager.add_assigned("a", handler.handler_type)

        result = handler.need_compile(block)

        self.assertTrue(result)