diff options
| author | theprimeagain <the.primeagen@gmail.com> | 2026-02-04 08:00:14 -0700 |
|---|---|---|
| committer | theprimeagain <the.primeagen@gmail.com> | 2026-02-04 08:00:14 -0700 |
| commit | 2f4af49b387a3f356fb94b657d506d3dd1ebfcf0 (patch) | |
| tree | a39188a4db07a4080d2cbe573fdba9aedcc7b29a /lua/99/test | |
| parent | 784926514bde856d60605c0b0dcfe6d0b7a876b3 (diff) | |
| download | a4-2f4af49b387a3f356fb94b657d506d3dd1ebfcf0.tar.xz a4-2f4af49b387a3f356fb94b657d506d3dd1ebfcf0.zip | |
moved typescript to its own file to follow style
Diffstat (limited to 'lua/99/test')
| -rw-r--r-- | lua/99/test/fill_in_function.typescript_spec.lua | 33 | ||||
| -rw-r--r-- | lua/99/test/fill_in_function_spec.lua | 26 | ||||
| -rw-r--r-- | lua/99/test/test_utils.lua | 27 |
3 files changed, 60 insertions, 26 deletions
diff --git a/lua/99/test/fill_in_function.typescript_spec.lua b/lua/99/test/fill_in_function.typescript_spec.lua new file mode 100644 index 0000000..0586a9c --- /dev/null +++ b/lua/99/test/fill_in_function.typescript_spec.lua @@ -0,0 +1,33 @@ +-- luacheck: globals describe it assert +local _99 = require("99") +local test_utils = require("99.test.test_utils") +---@diagnostic disable-next-line: undefined-field +local eq = assert.are.same + +describe("typescript", function() + it("should test a typescript file", function() + local ts_content = { + "", + "const foo = function() {}", + } + local p, buffer = test_utils.fif_setup(ts_content, 2, 12, "typescript") + local state = _99.__get_state() + + _99.fill_in_function() + + eq(1, state:active_request_count()) + eq(ts_content, test_utils.r(buffer)) + + p:resolve("success", "function() {\n return 42;\n}") + test_utils.next_frame() + + local expected_state = { + "", + "const foo = function() {", + " return 42;", + "}", + } + eq(expected_state, test_utils.r(buffer)) + eq(0, state:active_request_count()) + end) +end) diff --git a/lua/99/test/fill_in_function_spec.lua b/lua/99/test/fill_in_function_spec.lua index c4b00fb..46eac51 100644 --- a/lua/99/test/fill_in_function_spec.lua +++ b/lua/99/test/fill_in_function_spec.lua @@ -58,32 +58,6 @@ describe("fill_in_function", function() 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() - - _99.fill_in_function() - - eq(1, state:active_request_count()) - eq(ts_content, r(buffer)) - - 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) - it("should cancel request when stop_all_requests is called", function() local p, buffer = setup(content, 2, 12) _99.fill_in_function() diff --git a/lua/99/test/test_utils.lua b/lua/99/test/test_utils.lua index efcbe63..b3bd7db 100644 --- a/lua/99/test/test_utils.lua +++ b/lua/99/test/test_utils.lua @@ -1,3 +1,4 @@ +local Levels = require("99.logger.level") local M = {} function M.next_frame() @@ -103,4 +104,30 @@ function M.create_file(contents, file_type, row, col) return bufnr end +--- @param content string[] +--- @param row number +--- @param col number +--- @param lang string? +--- @return _99.test.Provider, number +function M.fif_setup(content, row, col, lang) + assert(lang, "lang must be provided") + local provider = M.TestProvider.new() + require("99").setup({ + provider = provider, + logger = { + error_cache_level = Levels.ERROR, + type = "print", + }, + }) + + local buffer = M.create_file(content, lang, row, col) + return provider, buffer +end + +--- @param buffer number +--- @return string[] +function M.r(buffer) + return vim.api.nvim_buf_get_lines(buffer, 0, -1, false) +end + return M |
