test: add top-priority missing test coverage

Problem: several critical code paths had zero test coverage —
parse.resolve_date (relative date resolution), store.snapshot
(foundation of the undo stack), and the diff.apply invariant that
unchanged tasks do not get their modified timestamp bumped. The
diff.apply due/priority clearing paths were also untested.

Solution: add six targeted test blocks across parse_spec, store_spec,
and diff_spec: resolve_date happy/failure paths, parse.body with
relative due tokens, snapshot copy-semantics and deleted-task
exclusion, diff unchanged-modified invariant, due cleared on removal,
priority cleared on ! removal.
This commit is contained in:
Barrett Ruth 2026-02-24 19:53:50 -05:00 committed by Barrett Ruth
parent 20b8cb760f
commit 39c98012d0
3 changed files with 134 additions and 0 deletions

View file

@ -135,5 +135,51 @@ describe('diff', function()
local task = store.get(1)
assert.are.equal('Work', task.category)
end)
it('does not update modified when task is unchanged', function()
store.add({ description = 'Stable task', category = 'Inbox' })
store.save()
local lines = {
'Inbox',
'/1/ Stable task',
}
diff.apply(lines)
store.unload()
store.load()
local modified_after_first = store.get(1).modified
diff.apply(lines)
store.unload()
store.load()
local task = store.get(1)
assert.are.equal(modified_after_first, task.modified)
end)
it('clears due when removed from buffer line', function()
store.add({ description = 'Pay bill', due = '2026-03-15' })
store.save()
local lines = {
'Inbox',
'/1/ Pay bill',
}
diff.apply(lines)
store.unload()
store.load()
local task = store.get(1)
assert.is_nil(task.due)
end)
it('clears priority when ! is removed from buffer line', function()
store.add({ description = 'Task name', priority = 1 })
store.save()
local lines = {
'Inbox',
'/1/ Task name',
}
diff.apply(lines)
store.unload()
store.load()
local task = store.get(1)
assert.are.equal(0, task.priority)
end)
end)
end)