Annotation of todotxt/Text-Todo-REST-API/t/formats/json.t, Revision 1.2
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.2 ! andrew 10: # REVISION: $AFresh1: json.t,v 1.1 2010/01/31 03:58:58 andrew Exp $
1.1 andrew 11: #===============================================================================
12:
13: use strict;
14: use warnings;
15:
1.2 ! andrew 16: use Test::More tests => 27;
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:
37: is( $api->content_type, 'text/plain', 'Check content_type' );
38:
39: my $files = ['todo.txt'];
40:
41: $result = undef;
42: ok( ($result) = $api->render_files( $format, $files ), 'render files' );
1.2 ! andrew 43: is_valid_json($result, 'files json is valid');
! 44: is_json( $result, to_json($files), 'files render as expected' );
1.1 andrew 45:
46: my $list = [
47: { 'text' => '(A) entry 1 @one +uno',
48: 'md5' => '931e0831c31a70928b29de55778dc294',
49: 'line' => 1
50: },
51: { 'text' => 'entry 2 @two +dos',
52: 'md5' => 'b38dde8029c047e81379d9de581a6251',
53: 'line' => 2
54: },
55: { 'text' => '',
56: 'md5' => 'd41d8cd98f00b204e9800998ecf8427e',
57: 'line' => 3
58: },
59: { 'text' => 'x completed entry 4',
60: 'md5' => '8de0a2b65a50d5e30e84ad48af46fa78',
61: 'line' => 4
62: },
63: { 'text' => '(B) entry 5 is priority',
64: 'md5' => 'c1692dfbf3b5829b6bce44b1a1614980',
65: 'line' => 5
66: },
67: { 'text' => 'entry 6 +delete',
68: 'md5' => 'e1f6bf867f75aa019063782554407d02',
69: 'line' => 6
70: }
71: ];
72:
73: $result = undef;
74: ok( eval { $result = $api->render_list( $format, $list ) }, 'render_list' );
1.2 ! andrew 75: is_valid_json($result, 'list json is valid');
! 76: is_json( $result, to_json($list), 'Got expected render_list result' );
1.1 andrew 77:
78: foreach my $e ( @{$list} ) {
79: my $result;
1.2 ! andrew 80: ok( $result = $api->render_entry( $format, $e ), 'render_entry' );
! 81: is_valid_json($result, 'entry json is valid');
! 82: is_json( $result, to_json($e), 'Got correct render_entry result' );
1.1 andrew 83: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>