| version 1.2, 2009/07/13 18:50:37 | version 1.3, 2010/01/06 19:54:56 | 
|  |  | 
| #       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: 50.read_todo.t,v 1.1 2009/07/10 22:26:14 andrew Exp $ | #     REVISION:  $RedRiver: 50.read_todo.t,v 1.2 2009/07/13 17:50:37 andrew Exp $ | 
| #=============================================================================== | #=============================================================================== | 
|  |  | 
| use strict; | use strict; | 
| use warnings; | use warnings; | 
| use File::Spec; | use File::Spec; | 
| use Test::More tests => 28; | use File::Temp qw/ tempdir /; | 
|  | use Test::More tests => 106; | 
|  |  | 
| 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'], | 
|  | complete => 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'], | 
|  | complete => undef, | 
| }, | }, | 
| {   text     => 'eat meatballs @home', | {   text     => 'X eat meatballs @home', | 
| priority => undef, | priority => undef, | 
| contexts => ['home'], | contexts => ['home'], | 
| projects => [], | projects => [], | 
|  | complete => '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 => [], | 
|  | complete => undef, | 
| }, | }, | 
| {   text     => '@shopping Eskimo pies', | {   text     => '@shopping Eskimo pies', | 
| priority => undef, | priority => undef, | 
| contexts => ['shopping'], | contexts => ['shopping'], | 
| projects => [], | projects => [], | 
|  | complete => undef, | 
| }, | }, | 
| {   text     => 'email andrew@cpan.org for help +report_bug @wherever', | {   text     => 'email andrew@cpan.org for help +report_bug @wherever', | 
| priority => undef, | priority => undef, | 
| contexts => ['wherever'], | contexts => ['wherever'], | 
| projects => ['report_bug'], | projects => ['report_bug'], | 
|  | complete => undef, | 
| }, | }, | 
| ); | ); | 
|  |  | 
|  | my %extra_todo = ( | 
|  | text     => '+test+everything hope there are no bugs @continually', | 
|  | priority => undef, | 
|  | contexts => ['continually'], | 
|  | projects => ['test+everything'], | 
|  | complete => 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]; | } | 
|  |  | 
| is( $read->text,     $sample->{text},     "check text [$id]" ); | foreach my $t ( $todo, $dup_todo, $new_todo ) { | 
| is( $read->priority, $sample->{priority}, "check priority [$id]" ); | my $list; | 
| is_deeply( | my $file = $t->file || 'unsaved'; | 
| [ $read->contexts ], | ok( $list = $t->list, 'Get list from ' . $file ); | 
| $sample->{contexts}, |  | 
| "check contexts [$id]" | for my $id ( 0 .. $#todos ) { | 
| ); | test_todo( $todos[$id], $list->[$id], $id); | 
| is_deeply( | } | 
| [ $read->projects ], |  | 
| $sample->{projects}, |  | 
| "check projects [$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->completed, $sample->{complete}, "check completion [$id]" ); | 
|  | is_deeply( | 
|  | [ $read->contexts ], | 
|  | $sample->{contexts}, | 
|  | "check contexts [$id]" | 
|  | ); | 
|  | is_deeply( | 
|  | [ $read->projects ], | 
|  | $sample->{projects}, | 
|  | "check projects [$id]" | 
|  | ); | 
|  | } |