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

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

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