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

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.3     ! andrew     11: #     REVISION:  $RedRiver: 50.read_todo.t,v 1.2 2009/07/13 17:50:37 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 /;
        !            18: use Test::More tests => 106;
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.3     ! andrew     31:         complete => 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.3     ! andrew     38:         complete => 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.3     ! andrew     44:         complete => 'X',
1.1       andrew     45:     },
                     46:     {   text     => '(A) @phone thank Mom for the meatballs WAIT',
                     47:         priority => 'A',
                     48:         contexts => ['phone'],
                     49:         projects => [],
1.3     ! andrew     50:         complete => undef,
1.1       andrew     51:     },
                     52:     {   text     => '@shopping Eskimo pies',
                     53:         priority => undef,
                     54:         contexts => ['shopping'],
                     55:         projects => [],
1.3     ! andrew     56:         complete => undef,
1.2       andrew     57:     },
                     58:     {   text     => 'email andrew@cpan.org for help +report_bug @wherever',
                     59:         priority => undef,
                     60:         contexts => ['wherever'],
                     61:         projects => ['report_bug'],
1.3     ! andrew     62:         complete => undef,
1.1       andrew     63:     },
                     64: );
                     65:
1.3     ! andrew     66: my %extra_todo = (
        !            67:     text     => '+test+everything hope there are no bugs @continually',
        !            68:     priority => undef,
        !            69:     contexts => ['continually'],
        !            70:     projects => ['test+everything'],
        !            71:     complete => undef,
        !            72: );
        !            73:
1.1       andrew     74: BEGIN: { use_ok( 'Text::Todo', 'use Text::Todo' ) }
                     75:
1.3     ! andrew     76: diag("Testing read Text::Todo $Text::Todo::VERSION");
1.1       andrew     77:
1.3     ! andrew     78: my $todo = new_ok( 'Text::Todo' => [], 'Empty todo' );
1.1       andrew     79:
                     80: #ok( $todo->load(), 'Load no file');
                     81:
                     82: ok( $todo->load($todo_file), "Load file [$todo_file]" );
                     83:
1.3     ! andrew     84: #my $bad_todo = new_ok('Text::Todo' => [ $new_todo_file ]);
        !            85:
        !            86: ok( $todo->save($dup_todo_file), "Save to tempfile" );
        !            87:
        !            88: my $dup_todo = new_ok( 'Text::Todo' => [$dup_todo_file], 'New todo' );
        !            89:
        !            90: ok( $todo->load($todo_file), "Load file [$todo_file]" );
        !            91:
        !            92: my $new_todo = new_ok( 'Text::Todo' => [], 'Empty todo' );
1.1       andrew     93:
                     94: for my $id ( 0 .. $#todos ) {
1.3     ! andrew     95:     my $t = ok( $new_todo->add( $todos[$id]->{text} ), "Add Todo [$id]" );
        !            96: }
1.1       andrew     97:
1.3     ! andrew     98: foreach my $t ( $todo, $dup_todo, $new_todo ) {
        !            99:     my $list;
        !           100:     my $file = $t->file || 'unsaved';
        !           101:     ok( $list = $t->list, 'Get list from ' . $file );
        !           102:
        !           103:     for my $id ( 0 .. $#todos ) {
        !           104:         test_todo( $todos[$id], $list->[$id], $id);
        !           105:     }
1.1       andrew    106: }
1.3     ! andrew    107:
        !           108: sub test_todo {
        !           109:     my ($sample, $read, $id) = @_;
        !           110:
        !           111:         is( $read->text,      $sample->{text},     "check text [$id]" );
        !           112:         is( $read->priority,  $sample->{priority}, "check priority [$id]" );
        !           113:         is( $read->completed, $sample->{complete}, "check completion [$id]" );
        !           114:         is_deeply(
        !           115:             [ $read->contexts ],
        !           116:             $sample->{contexts},
        !           117:             "check contexts [$id]"
        !           118:         );
        !           119:         is_deeply(
        !           120:             [ $read->projects ],
        !           121:             $sample->{projects},
        !           122:             "check projects [$id]"
        !           123:         );
        !           124:     }

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