Unit Tests

- Fixed a series of bugs to improve the test suite results.
This commit is contained in:
Paul Beckingham 2009-06-28 01:04:23 -04:00
parent f3d3126839
commit ce4f26bdf3
7 changed files with 32 additions and 22 deletions

View file

@ -69,7 +69,7 @@ bool Sequence::valid (const std::string& input) const
range.size () > 2)
return false;
if (range.size () == 1 && !validId (range[0]))
if (range.size () <= 2 && !validId (range[0]))
return false;
if (range.size () == 2 && !validId (range[1]))

View file

@ -856,9 +856,10 @@ std::string handleModify ()
{
std::string question = taskDifferences (before, *other) + "Are you sure?";
if (changes && permission.confirmed (question))
{
context.tdb.update (*other);
++count;
++count;
}
}
}
}

View file

@ -165,6 +165,8 @@ static void decorateTask (Task& task)
sprintf (entryTime, "%u", (unsigned int) time (NULL));
task.set ("entry", entryTime);
task.setStatus (Task::pending);
// Override with default.project, if not specified.
std::string defaultProject = context.config.get ("default.project", "");
if (!task.has ("project") && defaultProject != "")
@ -672,8 +674,8 @@ static std::string importTaskCmdLine (const std::vector <std::string>& lines)
try
{
std::vector <std::string> args;
split (args, std::string ("add ") + line, ' ');
context.args.clear ();
split (context.args, std::string ("add ") + line, ' ');
context.task.clear ();
context.cmd.command = "";
@ -719,8 +721,8 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
{
try
{
std::vector <std::string> args;
args.push_back ("add");
context.args.clear ();
context.args.push_back ("add");
bool isPending = true;
Date endDate;
@ -733,8 +735,8 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
if (words[w].length () > 1 &&
words[w][0] == '+')
{
args.push_back (std::string ("project:") +
words[w].substr (1, std::string::npos));
context.args.push_back (std::string ("project:") +
words[w].substr (1, std::string::npos));
}
// Convert "+aaa" to "project:aaa".
@ -742,8 +744,8 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
else if (words[w].length () > 1 &&
words[w][0] == '@')
{
args.push_back (std::string ("+") +
words[w].substr (1, std::string::npos));
context.args.push_back (std::string ("+") +
words[w].substr (1, std::string::npos));
}
// Convert "(A)" to "priority:H".
@ -753,9 +755,9 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
words[w][0] == '(' &&
words[w][2] == ')')
{
if (words[w][1] == 'A') args.push_back ("priority:H");
else if (words[w][1] == 'B') args.push_back ("priority:M");
else args.push_back ("priority:L");
if (words[w][1] == 'A') context.args.push_back ("priority:H");
else if (words[w][1] == 'B') context.args.push_back ("priority:M");
else context.args.push_back ("priority:L");
}
// Set status, if completed.
@ -778,7 +780,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
// Just an ordinary word.
else
{
args.push_back (words[w]);
context.args.push_back (words[w]);
}
}
@ -855,8 +857,8 @@ static std::string importText (const std::vector <std::string>& lines)
try
{
++count;
std::vector <std::string> args;
split (args, std::string ("add ") + line, ' ');
context.args.clear ();
split (context.args, std::string ("add ") + line, ' ');
context.task.clear ();
context.cmd.command = "";
@ -1057,6 +1059,7 @@ static std::string importCSV (const std::vector <std::string>& lines)
if ((f = mapping["uuid"]) != -1)
task.set ("uuid", lowerCase (unquoteText (trim (fields[f]))));
task.setStatus (Task::pending);
if ((f = mapping["status"]) != -1)
{
std::string value = lowerCase (unquoteText (trim (fields[f])));
@ -1065,7 +1068,6 @@ static std::string importCSV (const std::vector <std::string>& lines)
else if (value == "deleted") task.setStatus (Task::deleted);
else if (value == "completed") task.setStatus (Task::completed);
else if (value == "waiting") task.setStatus (Task::waiting);
else task.setStatus (Task::pending);
}
if ((f = mapping["tags"]) != -1)
@ -1183,7 +1185,7 @@ std::string handleImport ()
case task_cmd_line: identifier = "This looks like task command line arguments."; break;
case todo_sh_2_0: identifier = "This looks like a todo.sh 2.x file."; break;
case csv: identifier = "This looks like a CSV file, but not a task export file."; break;
case text: identifier = "This looks like a text file with one tasks per line."; break;
case text: identifier = "This looks like a text file with one task per line."; break;
case not_a_clue:
throw std::string ("Task cannot determine which type of file this is, "
"and cannot proceed.");

View file

@ -33,7 +33,8 @@ use Test::More tests => 8;
# Create the rc file.
if (open my $fh, '>', 'args.rc')
{
print $fh "data.location=.\n";
print $fh "data.location=.\n",
"confirmation=no\n";
close $fh;
ok (-r 'args.rc', 'Created args.rc');
}

View file

@ -33,7 +33,8 @@ use Test::More tests => 6;
# Create the rc file.
if (open my $fh, '>', 'bug_concat.rc')
{
print $fh "data.location=.\n";
print $fh "data.location=.\n",
"confirmation=no\n";
close $fh;
ok (-r 'bug_concat.rc', 'Created bug_concat.rc');
}

View file

@ -54,7 +54,13 @@ like ($output, qr/Imported 2 tasks successfully, with 0 errors./, 'no errors');
$output = qx{../task rc:import.rc list};
like ($output, qr/1.+H.+this is a test/, 't1');
diag ("---");
diag ($output);
diag ("---");
like ($output, qr/2.+another task/, 't2');
diag ("---");
diag ($output);
diag ("---");
# Cleanup.
unlink 'import.txt';

View file

@ -449,7 +449,6 @@ bool taskDiff (const Task& before, const Task& after)
foreach (name, beforeAtts)
if (*name != "uuid" &&
after.get (*name) != "" &&
before.get (*name) != after.get (*name))
return true;