Skip to content

Commit

Permalink
feat: support alternative receiver/suite syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 8, 2024
1 parent 79f651f commit 54be433
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lua/neotest-golang/testify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ M.lookup_query = [[
(call_expression
arguments: (argument_list
(type_identifier) @suite_receiver))))
; capture variable declarations
(short_var_declaration
left: (expression_list
(identifier) @var_name)
right: (expression_list
(unary_expression
operand: (composite_literal
type: (type_identifier) @struct_type))))
(assignment_statement
left: (expression_list
(identifier) @var_name)
right: (expression_list
(unary_expression
operand: (composite_literal
type: (type_identifier) @struct_type))))
]]

M.receiver_method_query = [[
Expand All @@ -53,7 +70,8 @@ function M.modify_neotest_tree(file_path, tree)
end

local modified_tree = M.replace_receiver_with_suite(tree:root(), lookup)
local tree_with_merged_namespaces = M.merge_duplicate_namespaces(tree:root())
local tree_with_merged_namespaces =
M.merge_duplicate_namespaces(modified_tree)
return tree_with_merged_namespaces
end

Expand Down Expand Up @@ -143,6 +161,26 @@ function M.generate_lookup_map()
end
end
end

-- Handle var_name and struct_type matches
if matches.var_name and matches.struct_type then
for i, var in ipairs(matches.var_name) do
local struct_type = matches.struct_type[i]
if struct_type then
-- Add the struct_type as a receiver
lookup[filepath].receivers[struct_type.text] = true

-- Find the corresponding function_name (test suite)
for _, func in ipairs(matches.function_name or {}) do
if func.text:match("^Test") then
lookup[filepath].suites[struct_type.text] = func.text
global_suites[struct_type.text] = func.text
break
end
end
end
end
end
end

-- Second pass: ensure all files have all receivers and suites
Expand Down Expand Up @@ -208,6 +246,8 @@ function M.run_query_on_file(filepath, query_string)

vim.api.nvim_buf_delete(bufnr, { force = true })

vim.notify(vim.inspect(matches))

return matches
end

Expand Down

0 comments on commit 54be433

Please sign in to comment.