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

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

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