forked from elixir-tools/elixir-tools.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_spec.lua
More file actions
70 lines (54 loc) · 2.14 KB
/
utils_spec.lua
File metadata and controls
70 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local root_dir = vim.fn.getcwd()
local utils = require("elixir.utils")
describe("utils", function()
after_each(function()
vim.api.nvim_command("cd " .. root_dir)
end)
describe("root_dir", function()
it("finds elixir project root dir without a filename", function()
local project_dir = root_dir .. "/tests/fixtures/project_a"
vim.api.nvim_command("cd " .. project_dir)
local result = utils.root_dir()
assert.are.equal(project_dir, result)
end)
it("finds elixir project root dir", function()
local project_dir = root_dir .. "/tests/fixtures/project_a"
local result = utils.root_dir(project_dir .. "/lib/module.ex")
assert.are.equal(project_dir, result)
end)
it("finds elixir umbrella project root dir", function()
local project_dir = root_dir .. "/tests/fixtures/project_b"
local result = utils.root_dir(project_dir .. "/apps/app_a/lib/module.ex")
assert.are.equal(project_dir, result)
end)
it("returns nil if no elixir project root dir is found", function()
local result = utils.root_dir()
assert.are.equal(nil, result)
end)
end)
describe("latest_release", function()
it("returns the latest release for the repo", function()
local result = utils.latest_release("elixir-tools", "next-ls", { cache_dir = "./tmp/" })
assert(type(result) == "string")
assert.is.Truthy(string.match(result, "%d+%.%d+%.%d+"))
end)
it("returns nil if the command has a non zero exit code and no file in cache", function()
vim.fn.delete("./tmp/elixir-tools-next-ls.txt")
local result = utils.latest_release(
"elixir-tools",
"next-ls",
{ github_host = "localhost:9999", cache_dir = "./tmp/" }
)
assert.is.Nil(result)
end)
it("returns nil if the command has a non zero exit code and no file in cache", function()
vim.fn.writefile({ "0.2.2" }, "./tmp/elixir-tools-next-ls.txt")
local result = utils.latest_release(
"elixir-tools",
"next-ls",
{ github_host = "localhost:9999", cache_dir = "./tmp/" }
)
assert.are.same(result, "0.2.2")
end)
end)
end)