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