File Import

- Implemented all remaining import functionality.
This commit is contained in:
Paul Beckingham 2009-03-29 17:42:11 -04:00
parent 5f4563af2f
commit 25425614b1
6 changed files with 354 additions and 22 deletions

70
src/tests/import.csv.t Executable file
View file

@ -0,0 +1,70 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2009, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 8;
# Create the rc file.
if (open my $fh, '>', 'import.rc')
{
print $fh "data.location=.\n";
close $fh;
ok (-r 'import.rc', 'Created import.rc');
}
# Create import file.
if (open my $fh, '>', 'import.txt')
{
print $fh "'id','priority','description'\n",
"1,H,'this is a test'\n",
"2,,'another task'\n",
"\n";
close $fh;
ok (-r 'import.txt', 'Created sample import data');
}
my $output = qx{../task rc:import.rc import import.txt};
is ($output, "Imported 2 tasks successfully, with 0 errors.\n", 'no errors');
$output = qx{../task rc:import.rc list};
like ($output, qr/1.+H.+this is a test/, 't1');
like ($output, qr/2.+another task/, 't2');
# Cleanup.
unlink 'import.txt';
ok (!-r 'import.txt', 'Removed import.txt');
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'import.rc';
ok (!-r 'import.rc', 'Removed import.rc');
exit 0;

View file

@ -41,7 +41,7 @@ if (open my $fh, '>', 'import.rc')
# Create import file.
if (open my $fh, '>', 'import.txt')
{
print $fh "x 2010-03-25 Walk the dog +project \@context\n",
print $fh "x 2009-03-25 Walk the dog +project \@context\n",
"This is a test +project \@context\n",
"(A) A prioritized task\n",
"\n";

View file

@ -31,7 +31,7 @@
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (78);
UnitTest t (94);
// 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.";
@ -183,6 +183,24 @@ int main (int argc, char** argv)
t.is (trim (" \t xxx \t "), "\t xxx \t", "trim ' \\t xxx \\t ' -> '\\t xxx \\t'");
t.is (trim (" \t xxx \t ", " \t"), "xxx", "trim ' \\t xxx \\t ' -> 'xxx'");
// std::string unquoteText (const std::string& text)
t.is (unquoteText (""), "", "unquoteText '' -> ''");
t.is (unquoteText ("x"), "x", "unquoteText 'x' -> 'x'");
t.is (unquoteText ("'x"), "'x", "unquoteText ''x' -> ''x'");
t.is (unquoteText ("x'"), "x'", "unquoteText 'x'' -> 'x''");
t.is (unquoteText ("\"x"), "\"x", "unquoteText '\"x' -> '\"x'");
t.is (unquoteText ("x\""), "x\"", "unquoteText 'x\"' -> 'x\"'");
t.is (unquoteText ("''"), "", "unquoteText '''' -> ''");
t.is (unquoteText ("'''"), "'", "unquoteText ''''' -> '''");
t.is (unquoteText ("\"\""), "", "unquoteText '\"\"' -> ''");
t.is (unquoteText ("\"\"\""), "\"", "unquoteText '\"\"\"' -> '\"'");
t.is (unquoteText ("''''"), "''", "unquoteText '''''' -> ''''");
t.is (unquoteText ("\"\"\"\""), "\"\"", "unquoteText '\"\"\"\"' -> '\"\"'");
t.is (unquoteText ("'\"\"'"), "\"\"", "unquoteText '''\"\"' -> '\"\"'");
t.is (unquoteText ("\"''\""), "''", "unquoteText '\"''\"' -> ''''");
t.is (unquoteText ("'x'"), "x", "unquoteText ''x'' -> 'x'");
t.is (unquoteText ("\"x\""), "x", "unquoteText '\"x\"' -> 'x'");
// std::string commify (const std::string& data)
t.is (commify (""), "", "commify '' -> ''");
t.is (commify ("1"), "1", "commify '1' -> '1'");