[BACK]Return to read_todo.t CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo / t

Annotation of todotxt/Text-Todo/t/read_todo.t, Revision 1.7

1.1       andrew      1: #
                      2: #===============================================================================
                      3: #
                      4: #         FILE:  50.read_todo.t
                      5: #
                      6: #  DESCRIPTION:  Reads in a sample todo.txt and makes sure it got it correctly
                      7: #
                      8: #       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
                      9: #      COMPANY:  Red River Communications
                     10: #      CREATED:  07/09/09 11:45:52
1.7     ! andrew     11: #     REVISION:  $RedRiver: read_todo.t,v 1.6 2010/01/11 01:08:35 andrew Exp $
1.1       andrew     12: #===============================================================================
                     13:
                     14: use strict;
                     15: use warnings;
                     16: use File::Spec;
1.3       andrew     17: use File::Temp qw/ tempdir /;
1.7     ! andrew     18: use Test::More tests => 138;
1.1       andrew     19:
                     20: my $todo_file = File::Spec->catfile( 't', 'todo1.txt' );
1.3       andrew     21: my $tempdir = tempdir( 'todotxt-XXXXXXX', CLEANUP => 1 );
                     22: my $dup_todo_file = File::Spec->catfile( $tempdir, 'todo50_dup.txt' );
                     23:
                     24: #my $new_todo_file = File::Spec->catfile( $tempdir, 'todo50_new.txt' );
                     25:
1.1       andrew     26: my @todos = (
                     27:     {   text     => '(B) +GarageSale @phone schedule Goodwill pickup',
                     28:         priority => 'B',
                     29:         contexts => ['phone'],
                     30:         projects => ['GarageSale'],
1.5       andrew     31:         done     => undef,
1.1       andrew     32:     },
                     33:     {   text =>
                     34:             '+GarageSale @home post signs around the neighborhood DUE:2006-08-01',
                     35:         priority => undef,
                     36:         contexts => ['home'],
                     37:         projects => ['GarageSale'],
1.5       andrew     38:         done     => undef,
1.1       andrew     39:     },
1.3       andrew     40:     {   text     => 'X eat meatballs @home',
1.1       andrew     41:         priority => undef,
                     42:         contexts => ['home'],
                     43:         projects => [],
1.5       andrew     44:         done     => 'X',
1.1       andrew     45:     },
                     46:     {   text     => '(A) @phone thank Mom for the meatballs WAIT',
                     47:         priority => 'A',
                     48:         contexts => ['phone'],
                     49:         projects => [],
1.5       andrew     50:         done     => undef,
                     51:     },
                     52:     {   text     => '',
                     53:         priority => undef,
                     54:         contexts => [],
                     55:         projects => [],
                     56:         done     => undef,
1.1       andrew     57:     },
                     58:     {   text     => '@shopping Eskimo pies',
                     59:         priority => undef,
                     60:         contexts => ['shopping'],
                     61:         projects => [],
1.5       andrew     62:         done     => undef,
1.2       andrew     63:     },
                     64:     {   text     => 'email andrew@cpan.org for help +report_bug @wherever',
                     65:         priority => undef,
                     66:         contexts => ['wherever'],
                     67:         projects => ['report_bug'],
1.5       andrew     68:         done     => undef,
1.6       andrew     69:     },
                     70:     {   text     => 'x 2009-01-01 completed with a date',
                     71:         priority => undef,
                     72:         contexts => [],
                     73:         projects => [],
                     74:         done     => '2009-01-01',
1.1       andrew     75:     },
                     76: );
                     77:
1.3       andrew     78: my %extra_todo = (
                     79:     text     => '+test+everything hope there are no bugs @continually',
                     80:     priority => undef,
                     81:     contexts => ['continually'],
                     82:     projects => ['test+everything'],
1.5       andrew     83:     done     => undef,
1.3       andrew     84: );
                     85:
1.1       andrew     86: BEGIN: { use_ok( 'Text::Todo', 'use Text::Todo' ) }
                     87:
1.3       andrew     88: diag("Testing read Text::Todo $Text::Todo::VERSION");
1.1       andrew     89:
1.3       andrew     90: my $todo = new_ok( 'Text::Todo' => [], 'Empty todo' );
1.1       andrew     91:
                     92: #ok( $todo->load(), 'Load no file');
                     93:
                     94: ok( $todo->load($todo_file), "Load file [$todo_file]" );
                     95:
1.3       andrew     96: #my $bad_todo = new_ok('Text::Todo' => [ $new_todo_file ]);
                     97:
                     98: ok( $todo->save($dup_todo_file), "Save to tempfile" );
                     99:
                    100: my $dup_todo = new_ok( 'Text::Todo' => [$dup_todo_file], 'New todo' );
                    101:
                    102: ok( $todo->load($todo_file), "Load file [$todo_file]" );
                    103:
                    104: my $new_todo = new_ok( 'Text::Todo' => [], 'Empty todo' );
1.1       andrew    105:
                    106: for my $id ( 0 .. $#todos ) {
1.3       andrew    107:     my $t = ok( $new_todo->add( $todos[$id]->{text} ), "Add Todo [$id]" );
                    108: }
1.1       andrew    109:
1.3       andrew    110: foreach my $t ( $todo, $dup_todo, $new_todo ) {
                    111:     my $list;
                    112:     my $file = $t->file || 'unsaved';
                    113:     ok( $list = $t->list, 'Get list from ' . $file );
                    114:
                    115:     for my $id ( 0 .. $#todos ) {
1.5       andrew    116:         test_todo( $todos[$id], $list->[$id], $id );
1.3       andrew    117:     }
1.1       andrew    118: }
1.3       andrew    119:
                    120: sub test_todo {
1.5       andrew    121:     my ( $sample, $read, $id ) = @_;
1.3       andrew    122:
1.5       andrew    123:     is( $read->text,     $sample->{text},     "check text [$id]" );
                    124:     is( $read->priority, $sample->{priority}, "check priority [$id]" );
                    125:     is( $read->done,     $sample->{done},     "check completion [$id]" );
                    126:     is_deeply(
                    127:         [ $read->contexts ],
                    128:         $sample->{contexts},
                    129:         "check contexts [$id]"
                    130:     );
                    131:     is_deeply(
                    132:         [ $read->projects ],
                    133:         $sample->{projects},
                    134:         "check projects [$id]"
                    135:     );
                    136: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>