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

File: [local] / todotxt / Text-Todo-REST-API / t / formats / text.t (download)

Revision 1.8, Mon Jan 18 13:47:53 2010 UTC (14 years, 5 months ago) by andrew
Branch: MAIN
Changes since 1.7: +6 -6 lines

No longer try to make this module figure out the todo_dir and todo_file. Leave that up to Todo::Text of allow overriding by passing in todo_file and todo_dir.

#===============================================================================
#
#         FILE:  text.t
#
#  DESCRIPTION:  Test Text::Todo::REST::API::text
#
#       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
#      COMPANY:  Red River Communications
#      CREATED:  01/07/10 19:11
#     REVISION:  $AFresh1: text.t,v 1.8 2010/01/18 13:47:53 andrew Exp $
#===============================================================================

use strict;
use warnings;

use Test::More tests => 45;

my $class;
my $subclass;
my $ext;

BEGIN {
    $ext = 'txt';

    $class = 'Text::Todo::REST::API';
    use_ok( $class, "use $class" );

    $subclass = $class . '::Representations::text';
}

diag("Testing entry $subclass $Text::Todo::REST::API::VERSION");

my $api = new_ok( $class,
    [ { todo_dir => 't/lists', path_info => '/.' . $ext } ] );
isa_ok( $api, $subclass );

my $files_should_be = ['todo.txt'];
my @files;
ok( @files = $api->get_files, 'get files' );
is_deeply( \@files, $files_should_be, 'Got correct files' );

my $files_dump_should_be = join q{}, map "$_\n", @{ $files_should_be };
my $result;
ok( ($result) = $api->Dump( @files ), 'Dump files' );
is_deeply( $result, $files_dump_should_be, 'files Dump as expected' );

$api = new_ok( $class,
    [ { todo_dir => 't/lists', path_info => '/todo.' . $ext } ] );
isa_ok( $api, $subclass );

my $list_should_be = [
    {   'text' => '(A) entry 1 @one +uno',
        'md5'  => '931e0831c31a70928b29de55778dc294',
        'line' => 1
    },
    {   'text' => 'entry 2 @two +dos',
        'md5'  => 'b38dde8029c047e81379d9de581a6251',
        'line' => 2
    },
    {   'text' => '',
        'md5'  => 'd41d8cd98f00b204e9800998ecf8427e',
        'line' => 3
    },
    {   'text' => 'x completed entry 4',
        'md5'  => '8de0a2b65a50d5e30e84ad48af46fa78',
        'line' => 4
    },
    {   'text' => '(B) entry 5 is priority',
        'md5'  => 'c1692dfbf3b5829b6bce44b1a1614980',
        'line' => 5
    },
    {   'text' => 'entry 6 +delete',
        'md5'  => 'e1f6bf867f75aa019063782554407d02',
        'line' => 6
    }
];

my $list_dump_should_be = join q{},
    map { $_->{text} . "\n" } @{$list_should_be};

$result = undef;
ok( !eval { $result = $api->Load() }, 'Load method' );
like( $@, '/^Unable to Load \[list\]/', 'Failed Load as expected' );

$result = undef;
ok( !( $result = $api->Dump() ), 'Dump method' );
is( $result, undef, 'Dump returned undef' );

$result = undef;
ok( eval { $result = $api->Dump( @{$list_should_be} ) }, 'Dump method' );
is( $result, $list_dump_should_be, 'Got expected Dump result' );
$result = undef;

foreach my $e ( @{$list_should_be} ) {
    my $api = new_ok(
        $class,
        [   {   todo_dir => 't/lists',
                path_info => '/todo/entry/' . $e->{md5} . '.' . $ext
            }
        ]
    );
    my @entry;
    ok( @entry = $api->GET(), "get_entry by GET()" );
    is_deeply( \@entry, [$e], 'got correct entry' );

    my $result;
    ok( $result = $api->Dump(@entry), 'Dump output' );
    is( $result, $e->{text} . "\n", 'Got correct Dump result' );
}