diff options
| author | William Boman <william@redwill.se> | 2022-02-21 20:56:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-21 20:56:16 +0100 |
| commit | 12d97eeabf44c2dd2cf841db218aac449022143d (patch) | |
| tree | 5c8b996a262761ae2433663351861e505dbceb8d /tests/ui_spec.lua | |
| parent | run autogen_metadata.lua (diff) | |
| download | mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.gz mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.bz2 mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.lz mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.xz mason-12d97eeabf44c2dd2cf841db218aac449022143d.tar.zst mason-12d97eeabf44c2dd2cf841db218aac449022143d.zip | |
feat: add async module (#499)
Diffstat (limited to 'tests/ui_spec.lua')
| -rw-r--r-- | tests/ui_spec.lua | 198 |
1 files changed, 104 insertions, 94 deletions
diff --git a/tests/ui_spec.lua b/tests/ui_spec.lua index df771a4d..0c075eef 100644 --- a/tests/ui_spec.lua +++ b/tests/ui_spec.lua @@ -2,7 +2,7 @@ local display = require "nvim-lsp-installer.ui.display" local match = require "luassert.match" local spy = require "luassert.spy" local Ui = require "nvim-lsp-installer.ui" -local a = require "plenary.async" +local a = require "nvim-lsp-installer.core.async" describe("ui", function() it("produces a correct tree", function() @@ -136,114 +136,124 @@ describe("ui", function() end) describe("integration test", function() - a.tests.it("calls vim APIs as expected during rendering", function() - local window = display.new_view_only_win "test" + it( + "calls vim APIs as expected during rendering", + async_test(function() + local window = display.new_view_only_win "test" - window.view(function(state) - return Ui.Node { - Ui.Keybind("U", "EFFECT", nil, true), - Ui.Text { - "Line number 1!", - state.text, - }, - Ui.Keybind("R", "R_EFFECT", { state.text }), - Ui.HlTextNode { - { - { "My highlighted text", "MyHighlightGroup" }, + window.view(function(state) + return Ui.Node { + Ui.Keybind("U", "EFFECT", nil, true), + Ui.Text { + "Line number 1!", + state.text, + }, + Ui.Keybind("R", "R_EFFECT", { state.text }), + Ui.HlTextNode { + { + { "My highlighted text", "MyHighlightGroup" }, + }, }, + } + end) + + local mutate_state = window.init { text = "Initial state" } + + window.open { + effects = { + ["EFFECT"] = function() end, + ["R_EFFECT"] = function() end, + }, + highlight_groups = { + "hi def MyHighlight gui=bold", }, } - end) - local mutate_state = window.init { text = "Initial state" } + local clear_namespace = spy.on(vim.api, "nvim_buf_clear_namespace") + local buf_set_option = spy.on(vim.api, "nvim_buf_set_option") + local win_set_option = spy.on(vim.api, "nvim_win_set_option") + local set_lines = spy.on(vim.api, "nvim_buf_set_lines") + local set_extmark = spy.on(vim.api, "nvim_buf_set_extmark") + local add_highlight = spy.on(vim.api, "nvim_buf_add_highlight") + local set_keymap = spy.on(vim.api, "nvim_buf_set_keymap") - window.open { - effects = { - ["EFFECT"] = function() end, - ["R_EFFECT"] = function() end, - }, - highlight_groups = { - "hi def MyHighlight gui=bold", - }, - } + -- Initial window and buffer creation + initial render + a.scheduler() - local clear_namespace = spy.on(vim.api, "nvim_buf_clear_namespace") - local buf_set_option = spy.on(vim.api, "nvim_buf_set_option") - local win_set_option = spy.on(vim.api, "nvim_win_set_option") - local set_lines = spy.on(vim.api, "nvim_buf_set_lines") - local set_extmark = spy.on(vim.api, "nvim_buf_set_extmark") - local add_highlight = spy.on(vim.api, "nvim_buf_add_highlight") - local set_keymap = spy.on(vim.api, "nvim_buf_set_keymap") + assert.spy(win_set_option).was_called(8) + assert.spy(win_set_option).was_called_with(match.is_number(), "number", false) + assert.spy(win_set_option).was_called_with(match.is_number(), "relativenumber", false) + assert.spy(win_set_option).was_called_with(match.is_number(), "wrap", false) + assert.spy(win_set_option).was_called_with(match.is_number(), "spell", false) + assert.spy(win_set_option).was_called_with(match.is_number(), "foldenable", false) + assert.spy(win_set_option).was_called_with(match.is_number(), "signcolumn", "no") + assert.spy(win_set_option).was_called_with(match.is_number(), "colorcolumn", "") + assert.spy(win_set_option).was_called_with(match.is_number(), "cursorline", true) - -- Initial window and buffer creation + initial render - a.util.scheduler() + assert.spy(buf_set_option).was_called(9) + assert.spy(buf_set_option).was_called_with(match.is_number(), "modifiable", false) + assert.spy(buf_set_option).was_called_with(match.is_number(), "swapfile", false) + assert.spy(buf_set_option).was_called_with(match.is_number(), "textwidth", 0) + assert.spy(buf_set_option).was_called_with(match.is_number(), "buftype", "nofile") + assert.spy(buf_set_option).was_called_with(match.is_number(), "bufhidden", "wipe") + assert.spy(buf_set_option).was_called_with(match.is_number(), "buflisted", false) + assert.spy(buf_set_option).was_called_with(match.is_number(), "filetype", "lsp-installer") - assert.spy(win_set_option).was_called(8) - assert.spy(win_set_option).was_called_with(match.is_number(), "number", false) - assert.spy(win_set_option).was_called_with(match.is_number(), "relativenumber", false) - assert.spy(win_set_option).was_called_with(match.is_number(), "wrap", false) - assert.spy(win_set_option).was_called_with(match.is_number(), "spell", false) - assert.spy(win_set_option).was_called_with(match.is_number(), "foldenable", false) - assert.spy(win_set_option).was_called_with(match.is_number(), "signcolumn", "no") - assert.spy(win_set_option).was_called_with(match.is_number(), "colorcolumn", "") - assert.spy(win_set_option).was_called_with(match.is_number(), "cursorline", true) + assert.spy(set_lines).was_called(1) + assert.spy(set_lines).was_called_with( + match.is_number(), + 0, + -1, + false, + { "Line number 1!", "Initial state", "My highlighted text" } + ) - assert.spy(buf_set_option).was_called(9) - assert.spy(buf_set_option).was_called_with(match.is_number(), "modifiable", false) - assert.spy(buf_set_option).was_called_with(match.is_number(), "swapfile", false) - assert.spy(buf_set_option).was_called_with(match.is_number(), "textwidth", 0) - assert.spy(buf_set_option).was_called_with(match.is_number(), "buftype", "nofile") - assert.spy(buf_set_option).was_called_with(match.is_number(), "bufhidden", "wipe") - assert.spy(buf_set_option).was_called_with(match.is_number(), "buflisted", false) - assert.spy(buf_set_option).was_called_with(match.is_number(), "filetype", "lsp-installer") + assert.spy(set_extmark).was_called(0) - assert.spy(set_lines).was_called(1) - assert.spy(set_lines).was_called_with( - match.is_number(), - 0, - -1, - false, - { "Line number 1!", "Initial state", "My highlighted text" } - ) + assert.spy(add_highlight).was_called(1) + assert.spy(add_highlight).was_called_with( + match.is_number(), + match.is_number(), + "MyHighlightGroup", + 2, + 0, + 19 + ) - assert.spy(set_extmark).was_called(0) + assert.spy(set_keymap).was_called(2) + assert.spy(set_keymap).was_called_with( + match.is_number(), + "n", + "U", + match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "55"%)<cr>]], + { nowait = true, silent = true, noremap = true } + ) + assert.spy(set_keymap).was_called_with( + match.is_number(), + "n", + "R", + match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "52"%)<cr>]], + { nowait = true, silent = true, noremap = true } + ) - assert.spy(add_highlight).was_called(1) - assert.spy(add_highlight).was_called_with(match.is_number(), match.is_number(), "MyHighlightGroup", 2, 0, 19) + assert.spy(clear_namespace).was_called(1) + assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1) - assert.spy(set_keymap).was_called(2) - assert.spy(set_keymap).was_called_with( - match.is_number(), - "n", - "U", - match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "55"%)<cr>]], - { nowait = true, silent = true, noremap = true } - ) - assert.spy(set_keymap).was_called_with( - match.is_number(), - "n", - "R", - match.has_match [[<cmd>lua require%('nvim%-lsp%-installer%.ui%.display'%)%.dispatch_effect%(%d, "52"%)<cr>]], - { nowait = true, silent = true, noremap = true } - ) + mutate_state(function(state) + state.text = "New state" + end) - assert.spy(clear_namespace).was_called(1) - assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1) + assert.spy(set_lines).was_called(1) + a.scheduler() + assert.spy(set_lines).was_called(2) - mutate_state(function(state) - state.text = "New state" + assert.spy(set_lines).was_called_with( + match.is_number(), + 0, + -1, + false, + { "Line number 1!", "New state", "My highlighted text" } + ) end) - - assert.spy(set_lines).was_called(1) - a.util.scheduler() - assert.spy(set_lines).was_called(2) - - assert.spy(set_lines).was_called_with( - match.is_number(), - 0, - -1, - false, - { "Line number 1!", "New state", "My highlighted text" } - ) - end) + ) end) |
