From 9dd7acac0ba295ebcaec1cda772b5b0ac09c962b Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 26 Jun 2014 23:55:50 -0400 Subject: [PATCH] Task - Simplified dependency modification hnadling. --- src/Task.cpp | 34 ++++++++++++---------------------- test/dependencies.t | 20 +++++++------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 166efd7c3..d76df8645 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1979,30 +1979,20 @@ void Task::modify (modType type, bool text_required /* = false */) std::vector ::iterator i; for (i = deps.begin (); i != deps.end (); i++) { - bool removal = false; - std::string& dep = *i; - - if (dep[0] == '-') + if ((*i)[0] == '-') { - removal = true; - dep = i->substr(1, std::string::npos); - } - - // Crude UUID check - // TODO Support partial UUIDs. - // TODO Do not assume that <36 characaters implies integer. - std::vector ids; - if (dep.length () == 36) - ids.push_back (context.tdb2.pending.id (dep)); - else - ids.push_back (strtol ((*i).c_str (), NULL, 10)); - - std::vector ::iterator id; - for (id = ids.begin (); id != ids.end(); id++) - if (removal) - removeDependency (*id); + if ((*i).length () == 37) + removeDependency (context.tdb2.pending.id ((*i).substr (1))); else - addDependency (*id); + removeDependency (strtol ((*i).substr (1).c_str (), NULL, 10)); + } + else + { + if ((*i).length () == 36) + addDependency (context.tdb2.pending.id ((*i))); + else + addDependency (strtol ((*i).c_str (), NULL, 10)); + } } ++modCount; diff --git a/test/dependencies.t b/test/dependencies.t index 00ad07ee9..0353815e8 100755 --- a/test/dependencies.t +++ b/test/dependencies.t @@ -27,7 +27,7 @@ use strict; use warnings; -use Test::More tests => 47; +use Test::More tests => 41; # Ensure environment has no influence. delete $ENV{'TASKDATA'}; @@ -94,7 +94,6 @@ like ($output, qr/Modified 1 task\./, 'dependencie # [16] unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data for a fresh start'); qx{../src/task rc:dep.rc add One 2>&1}; qx{../src/task rc:dep.rc add Two 2>&1}; @@ -111,7 +110,6 @@ unlike ($output, qr/Modified 1 task\./, 'dependencie # [19] unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data for a fresh start'); qx{../src/task rc:dep.rc add One 2>&1}; qx{../src/task rc:dep.rc add Two 2>&1}; @@ -144,7 +142,6 @@ like ($output, qr/\s1\s+One\s+/, 'dependencies - depends report column reflects # [26] unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data for a fresh start'); qx{../src/task rc:dep.rc add One 2>&1}; qx{../src/task rc:dep.rc add Two 2>&1}; @@ -165,7 +162,6 @@ like ($output, qr/\s1\s+2\s+One\s+/, 'dependencies - depends report column refle # [29] unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data for a fresh start'); qx{../src/task rc:dep.rc add One 2>&1}; qx{../src/task rc:dep.rc add Two 2>&1}; @@ -189,7 +185,6 @@ unlike ($output, qr/fixed/, 'dependencies - user not prompted to fix broken chai # [34] unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data for a fresh start'); qx{../src/task rc:dep.rc add One 2>&1}; qx{../src/task rc:dep.rc add Two 2>&1}; @@ -219,7 +214,6 @@ like ($output, qr/\s1\s+One\s*\n\s2\s+Four\s*\n\s3\s+2\s+Five/, 'dependencies - # [38] unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data for a fresh start'); # Bug when adding a range of dependencies - 'task 3 mod dep:1-2' interprets the # range 1-2 as the id 1 @@ -229,11 +223,11 @@ qx{../src/task rc:dep.rc add test2 2>&1}; qx{../src/task rc:dep.rc add test3 2>&1}; qx{../src/task rc:dep.rc add test4 2>&1}; qx{../src/task rc:dep.rc add test5 2>&1}; -$output = qx{../src/task rc:dep.rc 5 info 2>&1}; -my ($uuid) = $output =~ /UUID\s+(\S+)/; +my $uuid = qx{../src/task rc:dep.rc _get 5.uuid}; +chomp $uuid; -# [39-43] test a comma-separated list of IDs, UUIDs, and ID ranges for creation -qx{../src/task rc:dep.rc add test6 dep:1-3,4,$uuid 2>&1}; +# [38-42] test a comma-separated list of IDs, UUIDs, and ID ranges for creation +qx{../src/task rc:dep.rc add test6 dep:1,2,3,4,$uuid 2>&1}; $output = qx{../src/task rc:dep.rc 6 info 2>&1}; like ($output, qr/test1/ms, 'Dependency appearing for task1'); like ($output, qr/test2/ms, 'Dependency appearing for task2'); @@ -241,8 +235,8 @@ like ($output, qr/test3/ms, 'Dependency appearing for task3'); like ($output, qr/test4/ms, 'Dependency appearing for task4'); like ($output, qr/test5/ms, 'Dependency appearing for task5'); -# [44-48] test a comma-separated list of IDs, UUIDs, and ID ranges for deletion -qx{../src/task rc:dep.rc 6 mod dep:-1-3,-4,-$uuid 2>&1}; +# [43-47] test a comma-separated list of IDs, UUIDs, and ID ranges for deletion +qx{../src/task rc:dep.rc 6 mod dep:-1,-2,-3,-4,-$uuid 2>&1}; $output = qx{../src/task rc:dep.rc 6 info 2>&1}; unlike ($output, qr/test1/ms, 'Dependency not appearing for task1'); unlike ($output, qr/test2/ms, 'Dependency not appearing for task2');