Annotation of todotxt/Text-Todo/t/list.t, Revision 1.16
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.16 ! andrew 11: # REVISION: $AFresh1: list.t,v 1.15 2010/02/13 23:26:44 andrew Exp $
1.1 andrew 12: #===============================================================================
13:
14: use strict;
15: use warnings;
16:
1.16 ! andrew 17: use Test::More tests => 58;
1.2 andrew 18:
19: use File::Temp qw/ tempdir /;
1.14 andrew 20: use File::Spec;
1.1 andrew 21:
1.11 andrew 22: my $class;
1.14 andrew 23:
24: BEGIN {
25: $class = 'Text::Todo';
26: use_ok( $class, "use $class" );
1.11 andrew 27: }
1.1 andrew 28:
29: diag("Testing entry $class $Text::Todo::VERSION");
30:
1.13 andrew 31: my $orig = new_ok( $class, ['t/todo.list.txt'] );
1.2 andrew 32: my @orig_list;
33: ok( @orig_list = $orig->list, 'get orig list' );
34:
1.14 andrew 35: is( $orig->file('todo_file'),
36: File::Spec->catfile( 't', 'todo.list.txt' ),
37: 'orig todo_file matches'
38: );
39: is( $orig->file('done_file'),
40: File::Spec->catfile( 't', 'done.list.txt' ),
41: 'orig done_file matches'
42: );
1.2 andrew 43: is( $orig->file('report_file'),
1.14 andrew 44: File::Spec->catfile( 't', 'report.list.txt' ),
45: 'orig report_file matches'
46: );
1.2 andrew 47:
48: my $todo_dir = tempdir( 'todo-XXXXXXXXX', CLEANUP => 1, TMPDIR => 1 );
1.13 andrew 49: my $copy = new_ok($class);
1.2 andrew 50:
51: foreach my $e (@orig_list) {
52: ok( $copy->add($e), 'add entry from orginal list' );
53: }
1.14 andrew 54: ok( $copy->save( File::Spec->catfile( $todo_dir, 'todo.txt' ) ),
55: 'save the copy' );
1.2 andrew 56:
57: is( $copy->file('todo_file'),
1.14 andrew 58: File::Spec->catfile( $todo_dir, 'todo.txt' ),
1.2 andrew 59: 'copy todo_file matches'
60: );
61: is( $copy->file('done_file'),
1.14 andrew 62: File::Spec->catfile( $todo_dir, 'done.txt' ),
1.2 andrew 63: 'copy done_file matches'
64: );
65: is( $copy->file('report_file'),
1.14 andrew 66: File::Spec->catfile( $todo_dir, 'report.txt' ),
1.2 andrew 67: 'copy report_file matches'
68: );
69: my @copy_list;
70: ok( @copy_list = $copy->list, 'get copy list' );
1.1 andrew 71:
1.2 andrew 72: for my $id ( 0 .. $#orig_list ) {
73: is( $copy_list[$id]->text, $orig_list[$id]->text, "Entry $id matches" );
74: }
75:
76: $orig = undef;
77:
78: my @pri_list;
1.8 andrew 79: ok( @pri_list = $copy->listpri('A'), 'list priority item' );
1.2 andrew 80: is( scalar @pri_list, 1, 'only 1 item in the priority list' );
81: is( $pri_list[0]->text, '(A) entry 1 @one +uno', 'priority item is correct' );
82:
83: my $entry_to_move = $copy_list[-1];
84: ok( $copy->move( $entry_to_move, 1 ), 'move entry to position 1' );
85: ok( @copy_list = $copy->list, 'update our list' );
86: is( $copy_list[1]->text, $entry_to_move->text,
87: 'entry is in the new position' );
88:
89: $entry_to_move = $copy_list[3];
90: ok( $copy->move( 3, 1 ), 'move entry 3 to position 1' );
91: ok( @copy_list = $copy->list, 'update our list' );
92: is( $copy_list[1]->text, $entry_to_move->text,
93: 'entry is in the new position' );
1.15 andrew 94:
1.16 ! andrew 95: my $tags;
! 96: ok( $tags = $copy->known_tags, 'known_tags for current list' );
1.15 andrew 97: is_deeply(
1.16 ! andrew 98: $tags,
! 99: { 'context' => '@', 'project' => '+' },
! 100: 'got the tags we expected'
! 101: );
! 102:
! 103: ok( $copy->learn_tag('due_date', 'DUE:'), "Learn due_date tag" );
! 104: ok( $tags = $copy->known_tags, 'known_tags for current list' );
! 105: is_deeply(
! 106: $tags,
! 107: { 'context' => '@', 'project' => '+', 'due_date' => 'DUE:' },
! 108: 'got the tags we expected'
1.15 andrew 109: );
1.2 andrew 110:
111: my @projects;
112: ok( @projects = $copy->listproj, 'listproj for current list' );
113: is_deeply(
114: \@projects,
115: [ 'delete', 'dos', 'uno' ],
116: 'got the projects we expected'
1.1 andrew 117: );
118:
1.2 andrew 119: for my $id ( 0 .. $#copy_list ) {
120: my $e = $copy_list[$id];
121: if ( $e->in_project('delete') ) {
122: ok( $copy->del($e), "deleting entry $id" );
123: isnt( $copy->list->[$id]->text, $e->text, 'Entry seems to be gone' );
124: }
125: }
126:
127: ok( @projects = $copy->listproj, 'listproj for current list' );
128: is_deeply( \@projects, [ 'dos', 'uno' ], 'got the projects we expected' );
1.8 andrew 129:
130: my @contexts;
131: ok( @contexts = $copy->listcon, 'listcon for current list' );
132: is_deeply( \@contexts, [ 'one', 'two' ], 'got the contexts we expected' );
1.2 andrew 133:
1.3 andrew 134: my $entry_to_archive;
1.6 andrew 135: ok( $entry_to_archive = $copy->list->[3], 'read entry_to_archive' );
1.3 andrew 136: is( $entry_to_archive->text,
1.6 andrew 137: 'x completed entry 4',
1.3 andrew 138: 'make sure we got the right entry'
139: );
140:
1.4 andrew 141: ok( $copy->archive, 'archive done items' );
142: isnt( $copy->list->[1]->text,
143: $entry_to_archive->text, 'make sure it changed' );
144:
145: ok( $copy->load('done_file'), 'read the done_file' );
146: is( $copy->list->[-1]->text,
147: $entry_to_archive->text, 'make sure it moved to the archive' );
1.2 andrew 148:
1.3 andrew 149: my $file;
150: ok( $file = $copy->file('done_file'), 'get the done_file name' );
1.14 andrew 151: is( $file,
152: File::Spec->catfile( $todo_dir, 'done.txt' ),
153: 'the done_file name what we expected?'
154: );
1.3 andrew 155:
1.4 andrew 156: ok( $copy->addto( $file, 'added text' ), 'Add text to file' );
1.3 andrew 157:
158: my @done;
159: ok( @done = $copy->listfile('done_file'), 'get items in done_file' );
160: is( $done[-1]->text, 'added text', 'make sure what we added is there' );
1.2 andrew 161:
1.4 andrew 162: is( $done[-2]->text, $entry_to_archive->text,
163: 'make sure it moved to the archive' );
1.2 andrew 164:
1.7 andrew 165: #done_testing();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>