[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.5

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.5     ! andrew     11: #     REVISION:  $RedRiver: read_todo.t,v 1.4 2010/01/08 23:06:09 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.5     ! andrew     18: use Test::More tests => 122;
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.1       andrew     69:     },
                     70: );
                     71:
1.3       andrew     72: my %extra_todo = (
                     73:     text     => '+test+everything hope there are no bugs @continually',
                     74:     priority => undef,
                     75:     contexts => ['continually'],
                     76:     projects => ['test+everything'],
1.5     ! andrew     77:     done     => undef,
1.3       andrew     78: );
                     79:
1.1       andrew     80: BEGIN: { use_ok( 'Text::Todo', 'use Text::Todo' ) }
                     81:
1.3       andrew     82: diag("Testing read Text::Todo $Text::Todo::VERSION");
1.1       andrew     83:
1.3       andrew     84: my $todo = new_ok( 'Text::Todo' => [], 'Empty todo' );
1.1       andrew     85:
                     86: #ok( $todo->load(), 'Load no file');
                     87:
                     88: ok( $todo->load($todo_file), "Load file [$todo_file]" );
                     89:
1.3       andrew     90: #my $bad_todo = new_ok('Text::Todo' => [ $new_todo_file ]);
                     91:
                     92: ok( $todo->save($dup_todo_file), "Save to tempfile" );
                     93:
                     94: my $dup_todo = new_ok( 'Text::Todo' => [$dup_todo_file], 'New todo' );
                     95:
                     96: ok( $todo->load($todo_file), "Load file [$todo_file]" );
                     97:
                     98: my $new_todo = new_ok( 'Text::Todo' => [], 'Empty todo' );
1.1       andrew     99:
                    100: for my $id ( 0 .. $#todos ) {
1.3       andrew    101:     my $t = ok( $new_todo->add( $todos[$id]->{text} ), "Add Todo [$id]" );
                    102: }
1.1       andrew    103:
1.3       andrew    104: foreach my $t ( $todo, $dup_todo, $new_todo ) {
                    105:     my $list;
                    106:     my $file = $t->file || 'unsaved';
                    107:     ok( $list = $t->list, 'Get list from ' . $file );
                    108:
                    109:     for my $id ( 0 .. $#todos ) {
1.5     ! andrew    110:         test_todo( $todos[$id], $list->[$id], $id );
1.3       andrew    111:     }
1.1       andrew    112: }
1.3       andrew    113:
                    114: sub test_todo {
1.5     ! andrew    115:     my ( $sample, $read, $id ) = @_;
1.3       andrew    116:
1.5     ! andrew    117:     is( $read->text,     $sample->{text},     "check text [$id]" );
        !           118:     is( $read->priority, $sample->{priority}, "check priority [$id]" );
        !           119:     is( $read->done,     $sample->{done},     "check completion [$id]" );
        !           120:     is_deeply(
        !           121:         [ $read->contexts ],
        !           122:         $sample->{contexts},
        !           123:         "check contexts [$id]"
        !           124:     );
        !           125:     is_deeply(
        !           126:         [ $read->projects ],
        !           127:         $sample->{projects},
        !           128:         "check projects [$id]"
        !           129:     );
        !           130: }

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