Skip to content

Commit d98149e

Browse files
committed
Update tests and readme
1 parent b533a72 commit d98149e

File tree

4 files changed

+99
-149
lines changed

4 files changed

+99
-149
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ parrot = {
558558
module = "parrot.completion.blink",
559559
name = "parrot",
560560
score_offset = 20,
561+
opts = {
562+
show_hidden_files = false,
563+
max_items = 50,
564+
}
561565
},
562566
...
563567
```

tests/parrot/completion/blink_spec.lua

Lines changed: 0 additions & 73 deletions
This file was deleted.

tests/parrot/completion/cmp_spec.lua

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,119 @@
11
local comp_utils = require("parrot.completion.utils")
2+
local mock = require("luassert.mock")
23
local async = require("plenary.async")
34

45
describe("completion.utils", function()
56
describe("resolve_path", function()
67
it("should resolve relative paths correctly", function()
7-
async.run(function()
8-
local cwd = vim.fn.getcwd()
9-
local result = comp_utils.resolve_path("test/path", cwd)
10-
assert.are.equal(cwd .. "/test", result)
11-
end)
8+
local cwd = vim.fn.getcwd()
9+
local result = comp_utils.resolve_path("test/path", cwd)
10+
assert.are.equal(cwd .. "/test", result)
1211
end)
1312

1413
it("should handle absolute paths correctly", function()
15-
async.run(function()
16-
local result = comp_utils.resolve_path("/absolute/path/file.txt", "")
17-
assert.are.equal("/absolute/path", result)
18-
end)
14+
local result = comp_utils.resolve_path("/absolute/path/file.txt", "")
15+
assert.are.equal("/absolute/path", result)
1916
end)
2017

2118
it("should handle paths with trailing slashes", function()
22-
async.run(function()
23-
local result = comp_utils.resolve_path("test/path/", "")
24-
assert.are.equal("test/path/", result)
25-
end)
19+
local result = comp_utils.resolve_path("test/path/", "")
20+
assert.are.equal("test/path/", result)
21+
end)
22+
23+
it("should handle empty path with cwd", function()
24+
local cwd = vim.fn.getcwd()
25+
local result = comp_utils.resolve_path("", cwd)
26+
assert.are.equal(cwd, result)
2627
end)
2728
end)
2829

2930
describe("get_command_documentation", function()
3031
it("should return documentation for known commands", function()
31-
assert.is_string(comp_utils.get_command_documentation("file"))
32-
assert.is_string(comp_utils.get_command_documentation("buffer"))
33-
assert.is_string(comp_utils.get_command_documentation("directory"))
32+
local file_doc = comp_utils.get_command_documentation("file")
33+
assert.is_string(file_doc)
34+
assert.is_true(file_doc:find("@file:") > 0)
35+
36+
local buffer_doc = comp_utils.get_command_documentation("buffer")
37+
assert.is_string(buffer_doc)
38+
assert.is_true(buffer_doc:find("@buffer:") > 0)
39+
40+
local dir_doc = comp_utils.get_command_documentation("directory")
41+
assert.is_string(dir_doc)
42+
assert.is_true(dir_doc:find("@directory:") > 0)
3443
end)
3544

3645
it("should return empty string for unknown commands", function()
3746
assert.are.equal("", comp_utils.get_command_documentation("unknown"))
3847
end)
3948
end)
49+
50+
describe("is_completion_available", function()
51+
it("should return true in parrot chat files", function()
52+
local config_mock = mock(require("parrot.config"), true)
53+
config_mock.loaded = true
54+
config_mock.options = { chat_dir = "/mock/chat/dir" }
55+
56+
local utils_mock = mock(require("parrot.utils"), true)
57+
utils_mock.is_chat.returns(true)
58+
59+
local api_mock = mock(vim.api, true)
60+
api_mock.nvim_get_current_buf.returns(1)
61+
api_mock.nvim_buf_get_name.returns("/mock/chat/dir/test.txt")
62+
63+
assert.is_true(comp_utils.is_completion_available())
64+
65+
mock.revert(config_mock)
66+
mock.revert(utils_mock)
67+
mock.revert(api_mock)
68+
end)
69+
70+
it("should return true in UI input buffers", function()
71+
local api_mock = mock(vim.api, true)
72+
api_mock.nvim_get_current_buf.returns(1)
73+
api_mock.nvim_buf_get_name.returns("")
74+
api_mock.nvim_get_option_value.returns("nofile")
75+
api_mock.nvim_get_namespaces.returns({ 1 })
76+
api_mock.nvim_buf_get_extmarks.returns({
77+
{ 1, 0, 0, { virt_text = { { "Enter text here", "Comment" } } } },
78+
})
79+
80+
assert.is_true(comp_utils.is_completion_available())
81+
82+
mock.revert(api_mock)
83+
end)
84+
85+
it("should return false in regular files", function()
86+
local api_mock = mock(vim.api, true)
87+
api_mock.nvim_get_current_buf.returns(1)
88+
api_mock.nvim_buf_get_name.returns("somefile.txt")
89+
api_mock.nvim_get_option_value.returns("file")
90+
api_mock.nvim_get_namespaces.returns({})
91+
92+
assert.is_false(comp_utils.is_completion_available())
93+
94+
mock.revert(api_mock)
95+
end)
96+
end)
97+
98+
-- describe("read_file_async", function()
99+
-- it("should read file content asynchronously", function()
100+
-- local uv_mock = mock(vim.uv, true)
101+
-- uv_mock.fs_open.returns(1)
102+
-- uv_mock.fs_read.returns("test content")
103+
-- uv_mock.fs_close.returns(true)
104+
105+
-- local content
106+
-- async.run(function()
107+
-- comp_utils.read_file_async("test.txt", 1024, async).map(function(data)
108+
-- content = data
109+
-- end)
110+
-- end)
111+
112+
-- vim.wait(100, function() return content ~= nil end)
113+
-- assert.are.equal("test content", content)
114+
115+
-- mock.revert(uv_mock)
116+
-- end)
117+
-- end)
118+
40119
end)

0 commit comments

Comments
 (0)