summaryrefslogtreecommitdiff
path: root/lua/99/test/fill_in_function_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/99/test/fill_in_function_spec.lua')
-rw-r--r--lua/99/test/fill_in_function_spec.lua150
1 files changed, 74 insertions, 76 deletions
diff --git a/lua/99/test/fill_in_function_spec.lua b/lua/99/test/fill_in_function_spec.lua
index 8d28df4..cc356f1 100644
--- a/lua/99/test/fill_in_function_spec.lua
+++ b/lua/99/test/fill_in_function_spec.lua
@@ -10,111 +10,109 @@ local Levels = require("99.logger.level")
--- @param lang string?
--- @return _99.test.Provider, number
local function setup(content, row, col, lang)
- lang = lang or "lua"
- local p = test_utils.TestProvider.new()
- _99.setup({
- provider = p,
- logger = {
- error_cache_level = Levels.ERROR,
- type = "print",
- },
- })
+ lang = lang or "lua"
+ local p = test_utils.TestProvider.new()
+ _99.setup({
+ provider = p,
+ logger = {
+ error_cache_level = Levels.ERROR,
+ type = "print",
+ },
+ })
- local buffer = test_utils.create_file(content, lang, row, col)
- return p, buffer
+ local buffer = test_utils.create_file(content, lang, row, col)
+ return p, buffer
end
--- @param buffer number
--- @return string[]
local function r(buffer)
- return vim.api.nvim_buf_get_lines(buffer, 0, -1, false)
+ return vim.api.nvim_buf_get_lines(buffer, 0, -1, false)
end
local content = {
- "",
- "local foo = function() end",
+ "",
+ "local foo = function() end",
}
describe("fill_in_function", function()
- it("replace function contents", function()
- local p, buffer = setup(content, 2, 12)
- local state = _99.__get_state()
+ it("replace function contents", function()
+ local p, buffer = setup(content, 2, 12)
+ local state = _99.__get_state()
- _99.fill_in_function()
+ _99.fill_in_function()
- eq(1, state:active_request_count())
- eq(content, r(buffer))
+ eq(1, state:active_request_count())
+ eq(content, r(buffer))
- p:resolve("success", "function()\n return 42\nend")
- test_utils.next_frame()
+ p:resolve("success", "function()\n return 42\nend")
+ test_utils.next_frame()
- local expected_state = {
- "",
- "local foo = function()",
- " return 42",
- "end",
- }
- eq(expected_state, r(buffer))
- eq(0, state:active_request_count())
- end)
+ local expected_state = {
+ "",
+ "local foo = function()",
+ " return 42",
+ "end",
+ }
+ eq(expected_state, r(buffer))
+ eq(0, state:active_request_count())
+ end)
- it("should test a typescript file", function()
- local ts_content = {
- "",
- "const foo = function() {}",
- }
- local p, buffer = setup(ts_content, 2, 12, "typescript")
- local state = _99.__get_state()
+ it("should test a typescript file", function()
+ local ts_content = {
+ "",
+ "const foo = function() {}",
+ }
+ local p, buffer = setup(ts_content, 2, 12, "typescript")
+ local state = _99.__get_state()
- print("TEST", vim.bo[buffer].ft)
+ _99.fill_in_function()
- _99.fill_in_function()
+ eq(1, state:active_request_count())
+ eq(ts_content, r(buffer))
- eq(1, state:active_request_count())
- eq(ts_content, r(buffer))
+ p:resolve("success", "function() {\n return 42;\n}")
+ test_utils.next_frame()
- p:resolve("success", "function() {\n return 42;\n}")
- test_utils.next_frame()
+ local expected_state = {
+ "",
+ "const foo = function() {",
+ " return 42;",
+ "}",
+ }
+ eq(expected_state, r(buffer))
+ eq(0, state:active_request_count())
+ end)
- local expected_state = {
- "",
- "const foo = function() {",
- " return 42;",
- "}",
- }
- eq(expected_state, r(buffer))
- eq(0, state:active_request_count())
- end)
+ it("should cancel request when stop_all_requests is called", function()
+ local p, buffer = setup(content, 2, 12)
+ _99.fill_in_function()
- it("should cancel request when stop_all_requests is called", function()
- local p, buffer = setup(content, 2, 12)
- _99.fill_in_function()
+ eq(content, r(buffer))
- eq(content, r(buffer))
+ assert.is_false(p.request.request:is_cancelled())
+ assert.is_not_nil(p.request)
+ assert.is_not_nil(p.request.request)
- assert.is_false(p.request.request:is_cancelled())
- assert.is_not_nil(p.request)
- assert.is_not_nil(p.request.request)
+ _99.stop_all_requests()
+ test_utils.next_frame()
- _99.stop_all_requests()
- test_utils.next_frame()
+ assert.is_true(p.request.request:is_cancelled())
- assert.is_true(p.request.request:is_cancelled())
+ p:resolve("success", "function foo()\n return 42\nend")
+ test_utils.next_frame()
- p:resolve("success", "function foo()\n return 42\nend")
- test_utils.next_frame()
+ eq(content, r(buffer))
+ end)
- eq(content, r(buffer))
- end)
+ it("should handle error cases with graceful failures", function()
+ local p, buffer = setup(content, 2, 12)
+ _99.fill_in_function()
- it("should handle error cases with graceful failures", function()
- local p, buffer = setup(content, 2, 12)
- _99.fill_in_function()
+ eq(content, r(buffer))
- eq(content, r(buffer))
+ p:resolve("failed", "Something went wrong")
+ test_utils.next_frame()
- p:resolve("failed", "Something went wrong")
- test_utils.next_frame()
-
- eq(content, r(buffer))
- end)
+ eq(content, r(buffer))
+ end)
end)