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

Annotation of todotxt/Text-Todo/t/list.t, Revision 1.11

1.1       andrew      1: #===============================================================================
                      2: #
                      3: #         FILE:  list.t
                      4: #
                      5: #  DESCRIPTION:  Test list commands
                      6: #
                      7: #
                      8: #       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
                      9: #      COMPANY:  Red River Communications
                     10: #      CREATED:  01/07/10 19:11
1.11    ! andrew     11: #     REVISION:  $AFresh1: list.t,v 1.10 2010/01/15 19:44:32 andrew Exp $
1.1       andrew     12: #===============================================================================
                     13:
                     14: use strict;
                     15: use warnings;
                     16:
1.8       andrew     17: use Test::More tests => 53;
1.2       andrew     18:
                     19: use File::Temp qw/ tempdir /;
1.1       andrew     20:
1.11    ! andrew     21: my $class;
        !            22: BEGIN {
        !            23:        $class = 'Text::Todo';
        !            24:        use_ok( $class, "use $class" )
        !            25: }
1.1       andrew     26:
                     27: diag("Testing entry $class $Text::Todo::VERSION");
                     28:
1.2       andrew     29: my $orig = new_ok( $class, ['t/todo.list.txt'] );
                     30: my @orig_list;
                     31: ok( @orig_list = $orig->list, 'get orig list' );
                     32:
                     33: is( $orig->file('todo_file'), 't/todo.list.txt', 'orig todo_file matches' );
                     34: is( $orig->file('done_file'), 't/done.list.txt', 'orig done_file matches' );
                     35: is( $orig->file('report_file'),
                     36:     't/report.list.txt', 'orig report_file matches' );
                     37:
                     38: my $todo_dir = tempdir( 'todo-XXXXXXXXX', CLEANUP => 1, TMPDIR => 1 );
                     39: my $copy = new_ok($class);
                     40:
                     41: foreach my $e (@orig_list) {
                     42:     ok( $copy->add($e), 'add entry from orginal list' );
                     43: }
                     44: ok( $copy->save( $todo_dir . '/todo.txt' ), 'save the copy' );
                     45:
                     46: is( $copy->file('todo_file'),
                     47:     $todo_dir . '/todo.txt',
                     48:     'copy todo_file matches'
                     49: );
                     50: is( $copy->file('done_file'),
                     51:     $todo_dir . '/done.txt',
                     52:     'copy done_file matches'
                     53: );
                     54: is( $copy->file('report_file'),
                     55:     $todo_dir . '/report.txt',
                     56:     'copy report_file matches'
                     57: );
                     58: my @copy_list;
                     59: ok( @copy_list = $copy->list, 'get copy list' );
1.1       andrew     60:
1.2       andrew     61: for my $id ( 0 .. $#orig_list ) {
                     62:     is( $copy_list[$id]->text, $orig_list[$id]->text, "Entry $id matches" );
                     63: }
                     64:
                     65: $orig = undef;
                     66:
                     67: my @pri_list;
1.8       andrew     68: ok( @pri_list = $copy->listpri('A'), 'list priority item' );
1.2       andrew     69: is( scalar @pri_list, 1, 'only 1 item in the priority list' );
                     70: is( $pri_list[0]->text, '(A) entry 1 @one +uno', 'priority item is correct' );
                     71:
                     72: my $entry_to_move = $copy_list[-1];
                     73: ok( $copy->move( $entry_to_move, 1 ), 'move entry to position 1' );
                     74: ok( @copy_list = $copy->list, 'update our list' );
                     75: is( $copy_list[1]->text, $entry_to_move->text,
                     76:     'entry is in the new position' );
                     77:
                     78: $entry_to_move = $copy_list[3];
                     79: ok( $copy->move( 3, 1 ), 'move entry 3 to position 1' );
                     80: ok( @copy_list = $copy->list, 'update our list' );
                     81: is( $copy_list[1]->text, $entry_to_move->text,
                     82:     'entry is in the new position' );
                     83:
                     84: my @projects;
                     85: ok( @projects = $copy->listproj, 'listproj for current list' );
                     86: is_deeply(
                     87:     \@projects,
                     88:     [ 'delete', 'dos', 'uno' ],
                     89:     'got the projects we expected'
1.1       andrew     90: );
                     91:
1.2       andrew     92: for my $id ( 0 .. $#copy_list ) {
                     93:     my $e = $copy_list[$id];
                     94:     if ( $e->in_project('delete') ) {
                     95:         ok( $copy->del($e), "deleting entry $id" );
                     96:         isnt( $copy->list->[$id]->text, $e->text, 'Entry seems to be gone' );
                     97:     }
                     98: }
                     99:
                    100: ok( @projects = $copy->listproj, 'listproj for current list' );
                    101: is_deeply( \@projects, [ 'dos', 'uno' ], 'got the projects we expected' );
1.8       andrew    102:
                    103: my @contexts;
                    104: ok( @contexts = $copy->listcon, 'listcon for current list' );
                    105: is_deeply( \@contexts, [ 'one', 'two' ], 'got the contexts we expected' );
1.2       andrew    106:
1.3       andrew    107: my $entry_to_archive;
1.6       andrew    108: ok( $entry_to_archive = $copy->list->[3], 'read entry_to_archive' );
1.3       andrew    109: is( $entry_to_archive->text,
1.6       andrew    110:     'x completed entry 4',
1.3       andrew    111:     'make sure we got the right entry'
                    112: );
                    113:
1.4       andrew    114: ok( $copy->archive, 'archive done items' );
                    115: isnt( $copy->list->[1]->text,
                    116:     $entry_to_archive->text, 'make sure it changed' );
                    117:
                    118: ok( $copy->load('done_file'), 'read the done_file' );
                    119: is( $copy->list->[-1]->text,
                    120:     $entry_to_archive->text, 'make sure it moved to the archive' );
1.2       andrew    121:
1.3       andrew    122: my $file;
                    123: ok( $file = $copy->file('done_file'), 'get the done_file name' );
                    124: is( $file, $todo_dir . '/done.txt', 'the done_file name what we expected?' );
                    125:
1.4       andrew    126: ok( $copy->addto( $file, 'added text' ), 'Add text to file' );
1.3       andrew    127:
                    128: my @done;
                    129: ok( @done = $copy->listfile('done_file'), 'get items in done_file' );
                    130: is( $done[-1]->text, 'added text', 'make sure what we added is there' );
1.2       andrew    131:
1.4       andrew    132: is( $done[-2]->text, $entry_to_archive->text,
                    133:     'make sure it moved to the archive' );
1.2       andrew    134:
1.7       andrew    135: #done_testing();

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