- Fix #1056: the 'projects' command now outputs abstract parents
  and reduces repetition by not printing parent names in front of
  children names.
- Project name indentation is not affected by the first character
  being a period and/or the last character being a period.
- Unit tests for above.
This commit is contained in:
Scott Kostyshak
2012-09-21 16:29:32 -04:00
committed by Paul Beckingham
parent a3242f7b5b
commit be5dc8ab90
6 changed files with 147 additions and 8 deletions

View File

@@ -28,7 +28,7 @@
use strict;
use warnings;
use Test::More tests => 11;
use Test::More tests => 18;
# Create the rc file.
if (open my $fh, '>', 'pro.rc')
@@ -66,6 +66,91 @@ like ($output, qr/The project 'bar' has changed\. Project 'bar' is 0% complete
$output = qx{../src/task rc:pro.rc 3 modify pro:\\"foo bar\\" 2>&1 >/dev/null};
like ($output, qr/The project 'foo bar' has changed\./, 'project with spaces');
# Bug 1056: Project indentation.
# see also the tests of helper functions for CmdProjects in util.t.cpp
qx{../src/task rc:pro.rc add testing project:existingParent 2>&1 >/dev/null};
qx{../src/task rc:pro.rc add testing project:existingParent.child 2>&1 >/dev/null};
qx{../src/task rc:pro.rc add testing project:abstractParent.kid 2>&1 >/dev/null};
qx{../src/task rc:pro.rc add testing project:.myProject 2>&1 >/dev/null};
qx{../src/task rc:pro.rc add testing project:myProject. 2>&1 >/dev/null};
qx{../src/task rc:pro.rc add testing project:.myProject. 2>&1 >/dev/null};
$output = qx{../src/task rc:pro.rc projects 2>&1};
my @lines = split ('\n',$output);
# It's easier to make a pattern for the end than the beginning because priority
# counts are more predictable than project names.
my $project_name_column;
if ($lines[4] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = $lines[4];
}
else
{
$project_name_column = "error";
}
like ($project_name_column, qr/^\.myProject\s*$/, '\'.myProject\' not indented');
if ($lines[5] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = $lines[5];
}
else
{
$project_name_column = "error";
}
like ($project_name_column, qr/^\.myProject\.\s*$/, '\'.myProject.\' not indented');
if ($lines[6] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = "error";
}
else
{
$project_name_column = $lines[6];
}
like ($project_name_column, qr/^abstractParent\s*$/, 'abstract parent not indented and no priority columns');
if ($lines[7] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = $lines[7];
}
else
{
$project_name_column = "error";
}
like ($project_name_column, qr/^ kid\s*$/, 'child indented and without parent name');
if ($lines[8] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = $lines[8];
}
else
{
$project_name_column = "error";
}
like ($project_name_column, qr/^existingParent\s*$/, 'existing parent not indented and has priority columns');
if ($lines[9] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = $lines[9];
}
else
{
$project_name_column = "error";
}
like ($project_name_column, qr/^ child\s*$/, 'child of existing parent indented and without parent name');
if ($lines[12] =~ s/\d+\s+\d+\s+\d+\s+\d+\s+\d+$//)
{
$project_name_column = $lines[12];
}
else
{
$project_name_column = "error";
}
like ($project_name_column, qr/^myProject\.\s*$/, '\'myProject.\' not indented');
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data synch.key pro.rc);
ok (! -r 'pending.data' &&

View File

@@ -113,6 +113,7 @@ int main (int argc, char** argv)
t.is (vleft[3], 4, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5");
t.is (vleft[4], 5, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5");
// see also indirect tests of indentProject and extractParents in `project.t'.
// std::vector<std::string> indentTree (const std::vector<std::string>&, const std::string whitespace=" ", char delimiter='.');
std::vector <std::string> flat;
flat.push_back ("one");
@@ -124,16 +125,16 @@ int main (int argc, char** argv)
std::vector <std::string> structured = indentTree (flat, " ", '.');
t.is (structured.size (), (size_t) 5, "indentTree yields 5 strings");
t.is (structured[0], "one", "indentTree 'one' -> 'one'");
t.is (structured[1], " one.two", "indentTree 'one.two' -> ' one.two'");
t.is (structured[2], " one.two.three", "indentTree 'one.two.three' -> ' one.two.three'");
t.is (structured[3], " one.four", "indentTree 'one.four' -> ' one.four'");
t.is (structured[1], " two", "indentTree 'one.two' -> ' two'");
t.is (structured[2], " three", "indentTree 'one.two.three' -> ' three'");
t.is (structured[3], " four", "indentTree 'one.four' -> ' four'");
t.is (structured[4], "two", "indentTree 'two' -> 'two'");
// std::vector<std::string> indentProject (const std::string&, const std::string whitespace=" ", char delimiter='.');
t.is (indentProject (""), "", "indentProject '' -> ''");
t.is (indentProject ("one"), "one", "indentProject 'one' -> 'one'");
t.is (indentProject ("one.two"), " one.two", "indentProject 'one.two' -> ' one.two'");
t.is (indentProject ("one.two.three"), " one.two.three", "indentProject 'one.two.three' -> ' one.two.three'");
t.is (indentProject ("one.two"), " two", "indentProject 'one.two' -> ' two'");
t.is (indentProject ("one.two.three"), " three", "indentProject 'one.two.three' -> ' three'");
// TODO const std::string encode (const std::string& value);
// TODO const std::string decode (const std::string& value);