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<int>.
- Updated text.t unit tests.
This commit is contained in:
Paul Beckingham 2010-07-12 01:42:52 -04:00
parent 7e5c0eb9a5
commit 90c40dbebf
6 changed files with 48 additions and 7 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -34,7 +34,7 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (185);
UnitTest t (191);
// void wrapText (std::vector <std::string>& 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<int>& items)
std::vector <int> 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 '' -> ''");

View file

@ -24,7 +24,9 @@
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <strings.h>
@ -142,14 +144,34 @@ void join (
const std::string& separator,
const std::vector<std::string>& 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<int>& 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 ();
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -43,6 +43,7 @@ void split (std::vector<std::string>&, const std::string&, const std::string&);
void split_minimal (std::vector<std::string>&, const std::string&, const char);
void split_minimal (std::vector<std::string>&, const std::string&, const std::string&);
void join (std::string&, const std::string&, const std::vector<std::string>&);
void join (std::string&, const std::string&, const std::vector<int>&);
std::string commify (const std::string&);
std::string lowerCase (const std::string&);
std::string upperCase (const std::string&);