[BACK]Return to text.t CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo-REST-API / t / formats

Annotation of todotxt/Text-Todo-REST-API/t/formats/text.t, Revision 1.9

1.1       andrew      1: #===============================================================================
                      2: #
                      3: #         FILE:  text.t
                      4: #
                      5: #  DESCRIPTION:  Test Text::Todo::REST::API::text
                      6: #
                      7: #       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
                      8: #      COMPANY:  Red River Communications
                      9: #      CREATED:  01/07/10 19:11
1.9     ! andrew     10: #     REVISION:  $AFresh1: text.t,v 1.8 2010/01/18 13:47:53 andrew Exp $
1.1       andrew     11: #===============================================================================
                     12:
                     13: use strict;
                     14: use warnings;
                     15:
1.9     ! andrew     16: use Test::More tests => 43;
1.1       andrew     17:
                     18: my $class;
1.4       andrew     19: my $ext;
1.1       andrew     20:
                     21: BEGIN {
1.4       andrew     22:     $ext = 'txt';
                     23:
1.1       andrew     24:     $class = 'Text::Todo::REST::API';
                     25:     use_ok( $class, "use $class" );
                     26: }
                     27:
1.9     ! andrew     28: diag("Testing entry $class $Text::Todo::REST::API::VERSION");
1.1       andrew     29:
                     30: my $api = new_ok( $class,
1.8       andrew     31:     [ { todo_dir => 't/lists', path_info => '/.' . $ext } ] );
1.5       andrew     32:
                     33: my $files_should_be = ['todo.txt'];
                     34: my @files;
                     35: ok( @files = $api->get_files, 'get files' );
                     36: is_deeply( \@files, $files_should_be, 'Got correct files' );
                     37:
                     38: my $files_dump_should_be = join q{}, map "$_\n", @{ $files_should_be };
                     39: my $result;
                     40: ok( ($result) = $api->Dump( @files ), 'Dump files' );
                     41: is_deeply( $result, $files_dump_should_be, 'files Dump as expected' );
                     42:
                     43: $api = new_ok( $class,
1.8       andrew     44:     [ { todo_dir => 't/lists', path_info => '/todo.' . $ext } ] );
1.1       andrew     45:
                     46: my $list_should_be = [
                     47:     {   'text' => '(A) entry 1 @one +uno',
                     48:         'md5'  => '931e0831c31a70928b29de55778dc294',
                     49:         'line' => 1
                     50:     },
                     51:     {   'text' => 'entry 2 @two +dos',
                     52:         'md5'  => 'b38dde8029c047e81379d9de581a6251',
                     53:         'line' => 2
                     54:     },
                     55:     {   'text' => '',
                     56:         'md5'  => 'd41d8cd98f00b204e9800998ecf8427e',
                     57:         'line' => 3
                     58:     },
                     59:     {   'text' => 'x completed entry 4',
                     60:         'md5'  => '8de0a2b65a50d5e30e84ad48af46fa78',
                     61:         'line' => 4
                     62:     },
                     63:     {   'text' => '(B) entry 5 is priority',
                     64:         'md5'  => 'c1692dfbf3b5829b6bce44b1a1614980',
                     65:         'line' => 5
                     66:     },
                     67:     {   'text' => 'entry 6 +delete',
                     68:         'md5'  => 'e1f6bf867f75aa019063782554407d02',
                     69:         'line' => 6
                     70:     }
                     71: ];
                     72:
                     73: my $list_dump_should_be = join q{},
                     74:     map { $_->{text} . "\n" } @{$list_should_be};
                     75:
1.5       andrew     76: $result = undef;
1.9     ! andrew     77: ok( !eval { $result = $api->_handle_representation('load') }, 'Load method' );
        !            78: like( $@, '/^Unable to load \[list\]/', 'Failed Load as expected' );
1.1       andrew     79:
                     80: $result = undef;
1.4       andrew     81: ok( !( $result = $api->Dump() ), 'Dump method' );
                     82: is( $result, undef, 'Dump returned undef' );
1.1       andrew     83:
                     84: $result = undef;
1.4       andrew     85: ok( eval { $result = $api->Dump( @{$list_should_be} ) }, 'Dump method' );
1.1       andrew     86: is( $result, $list_dump_should_be, 'Got expected Dump result' );
                     87: $result = undef;
1.2       andrew     88:
                     89: foreach my $e ( @{$list_should_be} ) {
                     90:     my $api = new_ok(
                     91:         $class,
1.8       andrew     92:         [   {   todo_dir => 't/lists',
                     93:                 path_info => '/todo/entry/' . $e->{md5} . '.' . $ext
1.2       andrew     94:             }
                     95:         ]
                     96:     );
1.3       andrew     97:     my @entry;
                     98:     ok( @entry = $api->GET(), "get_entry by GET()" );
1.4       andrew     99:     is_deeply( \@entry, [$e], 'got correct entry' );
1.3       andrew    100:
                    101:     my $result;
                    102:     ok( $result = $api->Dump(@entry), 'Dump output' );
                    103:     is( $result, $e->{text} . "\n", 'Got correct Dump result' );
1.2       andrew    104: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>