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

Annotation of todotxt/Text-Todo/t/entry.t, Revision 1.13

1.1       andrew      1: #===============================================================================
                      2: #
1.6       andrew      3: #         FILE:  entry.t
1.1       andrew      4: #
1.6       andrew      5: #  DESCRIPTION:  Test entry commands
1.1       andrew      6: #
                      7: #       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
                      8: #      COMPANY:  Red River Communications
                      9: #      CREATED:  07/10/09 11:32:39
1.13    ! andrew     10: #     REVISION:  $AFresh1: entry.t,v 1.12 2010/01/15 19:44:32 andrew Exp $
1.1       andrew     11: #===============================================================================
                     12:
                     13: use strict;
                     14: use warnings;
                     15:
1.6       andrew     16: use Test::More tests => 40;
1.1       andrew     17:
1.13    ! andrew     18: my $class;
        !            19: BEGIN {
        !            20:        $class = 'Text::Todo::Entry';
        !            21:        use_ok( $class, "use $class" )
        !            22: }
1.1       andrew     23:
1.5       andrew     24: diag("Testing entry $class $Text::Todo::Entry::VERSION");
1.1       andrew     25:
                     26: my %sample = (
1.9       andrew     27:     text     => '(B) @home @work send email to andrew@cpan.org + +say_thanks',
1.8       andrew     28:     priority => 'B',
                     29:     contexts => [ 'home', 'work' ],
1.9       andrew     30:     projects => [ '', 'say_thanks' ],
1.8       andrew     31:     prepend  => 'before',
                     32:     append   => 'or something',
1.1       andrew     33:     new_project => 'notnapping',
                     34:     new_context => 'car',
                     35: );
                     36:
1.6       andrew     37: my $e = new_ok($class);
                     38:
1.8       andrew     39: ok( $e->replace( $sample{text} ), 'Update entry' );
1.6       andrew     40: is( $e->text,     $sample{text},     'Make sure entry matches' );
                     41: is( $e->priority, $sample{priority}, 'check priority' );
                     42: is_deeply( [ $e->contexts ], $sample{contexts}, 'check contexts' );
                     43: is_deeply( [ $e->projects ], $sample{projects}, 'check projects' );
1.1       andrew     44:
                     45: $sample{text} =~ s/^( \s* \( $sample{priority} \))/$1 $sample{prepend}/xms;
1.2       andrew     46: ok( $e->prepend( $sample{prepend} ), 'Prepend entry' );
1.6       andrew     47: is( $e->text,     $sample{text},     'Make sure entry matches' );
                     48: is( $e->priority, $sample{priority}, 'check priority' );
                     49: is_deeply( [ $e->contexts ], $sample{contexts}, 'check contexts' );
                     50: is_deeply( [ $e->projects ], $sample{projects}, 'check projects' );
1.1       andrew     51:
                     52: $sample{text} .= ' ' . $sample{append};
1.2       andrew     53: ok( $e->append( $sample{append} ), 'Append entry' );
1.6       andrew     54: is( $e->text,     $sample{text},     'Make sure entry matches' );
                     55: is( $e->priority, $sample{priority}, 'check priority' );
                     56: is_deeply( [ $e->contexts ], $sample{contexts}, 'check contexts' );
                     57: is_deeply( [ $e->projects ], $sample{projects}, 'check projects' );
1.1       andrew     58:
                     59: ok( !$e->in_project( $sample{new_project} ), 'not in new project yet' );
                     60: push @{ $sample{projects} }, $sample{new_project};
                     61: $sample{text} .= ' +' . $sample{new_project};
1.2       andrew     62: ok( $e->append( '+' . $sample{new_project} ), 'Add project' );
1.6       andrew     63: is( $e->text, $sample{text}, 'Make sure entry matches' );
1.1       andrew     64: ok( $e->in_project( $sample{new_project} ), 'now in new project' );
                     65:
                     66: ok( !$e->in_context( $sample{new_context} ), 'not in new context yet' );
                     67: push @{ $sample{contexts} }, $sample{new_context};
                     68: $sample{text} .= ' @' . $sample{new_context};
1.2       andrew     69: ok( $e->append( '@' . $sample{new_context} ), 'Add context' );
1.6       andrew     70: is( $e->text, $sample{text}, 'Make sure entry matches' );
1.1       andrew     71: ok( $e->in_context( $sample{new_context} ), 'now in new context' );
1.4       andrew     72:
1.6       andrew     73: $sample{text} =~ s/^\(B\)\s*/(A) /gxms;
                     74: $sample{priority} = 'A';
1.8       andrew     75: ok( $e->pri('A'), 'Set priority to A' );
                     76: is( $e->text,     $sample{text}, 'Make sure entry matches' );
                     77: is( $e->priority, 'A',           'New priority is set' );
1.6       andrew     78:
                     79: $sample{text} =~ s/^\(A\)\s*//gxms;
                     80: $sample{priority} = '';
                     81: ok( $e->depri(), 'Deprioritize' );
1.8       andrew     82: is( $e->text,     $sample{text}, 'Make sure entry matches' );
                     83: is( $e->priority, undef,         'New priority is set' );
1.6       andrew     84:
1.10      andrew     85: my $done_date = sprintf "%04d-%02d-%02d",
                     86:     ( (localtime)[5] + 1900 ),
                     87:     ( (localtime)[4] + 1 ),
                     88:     ( (localtime)[3] );
                     89: my $done_marker = "x $done_date ";
                     90:
1.7       andrew     91: ok( !$e->done, 'not done' );
1.8       andrew     92: ok( $e->do,    'mark as done' );
1.10      andrew     93: is( $e->done, $done_date, 'now done' );
                     94: is( $e->text, $done_marker . $sample{text}, 'Make sure entry matches' );
1.4       andrew     95:
1.8       andrew     96: ok( $e->replace(''), 'Blank entry' );
1.6       andrew     97: is( $e->text,     '',    'Make sure entry is blank' );
                     98: is( $e->priority, undef, 'check priority is undef' );
                     99: is_deeply( [ $e->contexts ], [], 'check contexts are empty' );
                    100: is_deeply( [ $e->projects ], [], 'check projects are empty' );
1.4       andrew    101:
1.6       andrew    102: # replace
                    103: # app => 'append',
                    104: # prep => 'prepend',
                    105: # dp => 'dpri',
                    106: # p => 'pri',

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