mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Bug - import.yaml
- Fixed bug in import for YAML and TODO that failed to recognize that a task was completed or deleted, and consequently set a Task::pending status. - Enhanced unit tests to verify this.
This commit is contained in:
parent
41f2520094
commit
5b8dbd8ff1
3 changed files with 66 additions and 10 deletions
15
src/TDB.cpp
15
src/TDB.cpp
|
@ -457,9 +457,18 @@ const std::vector <Task>& TDB::getAllModified ()
|
|||
// Note: mLocations[0] is where all tasks are written.
|
||||
void TDB::add (const Task& task)
|
||||
{
|
||||
mNew.push_back (task);
|
||||
mI2U[task.id] = task.get ("uuid");
|
||||
mU2I[task.get ("uuid")] = task.id;
|
||||
Task t (task);
|
||||
if (task.get ("uuid") == "")
|
||||
{
|
||||
std::string unique = ::uuid ();
|
||||
t.set ("uuid", unique);
|
||||
}
|
||||
else
|
||||
t.set ("uuid", task.get ("uuid"));
|
||||
|
||||
mNew.push_back (t);
|
||||
mI2U[task.id] = t.get ("uuid");
|
||||
mU2I[task.get ("uuid")] = t.id;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -171,9 +171,12 @@ static fileType determineFileType (const std::vector <std::string>& lines)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void decorateTask (Task& task)
|
||||
{
|
||||
char entryTime[16];
|
||||
sprintf (entryTime, "%u", (unsigned int) time (NULL));
|
||||
task.set ("entry", entryTime);
|
||||
if (!task.has ("entry"))
|
||||
{
|
||||
char entryTime[16];
|
||||
sprintf (entryTime, "%u", (unsigned int) time (NULL));
|
||||
task.set ("entry", entryTime);
|
||||
}
|
||||
|
||||
task.setStatus (Task::pending);
|
||||
|
||||
|
@ -798,6 +801,10 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
|
|||
context.parse ();
|
||||
decorateTask (context.task);
|
||||
|
||||
// Override the Task::pending that decorateTask applies.
|
||||
if (!isPending)
|
||||
context.task.setStatus (Task::completed);
|
||||
|
||||
context.task.set ("uuid", uuid ());
|
||||
|
||||
if (isPending)
|
||||
|
@ -1169,6 +1176,7 @@ static std::string importYAML (const std::vector <std::string>& lines)
|
|||
|
||||
bool inAnno = false;
|
||||
std::string annoEntry;
|
||||
Task::status status = Task::pending;
|
||||
|
||||
std::vector <std::string>::const_iterator it;
|
||||
for (it = lines.begin (); it != lines.end (); ++it)
|
||||
|
@ -1193,12 +1201,31 @@ static std::string importYAML (const std::vector <std::string>& lines)
|
|||
{
|
||||
if (t.size ())
|
||||
{
|
||||
// Generate a UUID if not present.
|
||||
if (t.get ("uuid") == "")
|
||||
t.set ("uuid", uuid ());
|
||||
|
||||
// Add defaults.
|
||||
decorateTask (t);
|
||||
t.setStatus (status);
|
||||
|
||||
// TODO Fail on UUID collision.
|
||||
|
||||
context.tdb.add (t);
|
||||
t.clear ();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
else if (name == "status")
|
||||
{
|
||||
if (value == "waiting") status = Task::waiting;
|
||||
else if (value == "completed") status = Task::completed;
|
||||
else if (value == "deleted") status = Task::deleted;
|
||||
else if (value == "recurring") status = Task::recurring;
|
||||
else status = Task::pending;
|
||||
}
|
||||
|
||||
else if (name == "annotation")
|
||||
inAnno = true;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 11;
|
||||
use Test::More tests => 14;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'import.rc')
|
||||
|
@ -49,15 +49,18 @@ if (open my $fh, '>', 'import.txt')
|
|||
description: zero
|
||||
project: A
|
||||
status: pending
|
||||
entry: 1234567889
|
||||
task:
|
||||
uuid: 11111111-1111-1111-1111-111111111111
|
||||
description: one
|
||||
project: B
|
||||
status: pending
|
||||
entry: 1234567889
|
||||
task:
|
||||
uuid: 22222222-2222-2222-2222-222222222222
|
||||
description: two
|
||||
status: completed
|
||||
entry: 1234567889
|
||||
end: 1234567890
|
||||
...
|
||||
EOF
|
||||
|
@ -68,13 +71,30 @@ EOF
|
|||
|
||||
my $output = qx{../task rc:import.rc import import.txt};
|
||||
like ($output, qr/Imported 3 tasks successfully./, 'no errors');
|
||||
# Imported 3 tasks successfully.
|
||||
|
||||
$output = qx{../task rc:import.rc list};
|
||||
like ($output, qr/1.+A.+zero/, 't1');
|
||||
like ($output, qr/2.+B.+one/, 't2');
|
||||
# ID Project Pri Due Active Age Description
|
||||
# -- ------- --- --- ------ ------- -----------
|
||||
# 1 A 1.5 yrs zero
|
||||
# 2 B 1.5 yrs one
|
||||
#
|
||||
# 2 tasks
|
||||
|
||||
like ($output, qr/1.+A.+zero/, 't1 present');
|
||||
like ($output, qr/2.+B.+one/, 't2 present');
|
||||
unlike ($output, qr/3.+two/, 't3 missing');
|
||||
|
||||
$output = qx{../task rc:import.rc completed};
|
||||
like ($output, qr/2\/13\/2009.+two/, 't3');
|
||||
# Complete Project Pri Age Description
|
||||
# --------- ------- --- ------- -----------
|
||||
# 2/13/2009 1.5 yrs two
|
||||
#
|
||||
# 1 task
|
||||
|
||||
unlike ($output, qr/1.+A.+zero/, 't1 missing');
|
||||
unlike ($output, qr/2.+B.+one/, 't2 missing');
|
||||
like ($output, qr/2\/13\/2009.+two/, 't3 present');
|
||||
|
||||
# Cleanup.
|
||||
unlink 'import.txt';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue