local t = require('test.testutil') local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') local clear = n.clear local exec = n.exec local exec_lua = n.exec_lua local eq = t.eq local fn = n.fn local api = n.api local insert = n.insert local function html_syntax_match() local styles = vim.split(api.nvim_exec2([[/', '', '', '
',
      'line',
      '',
      '
', '', '', }, fn.readfile(out_file)) end) it('expected internal html generated from range', function() insert([[ line1 line2 line3 ]]) local ns = api.nvim_create_namespace '' api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 1, end_row = 1, hl_group = 'Visual' }) exec('set termguicolors') local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui') local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui') exec_lua [[ local html = vim.cmd'2,2TOhtml' ]] local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf()) eq({ '', '', '', '', '', (''):format(api.nvim_get_var('colors_name')), '', '', '', '
',
      'line2',
      '',
      '
', '', '', }, 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 = { { 'fo┊o', { 'Conceal', 'Comment' } } }, 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('highlight', 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\194\160 \226\128\175foo') 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)