def test_process_with_filter_function(self): ast = self.create_ast(Fixtures.MAP_AND_FILTER_VARIABLE) parser = MapAndFilterParser() got_ast = parser.process(ast) string_expr_nodes = get_string_expr_content(got_ast['body'][1]['left']) self.assertEqual('v:key', string_expr_nodes[0]['left'].get('value'))
def attach_identifier_attributes(self, ast): """ Attach 5 flags to the AST. - is dynamic: True if the identifier name can be determined by static analysis. - is member: True if the identifier is a member of a subscription/dot/slice node. - is declaring: True if the identifier is used to declare. - is autoload: True if the identifier is declared with autoload. - is function: True if the identifier is a function. Vim distinguish between function identifiers and variable identifiers. - is declarative paramter: True if the identifier is a declarative parameter. For example, the identifier "param" in Func(param) is a declarative paramter. - is on string expression context: True if the variable is on the string expression context. The string expression context is the string content on the 2nd argument of the map or filter function. """ redir_assignment_parser = RedirAssignmentParser() ast_with_parsed_redir = redir_assignment_parser.process(ast) map_and_filter_parser = MapAndFilterParser() ast_with_parse_map_and_filter_and_redir = \ map_and_filter_parser.process(ast_with_parsed_redir) traverse(ast_with_parse_map_and_filter_and_redir, on_enter=self._enter_handler) return ast
def test_traverse(self): ast = self.create_ast(Fixtures.MAP_AND_FILTER_VARIABLE) parser = MapAndFilterParser() got_ast = parser.process(ast) is_map_and_filter_content_visited = { 'v:val': False, 'v:key': False, } def enter_handler(node): if NodeType(node['type']) is not NodeType.IDENTIFIER: return is_map_and_filter_content_visited[node['value']] = True traverse(got_ast, on_enter=enter_handler) self.assertTrue(all(is_map_and_filter_content_visited.values()))
def test_issue_256(self): ast = self.create_ast(Fixtures.ISSUE_256) parser = MapAndFilterParser() got_ast = parser.process(ast) self.assertIsNotNone(got_ast)