=================================================================== RCS file: /cvs/todotxt/Text-Todo/t/read_todo.t,v retrieving revision 1.2 retrieving revision 1.7 diff -u -r1.2 -r1.7 --- todotxt/Text-Todo/t/read_todo.t 2009/07/13 18:50:37 1.2 +++ todotxt/Text-Todo/t/read_todo.t 2010/01/11 01:20:09 1.7 @@ -8,68 +8,121 @@ # AUTHOR: Andrew Fresh (AAF), andrew@cpan.org # COMPANY: Red River Communications # CREATED: 07/09/09 11:45:52 -# REVISION: $RedRiver: 50.read_todo.t,v 1.1 2009/07/10 22:26:14 andrew Exp $ +# REVISION: $RedRiver: read_todo.t,v 1.6 2010/01/11 01:08:35 andrew Exp $ #=============================================================================== use strict; use warnings; use File::Spec; -use Test::More tests => 28; +use File::Temp qw/ tempdir /; +use Test::More tests => 138; 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 = ( { text => '(B) +GarageSale @phone schedule Goodwill pickup', priority => 'B', contexts => ['phone'], projects => ['GarageSale'], + done => undef, }, { text => '+GarageSale @home post signs around the neighborhood DUE:2006-08-01', priority => undef, contexts => ['home'], projects => ['GarageSale'], + done => undef, }, - { text => 'eat meatballs @home', + { text => 'X eat meatballs @home', priority => undef, contexts => ['home'], projects => [], + done => 'X', }, { text => '(A) @phone thank Mom for the meatballs WAIT', priority => 'A', contexts => ['phone'], projects => [], + done => undef, }, + { text => '', + priority => undef, + contexts => [], + projects => [], + done => undef, + }, { text => '@shopping Eskimo pies', priority => undef, contexts => ['shopping'], 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' ) } -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($todo_file), "Load file [$todo_file]" ); -my $list; -ok( $list = $todo->list, 'Get list' ); +#my $bad_todo = new_ok('Text::Todo' => [ $new_todo_file ]); +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 ) { - my $sample = $todos[$id]; - my $read = $list->[$id]; + my $t = ok( $new_todo->add( $todos[$id]->{text} ), "Add Todo [$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->priority, $sample->{priority}, "check priority [$id]" ); + is( $read->done, $sample->{done}, "check completion [$id]" ); is_deeply( [ $read->contexts ], $sample->{contexts},