test(tohtml): simplify font test

This commit is contained in:
Justin M. Keyes
2024-09-08 12:15:13 +02:00
parent e37404f7fe
commit 95b65a7554

View File

@@ -137,27 +137,26 @@ local function run_tohtml_and_assert(screen, func)
end end
---@param guifont boolean ---@param guifont boolean
local function test_generates_html(guifont) local function test_generates_html(guifont, expect_font)
insert([[line]]) insert([[line]])
exec('set termguicolors') exec('set termguicolors')
local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui') local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui')
local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui') local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui')
if guifont then local tmpfile = t.tmpname()
exec_lua [[
vim.o.guifont="Font,Escape\\,comma, Ignore space after comma" exec_lua(
local outfile = vim.fn.tempname() .. '.html' [[
local html = require('tohtml').tohtml(0,{title="title"}) local guifont, outfile = ...
vim.fn.writefile(html, outfile) local html = (guifont
vim.cmd.split(outfile) and require('tohtml').tohtml(0,{title="title"})
]] or require('tohtml').tohtml(0,{title="title",font={ "dumyfont","anotherfont" }}))
else vim.fn.writefile(html, outfile)
exec_lua [[ vim.cmd.split(outfile)
local outfile = vim.fn.tempname() .. '.html' ]],
local html = require('tohtml').tohtml(0,{title="title",font={ "dumyfont","anotherfont" }}) guifont,
vim.fn.writefile(html, outfile) tmpfile
vim.cmd.split(outfile) )
]]
end
local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf()) local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf())
eq({ eq({
'<!DOCTYPE html>', '<!DOCTYPE html>',
@@ -167,9 +166,7 @@ local function test_generates_html(guifont)
'<title>title</title>', '<title>title</title>',
('<meta name="colorscheme" content="%s"></meta>'):format(api.nvim_get_var('colors_name')), ('<meta name="colorscheme" content="%s"></meta>'):format(api.nvim_get_var('colors_name')),
'<style>', '<style>',
('* {font-family: %s,monospace}'):format( ('* {font-family: %s,monospace}'):format(expect_font),
guifont and '"Font","Escape,comma","Ignore space after comma"' or '"dumyfont","anotherfont"'
),
('body {background-color: %s; color: %s}'):format(bg, fg), ('body {background-color: %s; color: %s}'):format(bg, fg),
'</style>', '</style>',
'</head>', '</head>',
@@ -193,15 +190,16 @@ describe(':TOhtml', function()
exec('colorscheme default') exec('colorscheme default')
end) end)
it('generates html', function() it('generates html with given font', function()
test_generates_html(false) test_generates_html(false, '"dumyfont","anotherfont"')
end) end)
it("generates html, respects 'guifont'", function() it("generates html, respects 'guifont'", function()
test_generates_html(true) exec_lua [[vim.o.guifont='Font,Escape\\,comma, Ignore space after comma']]
test_generates_html(true, '"Font","Escape,comma","Ignore space after comma"')
end) end)
it('expected internal html generated from range', function() it('generates html from range', function()
insert([[ insert([[
line1 line1
line2 line2
@@ -239,7 +237,7 @@ describe(':TOhtml', function()
}, fn.readfile(out_file)) }, fn.readfile(out_file))
end) end)
it('highlight attributes generated', function() it('generates highlight attributes', function()
--Make sure to uncomment the attribute in `html_syntax_match()` --Make sure to uncomment the attribute in `html_syntax_match()`
exec('hi LINE guisp=#00ff00 gui=' .. table.concat({ exec('hi LINE guisp=#00ff00 gui=' .. table.concat({
'bold', 'bold',