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

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

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