Skip to content

Commit

Permalink
Tests Neovim commands correctly calls Lua functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cuducos committed Nov 5, 2023
1 parent 04bb793 commit 227b911
Showing 1 changed file with 46 additions and 21 deletions.
67 changes: 46 additions & 21 deletions tests/yaml_nvim/commands_spec.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,65 @@
describe("commands", function()
local stub = require("luassert.stub")

describe("Neovim commands:", function()
before_each(function()
vim.cmd(":e tests/sample.yaml")
require("yaml_nvim")
vim.cmd("set ft=yaml")
end)

after_each(function()
vim.cmd(":bw!")
end)

it("yanks key to the default register", function()
vim.cmd(":YAMLYankKey")
assert.are.equal(vim.fn.getreg('"'), "worldcup")
it("YAMLView calls Lua function", function()
local view = stub(require("yaml_nvim"), "view")
vim.cmd("YAMLView")
assert.stub(view).was_called_with()
end)

it("yanks key to a custom register", function()
vim.cmd(":YAMLYankKey 7")
assert.are.equal(vim.fn.getreg("7"), "worldcup")
it("YAMLYank calls Lua function for default register", function()
local yank = stub(require("yaml_nvim"), "yank")
vim.cmd("YAMLYank")
assert.stub(yank).was_called_with()
end)

it("yanks value to the default register", function()
require("yaml_nvim")
it("YAMLYank calls Lua function for custom register", function()
local yank = stub(require("yaml_nvim"), "yank")
vim.cmd("YAMLYank 8")
assert.stub(yank).was_called_with("8")
end)

vim.cmd(":e sample.yaml")
vim.cmd("norm 10j")
vim.cmd(":YAMLYankValue")
it("YAMLYankKey calls Lua function for default register", function()
local yank_key = stub(require("yaml_nvim"), "yank_key")
vim.cmd("YAMLYankKey")
assert.stub(yank_key).was_called_with()
end)

assert(vim.fn.getreg('"'), "7")
it("YAMLYankKey calls Lua function for custom register", function()
local yank_key = stub(require("yaml_nvim"), "yank_key")
vim.cmd("YAMLYankKey 8")
assert.stub(yank_key).was_called_with("8")
end)

it("yanks value to a custom register", function()
require("yaml_nvim")
it("YAMLYankValue calls Lua function for default register", function()
local yank_value = stub(require("yaml_nvim"), "yank_value")
vim.cmd("YAMLYankValue")
assert.stub(yank_value).was_called_with()
end)

vim.cmd(":e sample.yaml")
vim.cmd("norm 10j")
vim.cmd(":YAMLYankValue 7")
it("YAMLYankValue calls Lua function for custom register", function()
local yank_value = stub(require("yaml_nvim"), "yank_value")
vim.cmd("YAMLYankValue 8")
assert.stub(yank_value).was_called_with("8")
end)

it("YAMLQuickfix calls Lua function", function()
local qf = stub(require("yaml_nvim"), "quickfix")
vim.cmd("YAMLQuickfix")
assert.stub(qf).was_called_with()
end)

assert(vim.fn.getreg("7"), "7")
it("YAMLTelescope calls Lua function", function()
local telescope = stub(require("yaml_nvim"), "telescope")
vim.cmd("YAMLTelescope")
assert.stub(telescope).was_called_with()
end)
end)

0 comments on commit 227b911

Please sign in to comment.