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

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

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