From 5143eedee0b453347dfe1092030867e2598d0a7d Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Fri, 16 Feb 2024 15:46:37 +0100 Subject: [PATCH] tests: Add tests for markup highlighter --- lua/orgmode/colors/highlighter/init.lua | 3 + .../colors/highlighter/markup/dates.lua | 3 +- .../colors/highlighter/markup/emphasis.lua | 35 +- .../colors/highlighter/markup/init.lua | 5 + .../colors/highlighter/markup/latex.lua | 3 +- .../colors/highlighter/markup/link.lua | 9 +- lua/orgmode/init.lua | 3 +- tests/plenary/colors/highlighter_spec.lua | 321 ++++++++++++++++++ 8 files changed, 352 insertions(+), 30 deletions(-) create mode 100644 tests/plenary/colors/highlighter_spec.lua diff --git a/lua/orgmode/colors/highlighter/init.lua b/lua/orgmode/colors/highlighter/init.lua index 61ad37683..1595568f0 100644 --- a/lua/orgmode/colors/highlighter/init.lua +++ b/lua/orgmode/colors/highlighter/init.lua @@ -3,6 +3,7 @@ ---@field private stars OrgStarsHighlighter ---@field private markup OrgMarkupHighlighter ---@field private todos OrgTodosHighlighter +---@field private _ephemeral boolean ---@field private buffers table local OrgHighlighter = {} local config = require('orgmode.config') @@ -11,6 +12,8 @@ function OrgHighlighter:new() local data = { namespace = vim.api.nvim_create_namespace('org_custom_highlighter'), buffers = {}, + -- Use ephemeral for highlights. Added to config to allow toggling from tests. + _ephemeral = true, } setmetatable(data, self) self.__index = self diff --git a/lua/orgmode/colors/highlighter/markup/dates.lua b/lua/orgmode/colors/highlighter/markup/dates.lua index 9187fd762..1b632c7b1 100644 --- a/lua/orgmode/colors/highlighter/markup/dates.lua +++ b/lua/orgmode/colors/highlighter/markup/dates.lua @@ -129,10 +129,11 @@ end ---@param bufnr number function OrgDates:highlight(highlights, bufnr) local namespace = self.markup.highlighter.namespace + local ephemeral = self.markup:use_ephemeral() for _, entry in ipairs(highlights) do vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, { - ephemeral = true, + ephemeral = ephemeral, end_col = entry.to.end_col, hl_group = entry.char == '>' and 'OrgTSTimestampActive' or 'OrgTSTimestampInactive', priority = 110, diff --git a/lua/orgmode/colors/highlighter/markup/emphasis.lua b/lua/orgmode/colors/highlighter/markup/emphasis.lua index e367a1b9f..dbd5feee1 100644 --- a/lua/orgmode/colors/highlighter/markup/emphasis.lua +++ b/lua/orgmode/colors/highlighter/markup/emphasis.lua @@ -60,49 +60,38 @@ end function OrgEmphasis:highlight(highlights, bufnr) local namespace = self.markup.highlighter.namespace local hide_markers = config.org_hide_emphasis_markers + local ephemeral = self.markup:use_ephemeral() + local conceal = hide_markers and '' or nil for _, entry in ipairs(highlights) do - local hl_offset = 1 - -- Leading delimiter vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, { - ephemeral = true, - end_col = entry.from.start_col + hl_offset, + ephemeral = ephemeral, + end_col = entry.from.end_col, hl_group = markers[entry.char].hl_name .. '_delimiter', spell = markers[entry.char].spell, priority = 110 + entry.from.start_col, + conceal = conceal, }) -- Closing delimiter - vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.to.end_col - hl_offset, { - ephemeral = true, + vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.to.start_col, { + ephemeral = ephemeral, end_col = entry.to.end_col, hl_group = markers[entry.char].hl_name .. '_delimiter', spell = markers[entry.char].spell, priority = 110 + entry.from.start_col, + conceal = conceal, }) -- Main body highlight - vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col + hl_offset, { - ephemeral = true, - end_col = entry.to.end_col - hl_offset, + vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col + 1, { + ephemeral = ephemeral, + end_col = entry.to.end_col - 1, hl_group = markers[entry.char].hl_name, spell = markers[entry.char].spell, priority = 110 + entry.from.start_col, }) - - if hide_markers then - vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, { - end_col = entry.from.end_col, - ephemeral = true, - conceal = '', - }) - vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.to.line, entry.to.start_col, { - end_col = entry.to.end_col, - ephemeral = true, - conceal = '', - }) - end end end @@ -114,7 +103,7 @@ function OrgEmphasis:parse_node(node) return false end - local id = table.concat({'emphasis', node_type}, '_') + local id = table.concat({ 'emphasis', node_type }, '_') return { type = 'emphasis', diff --git a/lua/orgmode/colors/highlighter/markup/init.lua b/lua/orgmode/colors/highlighter/markup/init.lua index 59b8e88f4..0dcfb11cf 100644 --- a/lua/orgmode/colors/highlighter/markup/init.lua +++ b/lua/orgmode/colors/highlighter/markup/init.lua @@ -218,4 +218,9 @@ function OrgMarkup:has_valid_parent(item) return false end +function OrgMarkup:use_ephemeral() + ---@diagnostic disable-next-line: invisible + return self.highlighter._ephemeral +end + return OrgMarkup diff --git a/lua/orgmode/colors/highlighter/markup/latex.lua b/lua/orgmode/colors/highlighter/markup/latex.lua index 06da11238..1bd7edafc 100644 --- a/lua/orgmode/colors/highlighter/markup/latex.lua +++ b/lua/orgmode/colors/highlighter/markup/latex.lua @@ -96,10 +96,11 @@ end ---@param highlights OrgMarkupHighlight[] ---@param bufnr number function OrgLatex:highlight(highlights, bufnr) + local ephemeral = self.markup:use_ephemeral() local namespace = self.markup.highlighter.namespace for _, entry in ipairs(highlights) do vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col - 1, { - ephemeral = true, + ephemeral = ephemeral, end_col = entry.to.end_col, hl_group = 'org_latex', spell = false, diff --git a/lua/orgmode/colors/highlighter/markup/link.lua b/lua/orgmode/colors/highlighter/markup/link.lua index f471f2aeb..088493c97 100644 --- a/lua/orgmode/colors/highlighter/markup/link.lua +++ b/lua/orgmode/colors/highlighter/markup/link.lua @@ -92,6 +92,7 @@ end ---@param bufnr number function OrgLink:highlight(highlights, bufnr) local namespace = self.markup.highlighter.namespace + local ephemeral = self.markup:use_ephemeral() for _, entry in ipairs(highlights) do local link = @@ -100,26 +101,26 @@ function OrgLink:highlight(highlights, bufnr) local link_end = link:find('%]%[') or (link:len() - 1) vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, { - ephemeral = true, + ephemeral = ephemeral, end_col = entry.to.end_col, hl_group = 'org_hyperlink', priority = 110, }) vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, { - ephemeral = true, + ephemeral = ephemeral, end_col = entry.from.start_col + 1 + alias, conceal = '', }) vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col + 2, { - ephemeral = true, + ephemeral = ephemeral, end_col = entry.from.start_col - 1 + link_end, spell = false, }) vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.to.end_col - 2, { - ephemeral = true, + ephemeral = ephemeral, end_col = entry.to.end_col, conceal = '', }) diff --git a/lua/orgmode/init.lua b/lua/orgmode/init.lua index ea4ccfefc..3a9da7c4b 100644 --- a/lua/orgmode/init.lua +++ b/lua/orgmode/init.lua @@ -16,6 +16,7 @@ local auto_instance_keys = { ---@class Org ---@field initialized boolean ---@field files OrgFiles +---@field highlighter OrgHighlighter ---@field agenda OrgAgenda ---@field capture OrgCapture ---@field clock OrgClock @@ -41,8 +42,8 @@ function Org:init() if self.initialized then return end - require('orgmode.colors.highlighter'):new() require('orgmode.events').init() + self.highlighter = require('orgmode.colors.highlighter'):new() self.files = require('orgmode.files'):new({ paths = require('orgmode.config').org_agenda_files, }) diff --git a/tests/plenary/colors/highlighter_spec.lua b/tests/plenary/colors/highlighter_spec.lua new file mode 100644 index 000000000..09be4b2be --- /dev/null +++ b/tests/plenary/colors/highlighter_spec.lua @@ -0,0 +1,321 @@ +local helpers = require('tests.plenary.helpers') +local config = require('orgmode.config') +local org = require('orgmode') +local api = vim.api + +describe('highlighter', function() + local ns_id = api.nvim_create_namespace('org_custom_highlighter') + local get_extmarks = function(content) + config.ts_hl_enabled = true + helpers.load_file_content(content) + ---@diagnostic disable-next-line: invisible + org.highlighter._ephemeral = false + vim.cmd([[redraw!]]) + + return api.nvim_buf_get_extmarks(api.nvim_get_current_buf(), ns_id, 0, -1, { + details = true, + }) + end + + local assert_extmark = function(extmark, opts) + opts = opts or {} + local details = extmark[4] + assert.are.same(opts.line, extmark[2], 'line is not matching') + assert.are.same(opts.start_col, extmark[3], 'start col is not matching') + assert.are.same(opts.end_col, details.end_col, 'end col is not matching') + if opts.hl_group ~= nil then + assert.are.same(opts.hl_group, details.hl_group, 'hl group is not matching') + end + if opts.conceal ~= nil then + assert.are.same(opts.conceal, details.conceal, 'conceal is not matching') + end + if opts.spell ~= nil then + assert.are.same(opts.spell, details.spell, 'spell is not matching') + end + end + + after_each(function() + vim.cmd([[%bw!]]) + config.ts_hl_enabled = false + ---@diagnostic disable-next-line: invisible + org.highlighter._ephemeral = true + end) + + describe('emphasis', function() + it('should highlight bold', function() + local extmarks = get_extmarks({ + 'I am *bold* text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_bold_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 10, hl_group = 'org_bold' }) + assert_extmark(extmarks[3], { line = 0, start_col = 10, end_col = 11, hl_group = 'org_bold_delimiter' }) + end) + + it('should highlight italic', function() + local extmarks = get_extmarks({ + 'I am /italic/ text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 12, hl_group = 'org_italic' }) + assert_extmark(extmarks[3], { line = 0, start_col = 12, end_col = 13, hl_group = 'org_italic_delimiter' }) + end) + + it('should highlight underline', function() + local extmarks = get_extmarks({ + 'I am _underline_ text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_underline_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 15, hl_group = 'org_underline' }) + assert_extmark(extmarks[3], { line = 0, start_col = 15, end_col = 16, hl_group = 'org_underline_delimiter' }) + end) + + it('should highlight strikethrough', function() + local extmarks = get_extmarks({ + 'I am +strikethrough+ text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_strikethrough_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 19, hl_group = 'org_strikethrough' }) + assert_extmark(extmarks[3], { line = 0, start_col = 19, end_col = 20, hl_group = 'org_strikethrough_delimiter' }) + end) + + it('should highlight dode', function() + local extmarks = get_extmarks({ + 'I am ~code~ text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_code_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 10, hl_group = 'org_code' }) + assert_extmark(extmarks[3], { line = 0, start_col = 10, end_col = 11, hl_group = 'org_code_delimiter' }) + end) + + it('should highlight verbatim', function() + local extmarks = get_extmarks({ + 'I am =verbatim= text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_verbatim_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 14, hl_group = 'org_verbatim' }) + assert_extmark(extmarks[3], { line = 0, start_col = 14, end_col = 15, hl_group = 'org_verbatim_delimiter' }) + end) + + it('should highlight mix of emphasis that is nestable', function() + local extmarks = get_extmarks({ + 'I am *bold /italic and _underline_/* text', + }) + assert.are.same(9, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_bold_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 35, hl_group = 'org_bold' }) + assert_extmark(extmarks[3], { line = 0, start_col = 11, end_col = 12, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[4], { line = 0, start_col = 12, end_col = 34, hl_group = 'org_italic' }) + assert_extmark(extmarks[5], { line = 0, start_col = 23, end_col = 24, hl_group = 'org_underline_delimiter' }) + assert_extmark(extmarks[6], { line = 0, start_col = 24, end_col = 33, hl_group = 'org_underline' }) + assert_extmark(extmarks[7], { line = 0, start_col = 33, end_col = 34, hl_group = 'org_underline_delimiter' }) + assert_extmark(extmarks[8], { line = 0, start_col = 34, end_col = 35, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[9], { line = 0, start_col = 35, end_col = 36, hl_group = 'org_bold_delimiter' }) + end) + + it('should conceal markers if org_hide_emphasis_markers is true', function() + config.opts.org_hide_emphasis_markers = true + local extmarks = get_extmarks({ + 'Text with *bold /italic/* text', + }) + + assert.are.same(6, #extmarks) + assert_extmark( + extmarks[1], + { line = 0, start_col = 10, end_col = 11, hl_group = 'org_bold_delimiter', conceal = '' } + ) + assert_extmark(extmarks[2], { line = 0, start_col = 11, end_col = 24, hl_group = 'org_bold' }) + assert_extmark( + extmarks[3], + { line = 0, start_col = 16, end_col = 17, hl_group = 'org_italic_delimiter', conceal = '' } + ) + assert_extmark(extmarks[4], { line = 0, start_col = 17, end_col = 23, hl_group = 'org_italic' }) + assert_extmark( + extmarks[5], + { line = 0, start_col = 23, end_col = 24, hl_group = 'org_italic_delimiter', conceal = '' } + ) + assert_extmark( + extmarks[6], + { line = 0, start_col = 24, end_col = 25, hl_group = 'org_bold_delimiter', conceal = '' } + ) + config.opts.org_hide_emphasis_markers = false + end) + + it('should highlight emphasis in headline', function() + local extmarks = get_extmarks({ + '* Headline with *bold /italic/* text', + '- list item', + '- list item', + }) + assert.are.same(6, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 16, end_col = 17, hl_group = 'org_bold_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 17, end_col = 30, hl_group = 'org_bold' }) + assert_extmark(extmarks[3], { line = 0, start_col = 22, end_col = 23, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[4], { line = 0, start_col = 23, end_col = 29, hl_group = 'org_italic' }) + assert_extmark(extmarks[5], { line = 0, start_col = 29, end_col = 30, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[6], { line = 0, start_col = 30, end_col = 31, hl_group = 'org_bold_delimiter' }) + end) + + it('should highlight emphasis in list item', function() + local extmarks = get_extmarks({ + '- list item', + '- note with *bold /italic/* text', + '- list item', + }) + assert.are.same(6, #extmarks) + assert_extmark(extmarks[1], { line = 1, start_col = 12, end_col = 13, hl_group = 'org_bold_delimiter' }) + assert_extmark(extmarks[2], { line = 1, start_col = 13, end_col = 26, hl_group = 'org_bold' }) + assert_extmark(extmarks[3], { line = 1, start_col = 18, end_col = 19, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[4], { line = 1, start_col = 19, end_col = 25, hl_group = 'org_italic' }) + assert_extmark(extmarks[5], { line = 1, start_col = 25, end_col = 26, hl_group = 'org_italic_delimiter' }) + assert_extmark(extmarks[6], { line = 1, start_col = 26, end_col = 27, hl_group = 'org_bold_delimiter' }) + end) + + it('should not render emphasis that is nested in non-nestable emphasis', function() + local extmarks = get_extmarks({ + 'I am =verbatim and *not bold* part= of text', + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 5, end_col = 6, hl_group = 'org_verbatim_delimiter' }) + assert_extmark(extmarks[2], { line = 0, start_col = 6, end_col = 34, hl_group = 'org_verbatim' }) + assert_extmark(extmarks[3], { line = 0, start_col = 34, end_col = 35, hl_group = 'org_verbatim_delimiter' }) + end) + + it('should not render emphasis if pre-chars are not valid', function() + local extmarks = get_extmarks({ + 'I am v*bold* text', + }) + assert.are.same(0, #extmarks) + end) + + it('should not render emphasis if post-chars are not valid', function() + local extmarks = get_extmarks({ + 'I am *not bold*v text', + }) + assert.are.same(0, #extmarks) + end) + end) + + describe('links', function() + it('should highlight links without label', function() + local extmarks = get_extmarks({ + 'I have [[https://google.com]] link', + }) + assert.are.same(4, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 7, end_col = 29, hl_group = 'org_hyperlink' }) + assert_extmark(extmarks[2], { line = 0, start_col = 7, end_col = 9, conceal = '' }) + assert_extmark(extmarks[3], { line = 0, start_col = 9, end_col = 27, spell = false }) + assert_extmark(extmarks[4], { line = 0, start_col = 27, end_col = 29, conceal = '' }) + end) + + it('should highlight links with label', function() + local extmarks = get_extmarks({ + 'I have [[https://google.com][google]] link', + }) + assert.are.same(4, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 7, end_col = 37, hl_group = 'org_hyperlink' }) + assert_extmark(extmarks[2], { line = 0, start_col = 7, end_col = 29, conceal = '' }) + assert_extmark(extmarks[3], { line = 0, start_col = 9, end_col = 27, spell = false }) + assert_extmark(extmarks[4], { line = 0, start_col = 35, end_col = 37, conceal = '' }) + end) + + it('should highlight links with label and not render any markup inside', function() + local extmarks = get_extmarks({ + 'I have [[https://google.com][google I am *not bold*]] link', + }) + assert.are.same(4, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 7, end_col = 53, hl_group = 'org_hyperlink' }) + assert_extmark(extmarks[2], { line = 0, start_col = 7, end_col = 29, conceal = '' }) + assert_extmark(extmarks[3], { line = 0, start_col = 9, end_col = 27, spell = false }) + assert_extmark(extmarks[4], { line = 0, start_col = 51, end_col = 53, conceal = '' }) + end) + + it('should not highlight invalid link', function() + local extmarks = get_extmarks({ + 'I am not a [[https://google.com] link', + }) + assert.are.same(0, #extmarks) + end) + end) + + describe('latex', function() + it('should highlight latex with backslash only', function() + local extmarks = get_extmarks({ + [[this is \latex text]], + [[this is \latex{} text]], + [[this is \latex{inside} text]], + [[this is \latex[] text]], + [[this is \latex[inside] text]], + [[this is \latex() text]], + [[this is \latex(inside) text]], + }) + assert.are.same(7, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 8, end_col = 14, hl_group = 'org_latex' }) + assert_extmark(extmarks[2], { line = 1, start_col = 8, end_col = 16, hl_group = 'org_latex' }) + assert_extmark(extmarks[3], { line = 2, start_col = 8, end_col = 15, hl_group = 'org_latex' }) + assert_extmark(extmarks[4], { line = 3, start_col = 8, end_col = 16, hl_group = 'org_latex' }) + assert_extmark(extmarks[5], { line = 4, start_col = 8, end_col = 15, hl_group = 'org_latex' }) + assert_extmark(extmarks[6], { line = 5, start_col = 8, end_col = 16, hl_group = 'org_latex' }) + assert_extmark(extmarks[7], { line = 6, start_col = 8, end_col = 15, hl_group = 'org_latex' }) + end) + + it('should highlight latex with backslash brackets', function() + local extmarks = get_extmarks({ + [[this is \(1 + 1\) math]], + [[this is \[1 + 1\] math]], + [[this is \{1 + 1\} math]], + }) + assert.are.same(3, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 8, end_col = 17, hl_group = 'org_latex' }) + assert_extmark(extmarks[2], { line = 1, start_col = 8, end_col = 17, hl_group = 'org_latex' }) + assert_extmark(extmarks[3], { line = 2, start_col = 8, end_col = 17, hl_group = 'org_latex' }) + end) + end) + + describe('dates', function() + it('should highlight active dates', function() + local extmarks = get_extmarks({ + 'the date <2024-02-16>', + 'the date <2024-02-16 Fri>', + 'the date <2024-02-16 Fri 12:30>', + 'the date <2024-02-16 Fri 12:30 +1m>', + 'the date <2024-02-16 Fri 12:30 +1m -1d>', + }) + assert.are.same(5, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 9, end_col = 21, hl_group = 'OrgTSTimestampActive' }) + assert_extmark(extmarks[2], { line = 1, start_col = 9, end_col = 25, hl_group = 'OrgTSTimestampActive' }) + assert_extmark(extmarks[3], { line = 2, start_col = 9, end_col = 31, hl_group = 'OrgTSTimestampActive' }) + assert_extmark(extmarks[4], { line = 3, start_col = 9, end_col = 35, hl_group = 'OrgTSTimestampActive' }) + assert_extmark(extmarks[5], { line = 4, start_col = 9, end_col = 39, hl_group = 'OrgTSTimestampActive' }) + end) + + it('should highlight inactive dates', function() + local extmarks = get_extmarks({ + 'the date [2024-02-16]', + 'the date [2024-02-16 Fri]', + 'the date [2024-02-16 Fri 12:30]', + 'the date [2024-02-16 Fri 12:30 +1m]', + 'the date [2024-02-16 Fri 12:30 +1m -1d]', + }) + assert.are.same(5, #extmarks) + assert_extmark(extmarks[1], { line = 0, start_col = 9, end_col = 21, hl_group = 'OrgTSTimestampInactive' }) + assert_extmark(extmarks[2], { line = 1, start_col = 9, end_col = 25, hl_group = 'OrgTSTimestampInactive' }) + assert_extmark(extmarks[3], { line = 2, start_col = 9, end_col = 31, hl_group = 'OrgTSTimestampInactive' }) + assert_extmark(extmarks[4], { line = 3, start_col = 9, end_col = 35, hl_group = 'OrgTSTimestampInactive' }) + assert_extmark(extmarks[5], { line = 4, start_col = 9, end_col = 39, hl_group = 'OrgTSTimestampInactive' }) + end) + + it('should not highlight invalid dates', function() + local extmarks = get_extmarks({ + 'the date [2024-02-16 .]', + 'the date <2024-02-16 Fri <>', + }) + assert.are.same(0, #extmarks) + end) + end) +end)