local light_up = require 'std.light_up' describe('std.light_up', function() local bufnr before_each(function() vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'foo bar baz', 'test_word end_of_line', 'keyword1 keyword2 middle', }) bufnr = 0 end) after_each(function() pcall(vim.api.nvim_buf_delete, 0, { force = true }) end) describe('_.buffer', function() it('should highlight a word at start of line without preceding boundary', function() local words = { test_word = 'Title' } local ns = light_up.buffer(bufnr, words) local marks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true }) assert.equal(1, #marks, 'should have exactly one highlight mark') assert.equal(1, marks[1][2], 'should be on line 1 (where test_word appears)') assert.equal(0, marks[1][3], 'test_word starts at column 0') end) it('should highlight multiple different words on the same line', function() local words = { keyword1 = 'Title', keyword2 = 'Comment' } local ns = light_up.buffer(bufnr, words) local marks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true }) assert.equal(2, #marks, 'both keyword1 and keyword2 on same line should be highlighted') end) it('should highlight all instances of same word on same line', function() vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'foo foo foo' }) local words = { foo = 'Title' } local ns = light_up.buffer(bufnr, words) local marks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true }) assert.equal(3, #marks, 'all three foo occurrences should be highlighted') end) end) describe('_.get_vim_highlight_groups', function() it('should return a non-empty table', function() local groups = light_up.get_vim_highlight_groups() assert.is_table(groups) assert(next(groups) ~= nil, 'should have at least one highlight group') end) it('should contain common highlight groups', function() local groups = light_up.get_vim_highlight_groups() assert.is_not_nil(groups['Title']) assert.is_not_nil(groups['Comment']) assert.is_not_nil(groups['Normal']) end) end) end)