def test_find_start_end_line_in_class(self): file = Path(self.cur_file_dir, 'start_end/LottieImageAsset.java') with open(file, 'r', encoding='utf-8') as f: tree = javalang.parse.parse(f.read()) method = list(tree.filter(javalang.tree.ClassDeclaration))[0][1] start, end = find_start_and_end_lines(method) self.assertEqual(start, 11) self.assertEqual(end, 59)
def test_find_start_end_line_in_function2(self): file = Path(self.cur_file_dir, 'start_end/UpDirective.java') with open(file, 'r', encoding='utf-8') as f: tree = javalang.parse.parse(f.read()) method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] start, end = find_start_and_end_lines(method) self.assertEqual(start, 49) self.assertEqual(end, 65)
def test_find_start_end_line_return_by_one_line(self): file = Path(self.cur_file_dir, 'start_end/FileStorage.java') with open(file, 'r', encoding='utf-8') as f: tree = javalang.parse.parse(f.read()) method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] start, end = find_start_and_end_lines(method) self.assertEqual(start, 108) self.assertEqual(end, 140)
def test_find_start_end_line_empty_function_in_anonymous_class(self): file = Path(self.cur_file_dir, 'start_end/AnonymousClass.java') with open(file, 'r', encoding='utf-8') as f: tree = javalang.parse.parse(f.read()) method = list(tree.filter(javalang.tree.MethodDeclaration))[1][1] start, end = find_start_and_end_lines(method) self.assertEqual(start, 37) self.assertEqual(end, 38)
def test_find_start_end_line_empty_function_with_lambda(self): file = Path(self.cur_file_dir, 'start_end/Lambda.java') with open(file, 'r', encoding='utf-8') as f: tree = javalang.parse.parse(f.read()) method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] start, end = find_start_and_end_lines(method) self.assertEqual(start, 32) self.assertEqual(end, 43)
def test_find_start_end_line_empty_function(self): # Check start and end line for MethodDeclaration, # find_start_and_end_lines is used for functions only at the moment file = Path(self.cur_file_dir, 'start_end/EmptyFunction.java') with open(file, 'r', encoding='utf-8') as f: tree = javalang.parse.parse(f.read()) method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] start, end = find_start_and_end_lines(method) self.assertEqual(start, 32) self.assertEqual(end, 32)