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

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

Revision 1.4, Sat Feb 13 22:15:29 2010 UTC (14 years, 4 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +8 -3 lines

render_tags in JSON
simplify (a lot) Text::Todo::REST::API::Representations::json
make json representation return [] if passed in undef
and test

#===============================================================================
#
#         FILE:  json.t
#
#  DESCRIPTION:  Test Text::Todo::REST::API::Representations::json
#
#       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
#      COMPANY:  Red River Communications
#      CREATED:  01/07/10 19:11
#     REVISION:  $AFresh1: json.t,v 1.4 2010/02/13 22:15:29 andrew Exp $
#===============================================================================

use strict;
use warnings;

use Test::More tests => 30;

my $class;
my $format;

use JSON;
use Test::JSON;

BEGIN {
    $format = 'json';
    $class  = 'Text::Todo::REST::API::Representations::' . $format;
    use_ok( $class, "use $class" );
}

diag(
    "Testing entry $class $Text::Todo::REST::API::Representations::json::VERSION"
);

my $result;
my $api = new_ok($class);

is( $api->content_type, 'application/json', 'Check content_type' );

my $files = ['todo.txt'];
$result = undef;
ok( ($result) = $api->render_files( $format, $files ), 'render files' );
is_valid_json($result, 'files json is valid');
is_json( $result, to_json($files), 'files render as expected' );

my $tags = ['uno', 'dos', 'tres'];
$result = undef;
ok( ($result) = $api->render_tags( $format, $tags ), 'render tags' );
is_valid_json($result, 'tags json is valid');
is_json( $result, to_json($tags), 'tags render as expected' );

my $list = [
    {   '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
    }
];

$result = undef;
ok( eval { $result = $api->render_list( $format, $list ) }, 'render_list' );
is_valid_json($result, 'list json is valid');
is_json( $result, to_json($list), 'Got expected render_list result' );

foreach my $e ( @{$list} ) {
    my $result;
    ok( $result = $api->render_entry( $format, $e ), 'render_entry' );
    is_valid_json($result, 'entry json is valid');
    is_json( $result, to_json($e), 'Got correct render_entry result' );
}