fix(parse): position-independent inline metadata parsing
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. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e816e6fb7e
commit
ed0b72feee
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