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

Annotation of todotxt/Text-Todo-REST-API/t/formats/json.t, Revision 1.4

1.1       andrew      1: #===============================================================================
                      2: #
1.2       andrew      3: #         FILE:  json.t
1.1       andrew      4: #
1.2       andrew      5: #  DESCRIPTION:  Test Text::Todo::REST::API::Representations::json
1.1       andrew      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: json.t,v 1.3 2010/02/13 21:45:54 andrew Exp $
1.1       andrew     11: #===============================================================================
                     12:
                     13: use strict;
                     14: use warnings;
                     15:
1.4     ! andrew     16: use Test::More tests => 30;
1.1       andrew     17:
                     18: my $class;
                     19: my $format;
                     20:
1.2       andrew     21: use JSON;
                     22: use Test::JSON;
                     23:
1.1       andrew     24: BEGIN {
                     25:     $format = 'json';
                     26:     $class  = 'Text::Todo::REST::API::Representations::' . $format;
                     27:     use_ok( $class, "use $class" );
                     28: }
                     29:
                     30: diag(
                     31:     "Testing entry $class $Text::Todo::REST::API::Representations::json::VERSION"
                     32: );
                     33:
                     34: my $result;
                     35: my $api = new_ok($class);
                     36:
1.3       andrew     37: is( $api->content_type, 'application/json', 'Check content_type' );
1.1       andrew     38:
                     39: my $files = ['todo.txt'];
                     40: $result = undef;
                     41: ok( ($result) = $api->render_files( $format, $files ), 'render files' );
1.2       andrew     42: is_valid_json($result, 'files json is valid');
                     43: is_json( $result, to_json($files), 'files render as expected' );
1.4     ! andrew     44:
        !            45: my $tags = ['uno', 'dos', 'tres'];
        !            46: $result = undef;
        !            47: ok( ($result) = $api->render_tags( $format, $tags ), 'render tags' );
        !            48: is_valid_json($result, 'tags json is valid');
        !            49: is_json( $result, to_json($tags), 'tags render as expected' );
1.1       andrew     50:
                     51: my $list = [
                     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: $result = undef;
                     79: ok( eval { $result = $api->render_list( $format, $list ) }, 'render_list' );
1.2       andrew     80: is_valid_json($result, 'list json is valid');
                     81: is_json( $result, to_json($list), 'Got expected render_list result' );
1.1       andrew     82:
                     83: foreach my $e ( @{$list} ) {
                     84:     my $result;
1.2       andrew     85:     ok( $result = $api->render_entry( $format, $e ), 'render_entry' );
                     86:     is_valid_json($result, 'entry json is valid');
                     87:     is_json( $result, to_json($e), 'Got correct render_entry result' );
1.1       andrew     88: }

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