feat: rename
This commit is contained in:
parent
e1d7abf58e
commit
942438f817
21 changed files with 660 additions and 305 deletions
|
|
@ -6,32 +6,39 @@ describe('commands', function()
|
|||
end)
|
||||
|
||||
describe('setup', function()
|
||||
it('creates the :Render command', function()
|
||||
require('render.commands').setup()
|
||||
it('creates the :Preview command', function()
|
||||
require('preview.commands').setup()
|
||||
local cmds = vim.api.nvim_get_commands({})
|
||||
assert.is_not_nil(cmds.Render)
|
||||
assert.is_not_nil(cmds.Preview)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('dispatch', function()
|
||||
it('does not error on :Render with no provider', function()
|
||||
require('render.commands').setup()
|
||||
it('does not error on :Preview with no provider', function()
|
||||
require('preview.commands').setup()
|
||||
assert.has_no.errors(function()
|
||||
vim.cmd('Render compile')
|
||||
vim.cmd('Preview compile')
|
||||
end)
|
||||
end)
|
||||
|
||||
it('does not error on :Render stop', function()
|
||||
require('render.commands').setup()
|
||||
it('does not error on :Preview stop', function()
|
||||
require('preview.commands').setup()
|
||||
assert.has_no.errors(function()
|
||||
vim.cmd('Render stop')
|
||||
vim.cmd('Preview stop')
|
||||
end)
|
||||
end)
|
||||
|
||||
it('does not error on :Render status', function()
|
||||
require('render.commands').setup()
|
||||
it('does not error on :Preview status', function()
|
||||
require('preview.commands').setup()
|
||||
assert.has_no.errors(function()
|
||||
vim.cmd('Render status')
|
||||
vim.cmd('Preview status')
|
||||
end)
|
||||
end)
|
||||
|
||||
it('does not error on :Preview watch with no provider', function()
|
||||
require('preview.commands').setup()
|
||||
assert.has_no.errors(function()
|
||||
vim.cmd('Preview watch')
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -5,19 +5,19 @@ describe('compiler', function()
|
|||
|
||||
before_each(function()
|
||||
helpers.reset_config()
|
||||
compiler = require('render.compiler')
|
||||
compiler = require('preview.compiler')
|
||||
end)
|
||||
|
||||
describe('compile', function()
|
||||
it('spawns a process and tracks it in active table', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/render_test.txt')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test.txt')
|
||||
vim.bo[bufnr].modified = false
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
file = '/tmp/render_test.txt',
|
||||
file = '/tmp/preview_test.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
|
|
@ -35,14 +35,14 @@ describe('compiler', function()
|
|||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('fires RenderCompileStarted event', function()
|
||||
it('fires PreviewCompileStarted event', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/render_test_event.txt')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_event.txt')
|
||||
vim.bo[bufnr].modified = false
|
||||
|
||||
local fired = false
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'RenderCompileStarted',
|
||||
pattern = 'PreviewCompileStarted',
|
||||
once = true,
|
||||
callback = function()
|
||||
fired = true
|
||||
|
|
@ -52,7 +52,7 @@ describe('compiler', function()
|
|||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
file = '/tmp/render_test_event.txt',
|
||||
file = '/tmp/preview_test_event.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
|
|
@ -67,14 +67,14 @@ describe('compiler', function()
|
|||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('fires RenderCompileSuccess on exit code 0', function()
|
||||
it('fires PreviewCompileSuccess on exit code 0', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/render_test_success.txt')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_success.txt')
|
||||
vim.bo[bufnr].modified = false
|
||||
|
||||
local succeeded = false
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'RenderCompileSuccess',
|
||||
pattern = 'PreviewCompileSuccess',
|
||||
once = true,
|
||||
callback = function()
|
||||
succeeded = true
|
||||
|
|
@ -84,7 +84,7 @@ describe('compiler', function()
|
|||
local provider = { cmd = { 'true' } }
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
file = '/tmp/render_test_success.txt',
|
||||
file = '/tmp/preview_test_success.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
|
|
@ -99,14 +99,14 @@ describe('compiler', function()
|
|||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('fires RenderCompileFailed on non-zero exit', function()
|
||||
it('fires PreviewCompileFailed on non-zero exit', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/render_test_fail.txt')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_fail.txt')
|
||||
vim.bo[bufnr].modified = false
|
||||
|
||||
local failed = false
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'RenderCompileFailed',
|
||||
pattern = 'PreviewCompileFailed',
|
||||
once = true,
|
||||
callback = function()
|
||||
failed = true
|
||||
|
|
@ -116,7 +116,7 @@ describe('compiler', function()
|
|||
local provider = { cmd = { 'false' } }
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
file = '/tmp/render_test_fail.txt',
|
||||
file = '/tmp/preview_test_fail.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
|
|
@ -148,13 +148,13 @@ describe('compiler', function()
|
|||
|
||||
it('returns compiling during active process', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/render_test_status.txt')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_status.txt')
|
||||
vim.bo[bufnr].modified = false
|
||||
|
||||
local provider = { cmd = { 'sleep', '10' } }
|
||||
local ctx = {
|
||||
bufnr = bufnr,
|
||||
file = '/tmp/render_test_status.txt',
|
||||
file = '/tmp/preview_test_status.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
|
|
@ -173,4 +173,133 @@ describe('compiler', function()
|
|||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('watch', function()
|
||||
it('registers autocmd and tracks in watching table', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch.txt')
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx_builder = function(b)
|
||||
return { bufnr = b, file = '/tmp/preview_test_watch.txt', root = '/tmp', ft = 'text' }
|
||||
end
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
assert.is_not_nil(compiler._test.watching[bufnr])
|
||||
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('fires PreviewWatchStarted event', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_event.txt')
|
||||
|
||||
local fired = false
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'PreviewWatchStarted',
|
||||
once = true,
|
||||
callback = function()
|
||||
fired = true
|
||||
end,
|
||||
})
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx_builder = function(b)
|
||||
return { bufnr = b, file = '/tmp/preview_test_watch_event.txt', root = '/tmp', ft = 'text' }
|
||||
end
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
assert.is_true(fired)
|
||||
|
||||
compiler.unwatch(bufnr)
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('toggles off when called again', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_toggle.txt')
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx_builder = function(b)
|
||||
return { bufnr = b, file = '/tmp/preview_test_watch_toggle.txt', root = '/tmp', ft = 'text' }
|
||||
end
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
assert.is_not_nil(compiler._test.watching[bufnr])
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
assert.is_nil(compiler._test.watching[bufnr])
|
||||
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('fires PreviewWatchStopped on unwatch', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stop.txt')
|
||||
|
||||
local stopped = false
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'PreviewWatchStopped',
|
||||
once = true,
|
||||
callback = function()
|
||||
stopped = true
|
||||
end,
|
||||
})
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx_builder = function(b)
|
||||
return { bufnr = b, file = '/tmp/preview_test_watch_stop.txt', root = '/tmp', ft = 'text' }
|
||||
end
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
compiler.unwatch(bufnr)
|
||||
assert.is_true(stopped)
|
||||
assert.is_nil(compiler._test.watching[bufnr])
|
||||
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('stop_all clears watches', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stopall.txt')
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx_builder = function(b)
|
||||
return {
|
||||
bufnr = b,
|
||||
file = '/tmp/preview_test_watch_stopall.txt',
|
||||
root = '/tmp',
|
||||
ft = 'text',
|
||||
}
|
||||
end
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
assert.is_not_nil(compiler._test.watching[bufnr])
|
||||
|
||||
compiler.stop_all()
|
||||
assert.is_nil(compiler._test.watching[bufnr])
|
||||
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('status includes watching state', function()
|
||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_status.txt')
|
||||
|
||||
local s = compiler.status(bufnr)
|
||||
assert.is_false(s.watching)
|
||||
|
||||
local provider = { cmd = { 'echo', 'ok' } }
|
||||
local ctx_builder = function(b)
|
||||
return { bufnr = b, file = '/tmp/preview_test_watch_status.txt', root = '/tmp', ft = 'text' }
|
||||
end
|
||||
|
||||
compiler.watch(bufnr, 'echo', provider, ctx_builder)
|
||||
s = compiler.status(bufnr)
|
||||
assert.is_true(s.watching)
|
||||
|
||||
compiler.unwatch(bufnr)
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ describe('diagnostic', function()
|
|||
|
||||
before_each(function()
|
||||
helpers.reset_config()
|
||||
diagnostic = require('render.diagnostic')
|
||||
diagnostic = require('preview.diagnostic')
|
||||
end)
|
||||
|
||||
describe('clear', function()
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ function M.delete_buffer(bufnr)
|
|||
end
|
||||
|
||||
function M.reset_config(opts)
|
||||
vim.g.render = opts
|
||||
require('render')._test.reset()
|
||||
vim.g.preview = opts
|
||||
require('preview')._test.reset()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -1,30 +1,29 @@
|
|||
local helpers = require('spec.helpers')
|
||||
|
||||
describe('render', function()
|
||||
local render
|
||||
describe('preview', function()
|
||||
local preview
|
||||
|
||||
before_each(function()
|
||||
helpers.reset_config()
|
||||
render = require('render')
|
||||
preview = require('preview')
|
||||
end)
|
||||
|
||||
describe('config', function()
|
||||
it('accepts nil config', function()
|
||||
assert.has_no.errors(function()
|
||||
render.get_config()
|
||||
preview.get_config()
|
||||
end)
|
||||
end)
|
||||
|
||||
it('applies default values', function()
|
||||
local config = render.get_config()
|
||||
local config = preview.get_config()
|
||||
assert.is_false(config.debug)
|
||||
assert.are.same({}, config.providers)
|
||||
assert.are.same({}, config.providers_by_ft)
|
||||
end)
|
||||
|
||||
it('merges user config with defaults', function()
|
||||
helpers.reset_config({ debug = true })
|
||||
local config = require('render').get_config()
|
||||
local config = require('preview').get_config()
|
||||
assert.is_true(config.debug)
|
||||
assert.are.same({}, config.providers)
|
||||
end)
|
||||
|
|
@ -37,13 +36,9 @@ describe('render', function()
|
|||
args = { '%s' },
|
||||
},
|
||||
},
|
||||
providers_by_ft = {
|
||||
typst = 'typst',
|
||||
},
|
||||
})
|
||||
local config = require('render').get_config()
|
||||
local config = require('preview').get_config()
|
||||
assert.is_not_nil(config.providers.typst)
|
||||
assert.are.equal('typst', config.providers_by_ft.typst)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
|
@ -53,34 +48,20 @@ describe('render', function()
|
|||
providers = {
|
||||
typst = { cmd = { 'typst', 'compile' } },
|
||||
},
|
||||
providers_by_ft = {
|
||||
typst = 'typst',
|
||||
},
|
||||
})
|
||||
render = require('render')
|
||||
preview = require('preview')
|
||||
end)
|
||||
|
||||
it('returns provider name for mapped filetype', function()
|
||||
it('returns filetype when provider exists', function()
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
local name = render.resolve_provider(bufnr)
|
||||
local name = preview.resolve_provider(bufnr)
|
||||
assert.are.equal('typst', name)
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('returns nil for unmapped filetype', function()
|
||||
it('returns nil for unconfigured filetype', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local name = render.resolve_provider(bufnr)
|
||||
assert.is_nil(name)
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('returns nil when provider name maps to missing config', function()
|
||||
helpers.reset_config({
|
||||
providers = {},
|
||||
providers_by_ft = { typst = 'typst' },
|
||||
})
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
local name = require('render').resolve_provider(bufnr)
|
||||
local name = preview.resolve_provider(bufnr)
|
||||
assert.is_nil(name)
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
|
@ -89,7 +70,7 @@ describe('render', function()
|
|||
describe('build_context', function()
|
||||
it('builds context from buffer', function()
|
||||
local bufnr = helpers.create_buffer({}, 'typst')
|
||||
local ctx = render.build_context(bufnr)
|
||||
local ctx = preview.build_context(bufnr)
|
||||
assert.are.equal(bufnr, ctx.bufnr)
|
||||
assert.are.equal('typst', ctx.ft)
|
||||
assert.is_string(ctx.file)
|
||||
|
|
@ -101,7 +82,7 @@ describe('render', function()
|
|||
describe('status', function()
|
||||
it('returns idle when nothing is compiling', function()
|
||||
local bufnr = helpers.create_buffer({})
|
||||
local s = render.status(bufnr)
|
||||
local s = preview.status(bufnr)
|
||||
assert.is_false(s.compiling)
|
||||
assert.is_nil(s.provider)
|
||||
helpers.delete_buffer(bufnr)
|
||||
|
|
|
|||
88
spec/presets_spec.lua
Normal file
88
spec/presets_spec.lua
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
describe('presets', function()
|
||||
local presets
|
||||
|
||||
before_each(function()
|
||||
presets = require('preview.presets')
|
||||
end)
|
||||
|
||||
local ctx = {
|
||||
bufnr = 1,
|
||||
file = '/tmp/document.typ',
|
||||
root = '/tmp',
|
||||
ft = 'typst',
|
||||
}
|
||||
|
||||
describe('typst', function()
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'typst', 'compile' }, presets.typst.cmd)
|
||||
end)
|
||||
|
||||
it('returns args with file path', function()
|
||||
local args = presets.typst.args(ctx)
|
||||
assert.is_table(args)
|
||||
assert.are.same({ '/tmp/document.typ' }, args)
|
||||
end)
|
||||
|
||||
it('returns pdf output path', function()
|
||||
local output = presets.typst.output(ctx)
|
||||
assert.is_string(output)
|
||||
assert.are.equal('/tmp/document.pdf', output)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('latex', function()
|
||||
local tex_ctx = {
|
||||
bufnr = 1,
|
||||
file = '/tmp/document.tex',
|
||||
root = '/tmp',
|
||||
ft = 'tex',
|
||||
}
|
||||
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'latexmk' }, presets.latex.cmd)
|
||||
end)
|
||||
|
||||
it('returns args with pdf flag and file path', function()
|
||||
local args = presets.latex.args(tex_ctx)
|
||||
assert.is_table(args)
|
||||
assert.are.same({ '-pdf', '-interaction=nonstopmode', '/tmp/document.tex' }, args)
|
||||
end)
|
||||
|
||||
it('returns pdf output path', function()
|
||||
local output = presets.latex.output(tex_ctx)
|
||||
assert.is_string(output)
|
||||
assert.are.equal('/tmp/document.pdf', output)
|
||||
end)
|
||||
|
||||
it('returns clean command', function()
|
||||
local clean = presets.latex.clean(tex_ctx)
|
||||
assert.is_table(clean)
|
||||
assert.are.same({ 'latexmk', '-c', '/tmp/document.tex' }, clean)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('markdown', function()
|
||||
local md_ctx = {
|
||||
bufnr = 1,
|
||||
file = '/tmp/document.md',
|
||||
root = '/tmp',
|
||||
ft = 'markdown',
|
||||
}
|
||||
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'pandoc' }, presets.markdown.cmd)
|
||||
end)
|
||||
|
||||
it('returns args with file and output flag', function()
|
||||
local args = presets.markdown.args(md_ctx)
|
||||
assert.is_table(args)
|
||||
assert.are.same({ '/tmp/document.md', '-o', '/tmp/document.pdf' }, args)
|
||||
end)
|
||||
|
||||
it('returns pdf output path', function()
|
||||
local output = presets.markdown.output(md_ctx)
|
||||
assert.is_string(output)
|
||||
assert.are.equal('/tmp/document.pdf', output)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue