preview.nvim/spec/commands_spec.lua
Barrett Ruth cfe101c6c4
feat(commands): add :Preview open subcommand (#6)
Problem: after closing a viewer, there was no way to re-open the last
compiled output without recompiling.

Solution: track the most recent output file per buffer in a `last_output`
table that persists after compilation finishes. Add `compiler.open()`,
`M.open()`, and wire it into the command dispatch.
2026-03-03 13:37:02 -05:00

52 lines
1.3 KiB
Lua

local helpers = require('spec.helpers')
describe('commands', function()
before_each(function()
helpers.reset_config()
end)
describe('setup', function()
it('creates the :Preview command', function()
require('preview.commands').setup()
local cmds = vim.api.nvim_get_commands({})
assert.is_not_nil(cmds.Preview)
end)
end)
describe('dispatch', function()
it('does not error on :Preview with no provider', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview compile')
end)
end)
it('does not error on :Preview stop', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview stop')
end)
end)
it('does not error on :Preview status', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview status')
end)
end)
it('does not error on :Preview open', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview open')
end)
end)
it('does not error on :Preview toggle with no provider', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview toggle')
end)
end)
end)
end)