version 1.1, 2009/07/10 23:26:14 |
version 1.7, 2010/01/11 01:20:09 |
|
|
# AUTHOR: Andrew Fresh (AAF), andrew@cpan.org |
# AUTHOR: Andrew Fresh (AAF), andrew@cpan.org |
# COMPANY: Red River Communications |
# COMPANY: Red River Communications |
# CREATED: 07/09/09 11:45:52 |
# CREATED: 07/09/09 11:45:52 |
# REVISION: $RedRiver$ |
# REVISION: $RedRiver: read_todo.t,v 1.6 2010/01/11 01:08:35 andrew Exp $ |
#=============================================================================== |
#=============================================================================== |
|
|
use strict; |
use strict; |
use warnings; |
use warnings; |
use File::Spec; |
use File::Spec; |
use Test::More tests => 24; |
use File::Temp qw/ tempdir /; |
|
use Test::More tests => 138; |
|
|
my $todo_file = File::Spec->catfile( 't', 'todo1.txt' ); |
my $todo_file = File::Spec->catfile( 't', 'todo1.txt' ); |
|
my $tempdir = tempdir( 'todotxt-XXXXXXX', CLEANUP => 1 ); |
|
my $dup_todo_file = File::Spec->catfile( $tempdir, 'todo50_dup.txt' ); |
|
|
|
#my $new_todo_file = File::Spec->catfile( $tempdir, 'todo50_new.txt' ); |
|
|
my @todos = ( |
my @todos = ( |
{ text => '(B) +GarageSale @phone schedule Goodwill pickup', |
{ text => '(B) +GarageSale @phone schedule Goodwill pickup', |
priority => 'B', |
priority => 'B', |
contexts => ['phone'], |
contexts => ['phone'], |
projects => ['GarageSale'], |
projects => ['GarageSale'], |
|
done => undef, |
}, |
}, |
{ text => |
{ text => |
'+GarageSale @home post signs around the neighborhood DUE:2006-08-01', |
'+GarageSale @home post signs around the neighborhood DUE:2006-08-01', |
priority => undef, |
priority => undef, |
contexts => ['home'], |
contexts => ['home'], |
projects => ['GarageSale'], |
projects => ['GarageSale'], |
|
done => undef, |
}, |
}, |
{ text => 'eat meatballs @home', |
{ text => 'X eat meatballs @home', |
priority => undef, |
priority => undef, |
contexts => ['home'], |
contexts => ['home'], |
projects => [], |
projects => [], |
|
done => 'X', |
}, |
}, |
{ text => '(A) @phone thank Mom for the meatballs WAIT', |
{ text => '(A) @phone thank Mom for the meatballs WAIT', |
priority => 'A', |
priority => 'A', |
contexts => ['phone'], |
contexts => ['phone'], |
projects => [], |
projects => [], |
|
done => undef, |
}, |
}, |
|
{ text => '', |
|
priority => undef, |
|
contexts => [], |
|
projects => [], |
|
done => undef, |
|
}, |
{ text => '@shopping Eskimo pies', |
{ text => '@shopping Eskimo pies', |
priority => undef, |
priority => undef, |
contexts => ['shopping'], |
contexts => ['shopping'], |
projects => [], |
projects => [], |
|
done => undef, |
}, |
}, |
|
{ text => 'email andrew@cpan.org for help +report_bug @wherever', |
|
priority => undef, |
|
contexts => ['wherever'], |
|
projects => ['report_bug'], |
|
done => undef, |
|
}, |
|
{ text => 'x 2009-01-01 completed with a date', |
|
priority => undef, |
|
contexts => [], |
|
projects => [], |
|
done => '2009-01-01', |
|
}, |
); |
); |
|
|
|
my %extra_todo = ( |
|
text => '+test+everything hope there are no bugs @continually', |
|
priority => undef, |
|
contexts => ['continually'], |
|
projects => ['test+everything'], |
|
done => undef, |
|
); |
|
|
BEGIN: { use_ok( 'Text::Todo', 'use Text::Todo' ) } |
BEGIN: { use_ok( 'Text::Todo', 'use Text::Todo' ) } |
|
|
diag("Testing 50 read Text::Todo $Text::Todo::VERSION"); |
diag("Testing read Text::Todo $Text::Todo::VERSION"); |
|
|
my $todo = new_ok('Text::Todo'); |
my $todo = new_ok( 'Text::Todo' => [], 'Empty todo' ); |
|
|
#ok( $todo->load(), 'Load no file'); |
#ok( $todo->load(), 'Load no file'); |
|
|
ok( $todo->load($todo_file), "Load file [$todo_file]" ); |
ok( $todo->load($todo_file), "Load file [$todo_file]" ); |
|
|
my $list; |
#my $bad_todo = new_ok('Text::Todo' => [ $new_todo_file ]); |
ok( $list = $todo->list, 'Get list' ); |
|
|
|
|
ok( $todo->save($dup_todo_file), "Save to tempfile" ); |
|
|
|
my $dup_todo = new_ok( 'Text::Todo' => [$dup_todo_file], 'New todo' ); |
|
|
|
ok( $todo->load($todo_file), "Load file [$todo_file]" ); |
|
|
|
my $new_todo = new_ok( 'Text::Todo' => [], 'Empty todo' ); |
|
|
for my $id ( 0 .. $#todos ) { |
for my $id ( 0 .. $#todos ) { |
my $sample = $todos[$id]; |
my $t = ok( $new_todo->add( $todos[$id]->{text} ), "Add Todo [$id]" ); |
my $read = $list->[$id]; |
} |
|
|
|
foreach my $t ( $todo, $dup_todo, $new_todo ) { |
|
my $list; |
|
my $file = $t->file || 'unsaved'; |
|
ok( $list = $t->list, 'Get list from ' . $file ); |
|
|
|
for my $id ( 0 .. $#todos ) { |
|
test_todo( $todos[$id], $list->[$id], $id ); |
|
} |
|
} |
|
|
|
sub test_todo { |
|
my ( $sample, $read, $id ) = @_; |
|
|
is( $read->text, $sample->{text}, "check text [$id]" ); |
is( $read->text, $sample->{text}, "check text [$id]" ); |
is( $read->priority, $sample->{priority}, "check priority [$id]" ); |
is( $read->priority, $sample->{priority}, "check priority [$id]" ); |
|
is( $read->done, $sample->{done}, "check completion [$id]" ); |
is_deeply( |
is_deeply( |
[ $read->contexts ], |
[ $read->contexts ], |
$sample->{contexts}, |
$sample->{contexts}, |