Annotation of todotxt/Text-Todo/t/entry.t, Revision 1.5
1.1 andrew 1: #===============================================================================
2: #
3: # FILE: 20.entry.t
4: #
5: # DESCRIPTION: Test an entry that we create
6: #
7: # AUTHOR: Andrew Fresh (AAF), andrew@cpan.org
8: # COMPANY: Red River Communications
9: # CREATED: 07/10/09 11:32:39
1.5 ! andrew 10: # REVISION: $RedRiver: entry.t,v 1.4 2009/07/13 18:05:50 andrew Exp $
1.1 andrew 11: #===============================================================================
12:
13: use strict;
14: use warnings;
15:
1.4 andrew 16: use Test::More tests => 34; # last test to print
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 $e = new_ok($class);
25:
26: my %sample = (
1.3 andrew 27: text => '(B) @home @work send email to andrew@cpan.org +say_thanks',
1.1 andrew 28: priority => 'B',
29: contexts => [ 'home', 'work' ],
1.3 andrew 30: projects => ['say_thanks'],
1.1 andrew 31: prepend => 'before',
32: append => 'or something',
33: new_project => 'notnapping',
34: new_context => 'car',
35: );
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" );
42:
43: $sample{text} =~ s/^( \s* \( $sample{priority} \))/$1 $sample{prepend}/xms;
1.2 andrew 44: ok( $e->prepend( $sample{prepend} ), 'Prepend entry' );
1.1 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" );
49:
50: $sample{text} .= ' ' . $sample{append};
1.2 andrew 51: ok( $e->append( $sample{append} ), 'Append entry' );
1.1 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" );
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.1 andrew 61: is( $e->text, $sample{text}, "Make sure entry matches" );
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.1 andrew 68: is( $e->text, $sample{text}, "Make sure entry matches" );
69: ok( $e->in_context( $sample{new_context} ), 'now in new context' );
1.4 andrew 70:
71: ok( !$e->completed, 'not completed' );
72: ok( $e->complete, 'mark as completed' );
73: ok( $e->completed, 'now completed' );
74: is( $e->text, 'x ' . $sample{text}, "Make sure entry matches" );
75:
76: ok( $e->change( '' ), 'Blank entry' );
77: is( $e->text, '', "Make sure entry is blank" );
78: is( $e->priority, undef, "check priority is undef" );
79: is_deeply( [ $e->contexts ], [], "check contexts are empty" );
80: is_deeply( [ $e->projects ], [], "check projects are empty" );
81:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>