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

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

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