Annotation of todotxt/Text-Todo/t/list.t, Revision 1.15
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.15 ! andrew 11: # REVISION: $AFresh1: list.t,v 1.14 2010/01/20 21:15:15 andrew Exp $
1.1 andrew 12: #===============================================================================
13:
14: use strict;
15: use warnings;
16:
1.15 ! andrew 17: use Test::More tests => 55;
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:
! 95: my @tags;
! 96: ok( @tags = $copy->listtags, 'listtagsfor current list' );
! 97: is_deeply(
! 98: \@tags,
! 99: [ 'context', 'project' ],
! 100: 'got the projects we expected'
! 101: );
1.2 andrew 102:
103: my @projects;
104: ok( @projects = $copy->listproj, 'listproj for current list' );
105: is_deeply(
106: \@projects,
107: [ 'delete', 'dos', 'uno' ],
108: 'got the projects we expected'
1.1 andrew 109: );
110:
1.2 andrew 111: for my $id ( 0 .. $#copy_list ) {
112: my $e = $copy_list[$id];
113: if ( $e->in_project('delete') ) {
114: ok( $copy->del($e), "deleting entry $id" );
115: isnt( $copy->list->[$id]->text, $e->text, 'Entry seems to be gone' );
116: }
117: }
118:
119: ok( @projects = $copy->listproj, 'listproj for current list' );
120: is_deeply( \@projects, [ 'dos', 'uno' ], 'got the projects we expected' );
1.8 andrew 121:
122: my @contexts;
123: ok( @contexts = $copy->listcon, 'listcon for current list' );
124: is_deeply( \@contexts, [ 'one', 'two' ], 'got the contexts we expected' );
1.2 andrew 125:
1.3 andrew 126: my $entry_to_archive;
1.6 andrew 127: ok( $entry_to_archive = $copy->list->[3], 'read entry_to_archive' );
1.3 andrew 128: is( $entry_to_archive->text,
1.6 andrew 129: 'x completed entry 4',
1.3 andrew 130: 'make sure we got the right entry'
131: );
132:
1.4 andrew 133: ok( $copy->archive, 'archive done items' );
134: isnt( $copy->list->[1]->text,
135: $entry_to_archive->text, 'make sure it changed' );
136:
137: ok( $copy->load('done_file'), 'read the done_file' );
138: is( $copy->list->[-1]->text,
139: $entry_to_archive->text, 'make sure it moved to the archive' );
1.2 andrew 140:
1.3 andrew 141: my $file;
142: ok( $file = $copy->file('done_file'), 'get the done_file name' );
1.14 andrew 143: is( $file,
144: File::Spec->catfile( $todo_dir, 'done.txt' ),
145: 'the done_file name what we expected?'
146: );
1.3 andrew 147:
1.4 andrew 148: ok( $copy->addto( $file, 'added text' ), 'Add text to file' );
1.3 andrew 149:
150: my @done;
151: ok( @done = $copy->listfile('done_file'), 'get items in done_file' );
152: is( $done[-1]->text, 'added text', 'make sure what we added is there' );
1.2 andrew 153:
1.4 andrew 154: is( $done[-2]->text, $entry_to_archive->text,
155: 'make sure it moved to the archive' );
1.2 andrew 156:
1.7 andrew 157: #done_testing();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>