fix(parse): position-independent inline metadata parsing (#164)
Some checks are pending
quality / changes (push) Waiting to run
quality / Lua Format Check (push) Blocked by required conditions
quality / Lua Lint Check (push) Blocked by required conditions
quality / Lua Type Check (push) Blocked by required conditions
quality / Markdown Format Check (push) Blocked by required conditions
test / Test (Neovim nightly) (push) Waiting to run
test / Test (Neovim stable) (push) Waiting to run
Some checks are pending
quality / changes (push) Waiting to run
quality / Lua Format Check (push) Blocked by required conditions
quality / Lua Lint Check (push) Blocked by required conditions
quality / Lua Type Check (push) Blocked by required conditions
quality / Markdown Format Check (push) Blocked by required conditions
test / Test (Neovim nightly) (push) Waiting to run
test / Test (Neovim stable) (push) Waiting to run
Problem: `parse.body()` scanned tokens right-to-left and broke on the first non-metadata token, so metadata only worked at the trailing end of a line. `due:tomorrow Fix the bug` silently failed to parse the due date. Solution: Replace the right-to-left `while` loop with a single left-to-right pass that extracts metadata tokens from any position. Duplicate metadata tokens are dropped with a `log.warn`. Update docs and tests accordingly.
This commit is contained in:
parent
a3442401a0
commit
d6f3292d7c
3 changed files with 33 additions and 3 deletions
|
|
@ -48,16 +48,35 @@ describe('parse', function()
|
|||
assert.are.equal('Errands', meta.category)
|
||||
end)
|
||||
|
||||
it('first occurrence wins for duplicate keys', function()
|
||||
it('first occurrence wins for duplicate keys and warns', function()
|
||||
local warnings = {}
|
||||
local orig = vim.notify
|
||||
vim.notify = function(m, level)
|
||||
if level == vim.log.levels.WARN then
|
||||
table.insert(warnings, m)
|
||||
end
|
||||
end
|
||||
local desc, meta = parse.body('Buy milk due:2026-03-15 due:2026-04-01')
|
||||
vim.notify = orig
|
||||
assert.are.equal('Buy milk', desc)
|
||||
assert.are.equal('2026-03-15', meta.due)
|
||||
assert.are.equal(1, #warnings)
|
||||
assert.truthy(warnings[1]:find('duplicate', 1, true))
|
||||
end)
|
||||
|
||||
it('drops identical duplicate metadata tokens', function()
|
||||
it('drops identical duplicate metadata tokens and warns', function()
|
||||
local warnings = {}
|
||||
local orig = vim.notify
|
||||
vim.notify = function(m, level)
|
||||
if level == vim.log.levels.WARN then
|
||||
table.insert(warnings, m)
|
||||
end
|
||||
end
|
||||
local desc, meta = parse.body('Buy milk due:tomorrow due:tomorrow')
|
||||
vim.notify = orig
|
||||
assert.are.equal('Buy milk', desc)
|
||||
assert.are.equal(os.date('%Y-%m-%d', os.time() + 86400), meta.due)
|
||||
assert.are.equal(1, #warnings)
|
||||
end)
|
||||
|
||||
it('stops at non-meta token', function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue