[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.7

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

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