Deletion
- An already-completed task may now also be deleted. - Added unit tests.
This commit is contained in:
21
src/TDB2.cpp
21
src/TDB2.cpp
@@ -145,7 +145,7 @@ void TF2::add_task (const Task& task)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TF2::modify_task (const Task& task)
|
bool TF2::modify_task (const Task& task)
|
||||||
{
|
{
|
||||||
// Modify in-place.
|
// Modify in-place.
|
||||||
std::string uuid = task.get ("uuid");
|
std::string uuid = task.get ("uuid");
|
||||||
@@ -155,12 +155,13 @@ void TF2::modify_task (const Task& task)
|
|||||||
if (i->get ("uuid") == uuid)
|
if (i->get ("uuid") == uuid)
|
||||||
{
|
{
|
||||||
*i = task;
|
*i = task;
|
||||||
break;
|
_modified_tasks.push_back (task);
|
||||||
|
_dirty = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_modified_tasks.push_back (task);
|
return false;
|
||||||
_dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -522,17 +523,9 @@ void TDB2::modify (Task& task)
|
|||||||
|
|
||||||
if (taskDiff (original, task))
|
if (taskDiff (original, task))
|
||||||
{
|
{
|
||||||
std::string status = original.get ("status");
|
// Update the task, wherever it is.
|
||||||
if (status == "pending" ||
|
if (!pending.modify_task (task))
|
||||||
status == "waiting" ||
|
|
||||||
status == "recurring")
|
|
||||||
{
|
|
||||||
pending.modify_task (task);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
completed.modify_task (task);
|
completed.modify_task (task);
|
||||||
}
|
|
||||||
|
|
||||||
// time <time>
|
// time <time>
|
||||||
// old <task>
|
// old <task>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
const std::string& get_contents ();
|
const std::string& get_contents ();
|
||||||
|
|
||||||
void add_task (const Task&);
|
void add_task (const Task&);
|
||||||
void modify_task (const Task&);
|
bool modify_task (const Task&);
|
||||||
void add_line (const std::string&);
|
void add_line (const std::string&);
|
||||||
void clear_lines ();
|
void clear_lines ();
|
||||||
void commit ();
|
void commit ();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 14;
|
use Test::More tests => 16;
|
||||||
|
|
||||||
# Create the rc file.
|
# Create the rc file.
|
||||||
if (open my $fh, '>', 'delete.rc')
|
if (open my $fh, '>', 'delete.rc')
|
||||||
@@ -70,6 +70,16 @@ $output = qx{../src/task rc:delete.rc 1 info};
|
|||||||
like ($output, qr/foo/, 'Deletion annotation successful');
|
like ($output, qr/foo/, 'Deletion annotation successful');
|
||||||
like ($output, qr/H/, 'Deletion modification successful');
|
like ($output, qr/H/, 'Deletion modification successful');
|
||||||
|
|
||||||
|
# Add a task, complete it, then delete it.
|
||||||
|
qx{../src/task rc:delete.rc add three};
|
||||||
|
$output = qx{../src/task rc:delete.rc 2 info};
|
||||||
|
like ($output, qr/three/, 'added and verified new task');
|
||||||
|
my ($uuid) = $output =~ /UUID\s+(\S+)/;
|
||||||
|
qx{../src/task rc:delete.rc 2 done};
|
||||||
|
qx{../src/task rc:delete.rc $uuid delete};
|
||||||
|
$output = qx{../src/task rc:delete.rc $uuid info};
|
||||||
|
like ($output, qr/Deleted/, 'task added, completed, then deleted');
|
||||||
|
|
||||||
# Cleanup.
|
# Cleanup.
|
||||||
unlink qw(pending.data completed.data undo.data backlog.data synch.key delete.rc);
|
unlink qw(pending.data completed.data undo.data backlog.data synch.key delete.rc);
|
||||||
ok (! -r 'pending.data' &&
|
ok (! -r 'pending.data' &&
|
||||||
|
|||||||
Reference in New Issue
Block a user