Annotation of todotxt/Text-Todo-REST-API/t/formats/json.t, Revision 1.1
1.1 ! andrew 1: #===============================================================================
! 2: #
! 3: # FILE: text.t
! 4: #
! 5: # DESCRIPTION: Test Text::Todo::REST::API::Representations::text
! 6: #
! 7: # AUTHOR: Andrew Fresh (AAF), andrew@cpan.org
! 8: # COMPANY: Red River Communications
! 9: # CREATED: 01/07/10 19:11
! 10: # REVISION: $AFresh1: text.t,v 1.10 2010/01/23 07:04:43 andrew Exp $
! 11: #===============================================================================
! 12:
! 13: use strict;
! 14: use warnings;
! 15:
! 16: use Test::More tests => 19;
! 17:
! 18: my $class;
! 19: my $format;
! 20:
! 21: BEGIN {
! 22: $format = 'json';
! 23: $class = 'Text::Todo::REST::API::Representations::' . $format;
! 24: use_ok( $class, "use $class" );
! 25: }
! 26:
! 27: diag(
! 28: "Testing entry $class $Text::Todo::REST::API::Representations::json::VERSION"
! 29: );
! 30:
! 31: my $result;
! 32: my $api = new_ok($class);
! 33:
! 34: is( $api->content_type, 'text/plain', 'Check content_type' );
! 35:
! 36: my $files = ['todo.txt'];
! 37: my $files_render = join q{}, map "$_\n", @{$files};
! 38:
! 39: $result = undef;
! 40: ok( ($result) = $api->render_files( $format, $files ), 'render files' );
! 41: is_deeply( $result, $files_render, 'files render as expected' );
! 42:
! 43: my $list = [
! 44: { 'text' => '(A) entry 1 @one +uno',
! 45: 'md5' => '931e0831c31a70928b29de55778dc294',
! 46: 'line' => 1
! 47: },
! 48: { 'text' => 'entry 2 @two +dos',
! 49: 'md5' => 'b38dde8029c047e81379d9de581a6251',
! 50: 'line' => 2
! 51: },
! 52: { 'text' => '',
! 53: 'md5' => 'd41d8cd98f00b204e9800998ecf8427e',
! 54: 'line' => 3
! 55: },
! 56: { 'text' => 'x completed entry 4',
! 57: 'md5' => '8de0a2b65a50d5e30e84ad48af46fa78',
! 58: 'line' => 4
! 59: },
! 60: { 'text' => '(B) entry 5 is priority',
! 61: 'md5' => 'c1692dfbf3b5829b6bce44b1a1614980',
! 62: 'line' => 5
! 63: },
! 64: { 'text' => 'entry 6 +delete',
! 65: 'md5' => 'e1f6bf867f75aa019063782554407d02',
! 66: 'line' => 6
! 67: }
! 68: ];
! 69:
! 70: my $list_render = join q{}, map { $_->{text} . "\n" } @{$list};
! 71:
! 72: $result = undef;
! 73: ok( eval { $result = $api->render_list( $format, $list ) }, 'render_list' );
! 74: is( $result, $list_render, 'Got expected render_list result' );
! 75:
! 76: foreach my $e ( @{$list} ) {
! 77: my $result;
! 78: ok( eval { $result = $api->render_entry( $format, $e ) },
! 79: 'render_entry' );
! 80: is( $result, $e->{text} . "\n", 'Got correct render_entry result' );
! 81: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>