aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/ui_spec.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-11 16:31:50 +0200
committerWilliam Boman <william@redwill.se>2025-02-19 09:22:40 +0100
commit047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc (patch)
treec50c22cd05d3605fc5a1e8eb902ffeb11e339697 /tests/mason-core/ui_spec.lua
parentrefactor(receipt): change receipt structure and remove old builder APIs (#1521) (diff)
downloadmason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.gz
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.bz2
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.lz
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.xz
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.zst
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.zip
refactor!: refactor installer internals and add new Package class methods (#1523)
This contains the following changes: 1) `Package:install()` now accepts a second, optional, callback argument which is called when installation finishes (successfully or not). 2) Adds a `Package:is_installing()` method. This contains the following breaking changes: 1) `Package:install()` will now error when called while an installation is already ongoing. Use the new `Package:is_installing()` method to check whether an installation is already running. This also refactors large portions of the tests by removing test globals, removing async_test, and adding the `mason-test` Lua module instead. Test helpers via globals are problematic to work with due to not being detected through tools like the Lua language server without additional configuration. This has been replaced with a Lua module `mason-test`. `async_test` has also been removed in favour of explicitly making use of the `mason-core.async` API. These changes stands for a significant portion of the diff.
Diffstat (limited to 'tests/mason-core/ui_spec.lua')
-rw-r--r--tests/mason-core/ui_spec.lua308
1 files changed, 149 insertions, 159 deletions
diff --git a/tests/mason-core/ui_spec.lua b/tests/mason-core/ui_spec.lua
index 17087045..efd60712 100644
--- a/tests/mason-core/ui_spec.lua
+++ b/tests/mason-core/ui_spec.lua
@@ -142,187 +142,177 @@ describe("ui", function()
end)
describe("integration test", function()
- it(
- "calls vim APIs as expected during rendering",
- async_test(function()
- local window = display.new_view_only_win("test", "my-filetype")
+ it("calls vim APIs as expected during rendering", function()
+ local window = display.new_view_only_win("test", "my-filetype")
- 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.state { 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.keymap, "set")
-
- window.init {
- effects = {
- ["EFFECT"] = function() end,
- ["R_EFFECT"] = function() end,
+ window.view(function(state)
+ return Ui.Node {
+ Ui.Keybind("U", "EFFECT", nil, true),
+ Ui.Text {
+ "Line number 1!",
+ state.text,
},
- winhighlight = {
- "NormalFloat:MasonNormal",
- "CursorLine:MasonCursorLine",
+ Ui.Keybind("R", "R_EFFECT", { state.text }),
+ Ui.HlTextNode {
+ {
+ { "My highlighted text", "MyHighlightGroup" },
+ },
},
}
- window.open()
+ end)
- -- Initial window and buffer creation + initial render
- a.wait(vim.schedule)
+ local mutate_state = window.state { text = "Initial state" }
- assert.spy(win_set_option).was_called(9)
- 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(win_set_option)
- .was_called_with(match.is_number(), "winhighlight", "NormalFloat:MasonNormal,CursorLine:MasonCursorLine")
+ 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.keymap, "set")
- assert.spy(buf_set_option).was_called(10)
- 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", "my-filetype")
- assert.spy(buf_set_option).was_called_with(match.is_number(), "undolevels", -1)
+ window.init {
+ effects = {
+ ["EFFECT"] = function() end,
+ ["R_EFFECT"] = function() end,
+ },
+ winhighlight = {
+ "NormalFloat:MasonNormal",
+ "CursorLine:MasonCursorLine",
+ },
+ }
+ window.open()
- 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" })
+ -- Initial window and buffer creation + initial render
+ a.run_blocking(a.wait, vim.schedule)
- assert.spy(set_extmark).was_called(0)
+ assert.spy(win_set_option).was_called(9)
+ 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(win_set_option)
+ .was_called_with(match.is_number(), "winhighlight", "NormalFloat:MasonNormal,CursorLine:MasonCursorLine")
- 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(buf_set_option).was_called(10)
+ 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", "my-filetype")
+ assert.spy(buf_set_option).was_called_with(match.is_number(), "undolevels", -1)
- assert.spy(set_keymap).was_called(2)
- assert.spy(set_keymap).was_called_with(
- "n",
- "U",
- match.is_function(),
- match.tbl_containing { nowait = true, silent = true, buffer = match.is_number() }
- )
- assert.spy(set_keymap).was_called_with(
- "n",
- "R",
- match.is_function(),
- match.tbl_containing { nowait = true, silent = true, buffer = match.is_number() }
- )
+ 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(clear_namespace).was_called(1)
- assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1)
+ assert.spy(set_extmark).was_called(0)
- mutate_state(function(state)
- state.text = "New state"
- end)
+ 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_lines).was_called(1)
- a.wait(vim.schedule)
- assert.spy(set_lines).was_called(2)
+ assert.spy(set_keymap).was_called(2)
+ assert.spy(set_keymap).was_called_with(
+ "n",
+ "U",
+ match.is_function(),
+ match.tbl_containing { nowait = true, silent = true, buffer = match.is_number() }
+ )
+ assert.spy(set_keymap).was_called_with(
+ "n",
+ "R",
+ match.is_function(),
+ match.tbl_containing { nowait = true, silent = true, buffer = match.is_number() }
+ )
+
+ 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_with(match.is_number(), 0, -1, false, { "Line number 1!", "New state", "My highlighted text" })
+ mutate_state(function(state)
+ state.text = "New state"
end)
- )
- it(
- "anchors to sticky cursor",
- async_test(function()
- local window = display.new_view_only_win("test", "my-filetype")
- window.view(function(state)
- local extra_lines = state.show_extra_lines
- and Ui.Text {
- "More",
- "Lines",
- "Here",
- }
- or Ui.Node {}
- return Ui.Node {
- extra_lines,
- Ui.Text {
- "Line 1",
- "Line 2",
- "Line 3",
- "Line 4",
- "Special line",
- },
- Ui.StickyCursor { id = "special" },
- Ui.Text {
- "Line 6",
- "Line 7",
- "Line 8",
- "Line 9",
- "Line 10",
- },
- }
- end)
- local mutate_state = window.state { show_extra_lines = false }
- window.init {}
- window.open()
- a.wait(vim.schedule)
- window.set_cursor { 5, 3 } -- move cursor to sticky line
- mutate_state(function(state)
- state.show_extra_lines = true
- end)
- a.wait(vim.schedule)
- local cursor = window.get_cursor()
- assert.same({ 8, 3 }, cursor)
+ assert.spy(set_lines).was_called(1)
+ a.run_blocking(a.wait, vim.schedule)
+ 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)
+
+ it("anchors to sticky cursor", function()
+ local window = display.new_view_only_win("test", "my-filetype")
+ window.view(function(state)
+ local extra_lines = state.show_extra_lines
+ and Ui.Text {
+ "More",
+ "Lines",
+ "Here",
+ }
+ or Ui.Node {}
+ return Ui.Node {
+ extra_lines,
+ Ui.Text {
+ "Line 1",
+ "Line 2",
+ "Line 3",
+ "Line 4",
+ "Special line",
+ },
+ Ui.StickyCursor { id = "special" },
+ Ui.Text {
+ "Line 6",
+ "Line 7",
+ "Line 8",
+ "Line 9",
+ "Line 10",
+ },
+ }
end)
- )
- it(
- "should respect border ui setting",
- async_test(function()
- local nvim_open_win = spy.on(vim.api, "nvim_open_win")
+ local mutate_state = window.state { show_extra_lines = false }
+ window.init {}
+ window.open()
+ a.run_blocking(a.wait, vim.schedule)
+ window.set_cursor { 5, 3 } -- move cursor to sticky line
+ mutate_state(function(state)
+ state.show_extra_lines = true
+ end)
+ a.run_blocking(a.wait, vim.schedule)
+ local cursor = window.get_cursor()
+ assert.same({ 8, 3 }, cursor)
+ end)
- local window = display.new_view_only_win("test", "my-filetype")
- window.view(function()
- return Ui.Node {}
- end)
- window.state {}
- window.init { border = "rounded" }
- window.open()
- a.wait(vim.schedule)
+ it("should respect border ui setting", function()
+ local nvim_open_win = spy.on(vim.api, "nvim_open_win")
- assert.spy(nvim_open_win).was_called(1)
- assert.spy(nvim_open_win).was_called_with(
- match.is_number(),
- true,
- match.tbl_containing {
- border = "rounded",
- }
- )
+ local window = display.new_view_only_win("test", "my-filetype")
+ window.view(function()
+ return Ui.Node {}
end)
- )
+ window.state {}
+ window.init { border = "rounded" }
+ window.open()
+ a.run_blocking(a.wait, vim.schedule)
+
+ assert.spy(nvim_open_win).was_called(1)
+ assert.spy(nvim_open_win).was_called_with(
+ match.is_number(),
+ true,
+ match.tbl_containing {
+ border = "rounded",
+ }
+ )
+ end)
it("should not apply cascading styles to empty lines", function()
local render_output = display._render_node(