Example #1
0
    def test_success_get_vari_when_use_key_word_const(self):
        block = Block('const x string = "hello world"')

        varis = set(block.get_declared_varis())

        self.assertTrue("x" in varis)
        self.assertTrue(len(varis) == 1)
Example #2
0
    def test_parse_single_code(self):
        block = Block('fmt.Println("aa")')

        result = block.parse_to_codes()

        self.assertEqual(type(result), list)
        self.assertEqual(len(result), 2)
Example #3
0
    def test_success_get_vari_when_use_key_word_var(self):
        block = Block("var a int64")

        varis = set(block.get_declared_varis())

        self.assertTrue("a" in varis)
        self.assertTrue(len(varis) == 1)
Example #4
0
    def test_parse_one_metho_when_a_string_like_method(self):
        block = Block('get("console.Find()")')

        result = block.parse_to_codes()

        self.assertEqual(len(result), 2)
        self.assertTrue(result[0].startswith('get'))
Example #5
0
    def test_success_get_vari_when_declear(self):
        block = Block('a := "123"')

        varis = set(block.get_declared_varis())

        self.assertTrue("a" in varis)
        self.assertTrue(len(varis) == 1)
Example #6
0
    def test_parse_two_method_when_use_package_method_as_anothers_value(self):
        block = Block("get(console.Find())")

        result = block.parse_to_codes()

        self.assertEqual(len(result), 3)
        self.assertTrue(result[0] == "get(console.Find())")
        self.assertTrue(result[1].startswith("get"))
        self.assertTrue(result[2].startswith('console.'))
Example #7
0
    def test_scan_used_package_when_block_is_condition_code(self):
        handler = PackageHandler()
        handler.add_declared("com.yyx.console", "com.yyx.console")
        block = Block("if a == 1 {")
        block.append(Block("console.Find().get()"))
        block.append("}")

        handler.scan_used([block])
        self.assertEqual(len(list(handler.get_params())), 1)
Example #8
0
    def test_defined_method_but_not_call_it_should_not_assigned(self):
        console = Console()
        console.assignment_manager.clear()
        block = Block("func a(i int) {")
        block.append(Block("fmt.Println(i)"))
        block.append(Block("}"))

        console.custom_methods.add(block)
        console.custom_methods.scan_used(console.codes.blocks)
        console.packages.scan_used(
            console.codes.blocks + console.custom_methods.methods
        )

        self.assertEqual(len(console.custom_methods.methods), 0)
Example #9
0
    def test_pre_define_vari_a_then_overload_a_as_method_should_change_assignment(self):
        console = Console()
        console.assignment_manager.clear()
        block = Block("func a(i int) {")
        block.append(Block("fmt.Println(i)"))
        block.append(Block("}"))

        console.codes.add(Block("a := 1"))
        console.custom_methods.add(block)
        console.codes.add(Block("a(2)"))
        console.custom_methods.scan_used(console.codes.blocks)
        console.packages.scan_used(
            console.codes.blocks + console.custom_methods.methods
        )

        self.assertTrue("a" not in console.codes.get_params())
        self.assertTrue("a" in console.custom_methods.get_params())
Example #10
0
    def test_should_clear_old_package_when_clear_and_scan_used_package(self):
        handler = PackageHandler()
        handler.add_declared("com.yyx.console", "com.yyx.console")
        handler.assignment_manager.add_assigned(
            "com.yyx.text", handler.handler_type
        )
        block = Block("if a == 1 {")
        block.append(Block("console.Find().get()"))
        block.append("}")

        handler.assignment_manager.clear()

        handler.scan_used([block])

        self.assertEqual(handler.assignment_manager.length(), 1)
        self.assertTrue(
            "com.yyx.text" not in handler.get_params()
        )
Example #11
0
    def test_success_get_assignment_use_key_word_var(self):
        block = Block("var a int64")

        result = block.is_declared()

        self.assertTrue(result)
Example #12
0
    def test_return_false_when_give_a_not_declared_code(self):
        block = Block("a >= 1")

        result = block.is_declared()

        self.assertTrue(not result)
Example #13
0
    def test_return_false_when_declared_and_used_block(self):
        block = Block("a := 1; a++")

        result = block.is_declared()

        self.assertTrue(not result)
Example #14
0
    def test_return_true_when_is_a_declared_vari_code(self):
        block = Block("a := 1")

        result = block.is_declared()

        self.assertTrue(result)
Example #15
0
    def test_success_judge_is_declared_block_when_use_key_word_type(self):
        block = Block("type Counter int")

        result = block.is_declared()

        self.assertTrue(result)
Example #16
0
    def test_success_judge_is_declared_when_declared_multi_varis(self):
        block = Block("x, y := 1, 2")

        result = block.is_declared()

        self.assertTrue(result)
Example #17
0
    def test_success_get_assignment_use_key_word_const(self):
        block = Block('const x string = "hello world"')

        result = block.is_declared()

        self.assertTrue(result)
Example #18
0
    def test_success_judge_is_declared_block(self):
        block = Block('const x string = "hello world"')

        result = block.is_declared()

        self.assertTrue(result)
Example #19
0
    def test_success_get_vari_when_use_key_word_type(self):
        block = Block("type Counter int")

        varis = set(block.get_declared_varis())
        self.assertTrue("Counter" in varis)
        self.assertEqual(len(varis), 1)