From 2f85bbe61513d12c746641fed6ad07559bd95719 Mon Sep 17 00:00:00 2001 From: altermo <107814000+altermo@users.noreply.github.com> Date: Mon, 26 Feb 2024 11:42:51 -0800 Subject: feat!: rewrite TOhtml in lua Co-authored-by: wookayin Co-authored-by: clason Co-authored-by: Lewis Russell --- test/functional/plugin/tohtml_spec.lua | 370 +++++++++++++++++++++++++++++++++ 1 file changed, 370 insertions(+) create mode 100644 test/functional/plugin/tohtml_spec.lua (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua new file mode 100644 index 0000000000..66dcfde3aa --- /dev/null +++ b/test/functional/plugin/tohtml_spec.lua @@ -0,0 +1,370 @@ +local Screen = require('test.functional.ui.screen') +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local exec = helpers.exec +local exec_lua = helpers.exec_lua +local eq = helpers.eq +local fn = helpers.fn +local api = helpers.api +local insert = helpers.insert + +local function html_syntax_match() + local styles = + vim.split(api.nvim_exec2([[/', + '', + '', + '
',
+      'line',
+      '',
+      '
', + '', + '', + }, fn.readfile(out_file)) + end) + + it('highlight attributes generated', function() + --Make sure to uncomment the attribute in `html_syntax_match()` + exec('hi LINE gui=' .. table.concat({ + 'bold', + 'underline', + 'italic', + 'strikethrough', + }, ',')) + exec('hi UNDERCURL gui=undercurl') + exec('syn keyword LINE line') + exec('syn keyword UNDERCURL undercurl') + insert('line\nundercurl') + run_tohtml_and_assert(screen) + end) + + it('syntax', function() + insert [[ + function main() + print("hello world") + end + ]] + exec('set termguicolors') + exec('syntax enable') + exec('setf lua') + run_tohtml_and_assert(screen) + end) + + it('diff', function() + exec('set diffopt=') + insert [[ + diffadd + nochage + diffchange1 + ]] + exec('new') + insert [[ + nochage + diffchange2 + diffremove + ]] + exec('set diff') + exec('close') + exec('set diff') + run_tohtml_and_assert(screen) + end) + + it('treesitter', function() + insert [[ + function main() + print("hello world") + end + ]] + exec('setf lua') + exec_lua('vim.treesitter.start()') + run_tohtml_and_assert(screen) + end) + + it('matchadd', function() + insert [[ + line + ]] + fn.matchadd('Visual', 'line') + run_tohtml_and_assert(screen) + end) + + describe('conceallevel', function() + local function run(level) + insert([[ + line0 + line1 + line2 + line3 + ]]) + local ns = api.nvim_create_namespace '' + fn.matchadd('Conceal', 'line1', 3, 5, { conceal = 'a' }) + api.nvim_buf_set_extmark(0, ns, 2, 0, { conceal = 'a', end_col = 5 }) + exec(':syntax match Conceal "line3" conceal cchar=a') + exec('set conceallevel=' .. level) + run_tohtml_and_assert(screen) + end + it('conceallevel=0', function() + run(0) + end) + it('conceallevel=1', function() + run(1) + end) + it('conceallevel=2', function() + run(2) + end) + it('conceallevel=3', function() + run(3) + end) + end) + + describe('extmarks', function() + it('virt_text', function() + insert [[ + line1 + line2 + line3 + line4 + ]] + local ns = api.nvim_create_namespace '' + api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'foo' } } }) + api.nvim_buf_set_extmark( + 0, + ns, + 1, + 0, + { virt_text = { { 'foo' } }, virt_text_pos = 'overlay' } + ) + api.nvim_buf_set_extmark(0, ns, 2, 0, { virt_text = { { 'foo' } }, virt_text_pos = 'inline' }) + --api.nvim_buf_set_extmark(0,ns,3,0,{virt_text={{'foo'}},virt_text_pos='right_align'}) + run_tohtml_and_assert(screen) + end) + it('highlgith', function() + insert [[ + line1 + ]] + local ns = api.nvim_create_namespace '' + api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 2, hl_group = 'Visual' }) + run_tohtml_and_assert(screen) + end) + it('virt_line', function() + insert [[ + line1 + line2 + ]] + local ns = api.nvim_create_namespace '' + api.nvim_buf_set_extmark(0, ns, 1, 0, { end_col = 2, virt_lines = { { { 'foo' } } } }) + run_tohtml_and_assert(screen) + end) + end) + + it('listchars', function() + exec('setlocal list') + exec( + 'setlocal listchars=eol:$,tab:<->,space:-,multispace:++,lead:_,leadmultispace:##,trail:&,nbsp:%' + ) + fn.setline(1, '\tfoo\t') + fn.setline(2, ' foo foo ') + fn.setline(3, ' foo foo ') + fn.setline(4, 'foo\x2cfoo') + run_tohtml_and_assert(screen) + exec('new|only') + fn.setline(1, '\tfoo\t') + exec('setlocal list') + exec('setlocal listchars=tab:a-') + run_tohtml_and_assert(screen) + end) + + it('folds', function() + insert([[ + line1 + line2 + ]]) + exec('set foldtext=foldtext()') + exec('%fo') + run_tohtml_and_assert(screen) + end) + + it('statuscol', function() + local function run() + local buf = api.nvim_get_current_buf() + run_tohtml_and_assert(screen, function() + exec_lua [[ + local outfile = vim.fn.tempname() .. '.html' + local html = require('tohtml').tohtml(0,{number_lines=true}) + vim.fn.writefile(html, outfile) + vim.cmd.split(outfile) + ]] + end) + api.nvim_set_current_buf(buf) + end + insert([[ + line1 + line2 + ]]) + exec('setlocal relativenumber') + run() + exec('setlocal norelativenumber') + exec('setlocal number') + run() + exec('setlocal relativenumber') + run() + exec('setlocal signcolumn=yes:2') + run() + exec('setlocal foldcolumn=2') + run() + exec('setlocal norelativenumber') + run() + exec('setlocal signcolumn=no') + run() + end) +end) -- cgit