Annotation of todotxt/Text-Todo/t/entry.t, Revision 1.6
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.6 ! andrew 10: # REVISION: $RedRiver: entry.t,v 1.5 2010/01/06 19:54:56 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:
20: BEGIN: { use_ok( $class, "use $class" ) }
21:
1.5 andrew 22: diag("Testing entry $class $Text::Todo::Entry::VERSION");
1.1 andrew 23:
24: my %sample = (
1.3 andrew 25: text => '(B) @home @work send email to andrew@cpan.org +say_thanks',
1.1 andrew 26: priority => 'B',
27: contexts => [ 'home', 'work' ],
1.3 andrew 28: projects => ['say_thanks'],
1.1 andrew 29: prepend => 'before',
30: append => 'or something',
31: new_project => 'notnapping',
32: new_context => 'car',
33: );
34:
1.6 ! andrew 35: my $e = new_ok($class);
! 36:
! 37: ok( $e->change( $sample{text} ), 'Update entry' );
! 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';
! 73: ok( $e->priority('A'), 'Set priority to A' );
! 74: is( $e->text, $sample{text}, 'Make sure entry matches' );
! 75: is( $e->priority, 'A', 'New priority is set' );
! 76:
! 77: $sample{text} =~ s/^\(A\)\s*//gxms;
! 78: $sample{priority} = '';
! 79: ok( $e->depri(), 'Deprioritize' );
! 80: is( $e->text, $sample{text}, 'Make sure entry matches' );
! 81: is( $e->priority, undef, 'New priority is set' );
! 82:
1.4 andrew 83: ok( !$e->completed, 'not completed' );
84: ok( $e->complete, 'mark as completed' );
85: ok( $e->completed, 'now completed' );
1.6 ! andrew 86: is( $e->text, 'x ' . $sample{text}, 'Make sure entry matches' );
1.4 andrew 87:
88: ok( $e->change( '' ), 'Blank entry' );
1.6 ! andrew 89: is( $e->text, '', 'Make sure entry is blank' );
! 90: is( $e->priority, undef, 'check priority is undef' );
! 91: is_deeply( [ $e->contexts ], [], 'check contexts are empty' );
! 92: is_deeply( [ $e->projects ], [], 'check projects are empty' );
! 93:
1.4 andrew 94:
1.6 ! andrew 95: # replace
! 96: # app => 'append',
! 97: # prep => 'prepend',
! 98: # dp => 'dpri',
! 99: # p => 'pri',
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>