Annotation of todotxt/Text-Todo/t/list.t, Revision 1.10
1.1 andrew 1: #===============================================================================
2: #
3: # FILE: list.t
4: #
5: # DESCRIPTION: Test list commands
6: #
7: #
8: # AUTHOR: Andrew Fresh (AAF), andrew@cpan.org
9: # COMPANY: Red River Communications
10: # CREATED: 01/07/10 19:11
1.10 ! andrew 11: # REVISION: $AFresh1: list.t,v 1.9 2010/01/11 19:52:06 andrew Exp $
1.1 andrew 12: #===============================================================================
13:
14: use strict;
15: use warnings;
16:
1.8 andrew 17: use Test::More tests => 53;
1.2 andrew 18:
19: use File::Temp qw/ tempdir /;
20: use Data::Dumper;
1.1 andrew 21:
22: my $class = 'Text::Todo';
23:
1.10 ! andrew 24: BEGIN { use_ok( $class, "use $class" ) }
1.1 andrew 25:
26: diag("Testing entry $class $Text::Todo::VERSION");
27:
1.2 andrew 28: my $orig = new_ok( $class, ['t/todo.list.txt'] );
29: my @orig_list;
30: ok( @orig_list = $orig->list, 'get orig list' );
31:
32: is( $orig->file('todo_file'), 't/todo.list.txt', 'orig todo_file matches' );
33: is( $orig->file('done_file'), 't/done.list.txt', 'orig done_file matches' );
34: is( $orig->file('report_file'),
35: 't/report.list.txt', 'orig report_file matches' );
36:
37: my $todo_dir = tempdir( 'todo-XXXXXXXXX', CLEANUP => 1, TMPDIR => 1 );
38: my $copy = new_ok($class);
39:
40: foreach my $e (@orig_list) {
41: ok( $copy->add($e), 'add entry from orginal list' );
42: }
43: ok( $copy->save( $todo_dir . '/todo.txt' ), 'save the copy' );
44:
45: is( $copy->file('todo_file'),
46: $todo_dir . '/todo.txt',
47: 'copy todo_file matches'
48: );
49: is( $copy->file('done_file'),
50: $todo_dir . '/done.txt',
51: 'copy done_file matches'
52: );
53: is( $copy->file('report_file'),
54: $todo_dir . '/report.txt',
55: 'copy report_file matches'
56: );
57: my @copy_list;
58: ok( @copy_list = $copy->list, 'get copy list' );
1.1 andrew 59:
1.2 andrew 60: for my $id ( 0 .. $#orig_list ) {
61: is( $copy_list[$id]->text, $orig_list[$id]->text, "Entry $id matches" );
62: }
63:
64: $orig = undef;
65:
66: my @pri_list;
1.8 andrew 67: ok( @pri_list = $copy->listpri('A'), 'list priority item' );
1.2 andrew 68: is( scalar @pri_list, 1, 'only 1 item in the priority list' );
69: is( $pri_list[0]->text, '(A) entry 1 @one +uno', 'priority item is correct' );
70:
71: my $entry_to_move = $copy_list[-1];
72: ok( $copy->move( $entry_to_move, 1 ), 'move entry to position 1' );
73: ok( @copy_list = $copy->list, 'update our list' );
74: is( $copy_list[1]->text, $entry_to_move->text,
75: 'entry is in the new position' );
76:
77: $entry_to_move = $copy_list[3];
78: ok( $copy->move( 3, 1 ), 'move entry 3 to position 1' );
79: ok( @copy_list = $copy->list, 'update our list' );
80: is( $copy_list[1]->text, $entry_to_move->text,
81: 'entry is in the new position' );
82:
83: my @projects;
84: ok( @projects = $copy->listproj, 'listproj for current list' );
85: is_deeply(
86: \@projects,
87: [ 'delete', 'dos', 'uno' ],
88: 'got the projects we expected'
1.1 andrew 89: );
90:
1.2 andrew 91: for my $id ( 0 .. $#copy_list ) {
92: my $e = $copy_list[$id];
93: if ( $e->in_project('delete') ) {
94: ok( $copy->del($e), "deleting entry $id" );
95: isnt( $copy->list->[$id]->text, $e->text, 'Entry seems to be gone' );
96: }
97: }
98:
99: ok( @projects = $copy->listproj, 'listproj for current list' );
100: is_deeply( \@projects, [ 'dos', 'uno' ], 'got the projects we expected' );
1.8 andrew 101:
102: my @contexts;
103: ok( @contexts = $copy->listcon, 'listcon for current list' );
104: is_deeply( \@contexts, [ 'one', 'two' ], 'got the contexts we expected' );
1.2 andrew 105:
1.3 andrew 106: my $entry_to_archive;
1.6 andrew 107: ok( $entry_to_archive = $copy->list->[3], 'read entry_to_archive' );
1.3 andrew 108: is( $entry_to_archive->text,
1.6 andrew 109: 'x completed entry 4',
1.3 andrew 110: 'make sure we got the right entry'
111: );
112:
1.4 andrew 113: ok( $copy->archive, 'archive done items' );
114: isnt( $copy->list->[1]->text,
115: $entry_to_archive->text, 'make sure it changed' );
116:
117: ok( $copy->load('done_file'), 'read the done_file' );
118: is( $copy->list->[-1]->text,
119: $entry_to_archive->text, 'make sure it moved to the archive' );
1.2 andrew 120:
1.3 andrew 121: my $file;
122: ok( $file = $copy->file('done_file'), 'get the done_file name' );
123: is( $file, $todo_dir . '/done.txt', 'the done_file name what we expected?' );
124:
1.4 andrew 125: ok( $copy->addto( $file, 'added text' ), 'Add text to file' );
1.3 andrew 126:
127: my @done;
128: ok( @done = $copy->listfile('done_file'), 'get items in done_file' );
129: is( $done[-1]->text, 'added text', 'make sure what we added is there' );
1.2 andrew 130:
1.4 andrew 131: is( $done[-2]->text, $entry_to_archive->text,
132: 'make sure it moved to the archive' );
1.2 andrew 133:
1.7 andrew 134: #done_testing();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>