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)
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)
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)
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'))
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)
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.'))
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)
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)
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())
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() )
def test_success_get_assignment_use_key_word_var(self): block = Block("var a int64") result = block.is_declared() self.assertTrue(result)
def test_return_false_when_give_a_not_declared_code(self): block = Block("a >= 1") result = block.is_declared() self.assertTrue(not result)
def test_return_false_when_declared_and_used_block(self): block = Block("a := 1; a++") result = block.is_declared() self.assertTrue(not result)
def test_return_true_when_is_a_declared_vari_code(self): block = Block("a := 1") result = block.is_declared() self.assertTrue(result)
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)
def test_success_judge_is_declared_when_declared_multi_varis(self): block = Block("x, y := 1, 2") result = block.is_declared() self.assertTrue(result)
def test_success_get_assignment_use_key_word_const(self): block = Block('const x string = "hello world"') result = block.is_declared() self.assertTrue(result)
def test_success_judge_is_declared_block(self): block = Block('const x string = "hello world"') result = block.is_declared() self.assertTrue(result)
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)