fix: correct buffer parser and timestamp test
Problem: parse_buffer classified /id/-prefixed task lines as headers because '/' matches the '^%S' header pattern. Store timestamp test was flaky when add and update ran within the same second. Solution: check for task line patterns (id prefix or 2-space indent) before falling through to the header branch. Backdate the initial modified timestamp in the store update test.
This commit is contained in:
parent
41b06387be
commit
6f7959cb18
2 changed files with 25 additions and 27 deletions
|
|
@ -26,17 +26,13 @@ function M.parse_buffer(lines)
|
|||
local current_category = nil
|
||||
|
||||
for i, line in ipairs(lines) do
|
||||
if line == '' then
|
||||
table.insert(result, { type = 'blank', lnum = i })
|
||||
elseif line:match('^%S') then
|
||||
current_category = line
|
||||
table.insert(result, { type = 'header', category = line, lnum = i })
|
||||
else
|
||||
local id, body = line:match('^/(%d+)/( .+)$')
|
||||
if not id then
|
||||
body = line:match('^( .+)$')
|
||||
end
|
||||
if body then
|
||||
if line == '' then
|
||||
table.insert(result, { type = 'blank', lnum = i })
|
||||
elseif id or body then
|
||||
local stripped = body:match('^ (.+)$') or body
|
||||
local priority = 0
|
||||
if stripped:match('^! ') then
|
||||
|
|
@ -55,7 +51,9 @@ function M.parse_buffer(lines)
|
|||
lnum = i,
|
||||
})
|
||||
end
|
||||
end
|
||||
elseif line:match('^%S') then
|
||||
current_category = line
|
||||
table.insert(result, { type = 'header', category = line, lnum = i })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -106,11 +106,11 @@ describe('store', function()
|
|||
it('updates fields and sets modified', function()
|
||||
store.load()
|
||||
local t = store.add({ description = 'Original' })
|
||||
local original_modified = t.modified
|
||||
t.modified = '2025-01-01T00:00:00Z'
|
||||
store.update(t.id, { description = 'Updated' })
|
||||
local updated = store.get(t.id)
|
||||
assert.are.equal('Updated', updated.description)
|
||||
assert.is_not.equal(original_modified, updated.modified)
|
||||
assert.is_not.equal('2025-01-01T00:00:00Z', updated.modified)
|
||||
end)
|
||||
|
||||
it('sets end timestamp on completion', function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue