From 90c40dbebfbcb7c5c51a28e2e982d6ad9ff88958 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 12 Jul 2010 01:42:52 -0400 Subject: [PATCH] Dependencies - Added 'depends' as a valid report column. - Added 'depends' to the 'long' report. - Updated hook.format*t unit tests to accommodate new long report. - Added new join () function that handles std::vector. - Updated text.t unit tests. --- src/tests/hook.format-countdown_compact.t | 2 +- src/tests/hook.format-entry_time.t | 2 +- src/tests/hook.format-start_time.t | 2 +- src/tests/text.t.cpp | 20 +++++++++++++++- src/text.cpp | 28 ++++++++++++++++++++--- src/text.h | 1 + 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/tests/hook.format-countdown_compact.t b/src/tests/hook.format-countdown_compact.t index 99dd05823..6240e317c 100755 --- a/src/tests/hook.format-countdown_compact.t +++ b/src/tests/hook.format-countdown_compact.t @@ -35,7 +35,7 @@ if (open my $fh, '>', 'hook.rc') { print $fh "data.location=.\n", "report.long.columns=id,project,priority,entry,start_time,due,", - "recur,countdown_compact,age,tags,description\n", + "recur,countdown_compact,age,depends,tags,description\n", "hooks=on\n", "hook.format-countdown_compact=" . $ENV{'PWD'} . "/hook:countdown_compact\n"; close $fh; diff --git a/src/tests/hook.format-entry_time.t b/src/tests/hook.format-entry_time.t index 45c297311..86ab54536 100755 --- a/src/tests/hook.format-entry_time.t +++ b/src/tests/hook.format-entry_time.t @@ -34,7 +34,7 @@ use Test::More tests => 7; if (open my $fh, '>', 'hook.rc') { print $fh "data.location=.\n", - "report.long.columns=id,project,priority,entry_time,start,due,recur,countdown,age,tags,description\n", + "report.long.columns=id,project,priority,entry_time,start,due,recur,countdown,age,depends,tags,description\n", "hooks=on\n", "hook.format-entry_time=" . $ENV{'PWD'} . "/hook:entry_time\n"; close $fh; diff --git a/src/tests/hook.format-start_time.t b/src/tests/hook.format-start_time.t index 3e6ea16f1..fa5d472ef 100755 --- a/src/tests/hook.format-start_time.t +++ b/src/tests/hook.format-start_time.t @@ -34,7 +34,7 @@ use Test::More tests => 7; if (open my $fh, '>', 'hook.rc') { print $fh "data.location=.\n", - "report.long.columns=id,project,priority,entry,start_time,due,recur,countdown,age,tags,description\n", + "report.long.columns=id,project,priority,entry,start_time,due,recur,countdown,age,depends,tags,description\n", "hooks=on\n", "hook.format-start_time=" . $ENV{'PWD'} . "/hook:start_time\n"; close $fh; diff --git a/src/tests/text.t.cpp b/src/tests/text.t.cpp index a42896cf1..90b33f588 100644 --- a/src/tests/text.t.cpp +++ b/src/tests/text.t.cpp @@ -34,7 +34,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (185); + UnitTest t (191); // void wrapText (std::vector & lines, const std::string& text, const int width) std::string text = "This is a test of the line wrapping code."; @@ -178,6 +178,24 @@ int main (int argc, char** argv) t.is (joined.length (), (size_t) 9, "join '' - 'a' - 'bc' - 'def' -> length 9"); t.is (joined, "-a-bc-def", "join '' - 'a' - 'bc' - 'def' -> '-a-bc-def'"); + // void join (std::string& result, const std::string& separator, const std::vector& items) + std::vector unjoined2; + + join (joined, "", unjoined2); + t.is (joined.length (), (size_t) 0, "join -> length 0"); + t.is (joined, "", "join -> ''"); + + unjoined2.push_back (0); + unjoined2.push_back (1); + unjoined2.push_back (2); + join (joined, "", unjoined2); + t.is (joined.length (), (size_t) 3, "join 0 1 2 -> length 3"); + t.is (joined, "012", "join 0 1 2 -> '012'"); + + join (joined, "-", unjoined2); + t.is (joined.length (), (size_t) 5, "join 0 1 2 -> length 5"); + t.is (joined, "0-1-2", "join 0 1 2 -> '0-1-2'"); + // std::string trimLeft (const std::string& in, const std::string& t /*= " "*/) t.is (trimLeft (""), "", "trimLeft '' -> ''"); t.is (trimLeft ("", " \t"), "", "trimLeft '' -> ''"); diff --git a/src/text.cpp b/src/text.cpp index 2b7b0f9f9..01505dd00 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -24,7 +24,9 @@ // USA // //////////////////////////////////////////////////////////////////////////////// + #include +#include #include #include #include @@ -142,14 +144,34 @@ void join ( const std::string& separator, const std::vector& items) { - result = ""; + std::stringstream s; unsigned int size = items.size (); for (unsigned int i = 0; i < size; ++i) { - result += items[i]; + s << items[i]; if (i < size - 1) - result += separator; + s << separator; } + + result = s.str (); +} + +//////////////////////////////////////////////////////////////////////////////// +void join ( + std::string& result, + const std::string& separator, + const std::vector& items) +{ + std::stringstream s; + unsigned int size = items.size (); + for (unsigned int i = 0; i < size; ++i) + { + s << items[i]; + if (i < size - 1) + s << separator; + } + + result = s.str (); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/text.h b/src/text.h index 886c13ea6..d17263b23 100644 --- a/src/text.h +++ b/src/text.h @@ -43,6 +43,7 @@ void split (std::vector&, const std::string&, const std::string&); void split_minimal (std::vector&, const std::string&, const char); void split_minimal (std::vector&, const std::string&, const std::string&); void join (std::string&, const std::string&, const std::vector&); +void join (std::string&, const std::string&, const std::vector&); std::string commify (const std::string&); std::string lowerCase (const std::string&); std::string upperCase (const std::string&);