feat(diff): propagate recurrence through buffer reconciliation
Problem: the diff layer does not extract or apply recurrence fields, so rec: tokens written in the buffer are silently ignored on :w. Solution: add rec and rec_mode to ParsedEntry, extract them in parse_buffer(), and pass them through create and update paths in apply().
This commit is contained in:
parent
e19cfdda18
commit
597ec6bb2a
2 changed files with 89 additions and 0 deletions
|
|
@ -69,6 +69,25 @@ describe('diff', function()
|
|||
assert.are.equal('Work', result[2].category)
|
||||
end)
|
||||
|
||||
it('extracts rec: token from buffer line', function()
|
||||
local lines = {
|
||||
'## Inbox',
|
||||
'/1/- [ ] Take trash out rec:weekly',
|
||||
}
|
||||
local result = diff.parse_buffer(lines)
|
||||
assert.are.equal('weekly', result[2].rec)
|
||||
end)
|
||||
|
||||
it('extracts rec: with completion mode', function()
|
||||
local lines = {
|
||||
'## Inbox',
|
||||
'/1/- [ ] Water plants rec:!daily',
|
||||
}
|
||||
local result = diff.parse_buffer(lines)
|
||||
assert.are.equal('daily', result[2].rec)
|
||||
assert.are.equal('completion', result[2].rec_mode)
|
||||
end)
|
||||
|
||||
it('inline due: token is parsed', function()
|
||||
local lines = {
|
||||
'## Inbox',
|
||||
|
|
@ -206,6 +225,60 @@ describe('diff', function()
|
|||
assert.is_nil(task.due)
|
||||
end)
|
||||
|
||||
it('stores recur field on new tasks from buffer', function()
|
||||
local lines = {
|
||||
'## Inbox',
|
||||
'- [ ] Take out trash rec:weekly',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
store.load()
|
||||
local tasks = store.active_tasks()
|
||||
assert.are.equal(1, #tasks)
|
||||
assert.are.equal('weekly', tasks[1].recur)
|
||||
end)
|
||||
|
||||
it('updates recur field when changed inline', function()
|
||||
store.add({ description = 'Task', recur = 'daily' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'## Todo',
|
||||
'/1/- [ ] Task rec:weekly',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
store.load()
|
||||
local task = store.get(1)
|
||||
assert.are.equal('weekly', task.recur)
|
||||
end)
|
||||
|
||||
it('clears recur when token removed from line', function()
|
||||
store.add({ description = 'Task', recur = 'daily' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'## Todo',
|
||||
'/1/- [ ] Task',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
store.load()
|
||||
local task = store.get(1)
|
||||
assert.is_nil(task.recur)
|
||||
end)
|
||||
|
||||
it('parses rec: with completion mode prefix', function()
|
||||
local lines = {
|
||||
'## Inbox',
|
||||
'- [ ] Water plants rec:!weekly',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
store.load()
|
||||
local tasks = store.active_tasks()
|
||||
assert.are.equal('weekly', tasks[1].recur)
|
||||
assert.are.equal('completion', tasks[1].recur_mode)
|
||||
end)
|
||||
|
||||
it('clears priority when [N] is removed from buffer line', function()
|
||||
store.add({ description = 'Task name', priority = 1 })
|
||||
store.save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue