Merge pull request #218 from emmanueltouzery/elixir_exunit

support for elixir exunit tests
This commit is contained in:
Steven Arcangeli 2023-02-11 17:31:25 -08:00 committed by GitHub
commit a467e9a06a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 0 deletions

View file

@ -82,6 +82,10 @@ M.elixir = {
local protocol = (utils.get_at_path(match, "protocol") or {}).node
local protocol_name = vim.treesitter.query.get_node_text(protocol, bufnr) or "<parse error>"
item.name = string.format("%s > %s", item.name, protocol_name)
elseif name == "test" then
item.name = string.format("test %s", item.name)
elseif name == "describe" then
item.name = string.format("describe %s", item.name)
end
elseif item.kind == "Constant" then
item.name = string.format("@%s", item.name)

View file

@ -57,3 +57,18 @@
target: (identifier) @identifier (#eq? @identifier "defstruct")) @type
(#set! "kind" "Function")
) @start
; exunit unit test
(call
target: (identifier) @identifier (#any-of? @identifier "describe" "test")
(arguments [(string (quoted_content) @name)])
(#set! "kind" "Function")
) @type
; exunit test setup
(do_block
(call
target: (identifier) @identifier @name (#eq? @identifier "setup")) @type
(#set! "kind" "Function")
) @type

View file

@ -175,6 +175,55 @@ describe("treesitter elixir", function()
},
},
},
{
kind = "Module",
name = "StringTest",
level = 0,
lnum = 43,
col = 0,
end_lnum = 59,
end_col = 3,
children = {
{
kind = "Function",
name = "describe String.capitalize/1",
level = 1,
lnum = 46,
col = 2,
end_lnum = 58,
end_col = 5,
children = {
{
kind = "Function",
name = "setup",
level = 2,
lnum = 47,
col = 4,
end_lnum = 49,
end_col = 7,
},
{
kind = "Function",
name = "test first grapheme is in uppercase",
level = 2,
lnum = 51,
col = 4,
end_lnum = 53,
end_col = 7,
},
{
kind = "Function",
name = "test converts remaining graphemes to lowercase",
level = 2,
lnum = 55,
col = 4,
end_lnum = 57,
end_col = 7,
},
},
},
},
},
})
end)
end)

View file

@ -38,3 +38,22 @@ defimpl Example.Protocol, for: Map do
true
end
end
# https://hexdocs.pm/ex_unit/ExUnit.Case.html#describe/2-examples
defmodule StringTest do
use ExUnit.Case, async: true
describe "String.capitalize/1" do
setup do
# setup code
end
test "first grapheme is in uppercase" do
assert String.capitalize("hello") == "Hello"
end
test "converts remaining graphemes to lowercase" do
assert String.capitalize("HELLO") == "Hello"
end
end
end