preview.nvim/spec/presets_spec.lua
Barrett Ruth edfe3b6117
refactor(presets): replace xdg-open with vim.ui.open
Problem: all presets hardcoded `open = { 'xdg-open' }`, making them
Linux-only. The compiler already handles `open = true` via
`vim.ui.open()`, which is cross-platform.

Solution: change all four presets to `open = true`.
2026-03-03 13:33:13 -05:00

183 lines
4.6 KiB
Lua

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 ft', function()
assert.are.equal('typst', presets.typst.ft)
end)
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)
it('has open enabled', function()
assert.is_true(presets.typst.open)
end)
end)
describe('latex', function()
local tex_ctx = {
bufnr = 1,
file = '/tmp/document.tex',
root = '/tmp',
ft = 'tex',
}
it('has ft', function()
assert.are.equal('tex', presets.latex.ft)
end)
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)
it('has open enabled', function()
assert.is_true(presets.latex.open)
end)
end)
describe('markdown', function()
local md_ctx = {
bufnr = 1,
file = '/tmp/document.md',
root = '/tmp',
ft = 'markdown',
}
it('has ft', function()
assert.are.equal('markdown', presets.markdown.ft)
end)
it('has cmd', function()
assert.are.same({ 'pandoc' }, presets.markdown.cmd)
end)
it('returns args with standalone and embed-resources flags', function()
local args = presets.markdown.args(md_ctx)
assert.is_table(args)
assert.are.same(
{ '/tmp/document.md', '-s', '--embed-resources', '-o', '/tmp/document.html' },
args
)
end)
it('returns html output path', function()
local output = presets.markdown.output(md_ctx)
assert.is_string(output)
assert.are.equal('/tmp/document.html', output)
end)
it('returns clean command', function()
local clean = presets.markdown.clean(md_ctx)
assert.is_table(clean)
assert.are.same({ 'rm', '-f', '/tmp/document.html' }, clean)
end)
it('has open enabled', function()
assert.is_true(presets.markdown.open)
end)
end)
describe('github', function()
local md_ctx = {
bufnr = 1,
file = '/tmp/document.md',
root = '/tmp',
ft = 'markdown',
}
it('has ft', function()
assert.are.equal('markdown', presets.github.ft)
end)
it('has cmd', function()
assert.are.same({ 'pandoc' }, presets.github.cmd)
end)
it('returns args with standalone, embed-resources, and css flags', function()
local args = presets.github.args(md_ctx)
assert.is_table(args)
assert.are.same({
'-f',
'gfm',
'/tmp/document.md',
'-s',
'--embed-resources',
'--css',
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
'-o',
'/tmp/document.html',
}, args)
end)
it('args include -f and gfm flags', function()
local args = presets.github.args(md_ctx)
local idx = nil
for i, v in ipairs(args) do
if v == '-f' then
idx = i
break
end
end
assert.is_not_nil(idx)
assert.are.equal('gfm', args[idx + 1])
end)
it('returns html output path', function()
local output = presets.github.output(md_ctx)
assert.is_string(output)
assert.are.equal('/tmp/document.html', output)
end)
it('returns clean command', function()
local clean = presets.github.clean(md_ctx)
assert.is_table(clean)
assert.are.same({ 'rm', '-f', '/tmp/document.html' }, clean)
end)
it('has open enabled', function()
assert.is_true(presets.github.open)
end)
end)
end)