Annotation of todotxt/Text-Todo-REST-API/t/response.t, Revision 1.1
1.1 ! andrew 1: #===============================================================================
! 2: #
! 3: # FILE: response.t
! 4: #
! 5: # DESCRIPTION: Test Text::Todo::REST::API::Response
! 6: #
! 7: # AUTHOR: Andrew Fresh (AAF), andrew@cpan.org
! 8: # COMPANY: Red River Communications
! 9: # CREATED: 01/07/10 19:11
! 10: # REVISION: $AFresh1$
! 11: #===============================================================================
! 12:
! 13: use strict;
! 14: use warnings;
! 15:
! 16: use Test::More tests => 49;
! 17:
! 18: my $class;
! 19:
! 20: BEGIN {
! 21: $class = 'Text::Todo::REST::API::Response';
! 22: use_ok( $class, "use $class" );
! 23: }
! 24:
! 25: diag("Testing $class $Text::Todo::REST::API::Response::VERSION");
! 26:
! 27: my %data = (
! 28: files => ['todo.txt'],
! 29: list => [
! 30: { text => 'uno', md5 => 'XXX md5 of uno XXX' },
! 31: { text => 'dos', md5 => 'XXX md5 of dos XXX' },
! 32: { text => 'tre', md5 => 'XXX md5 of tre XXX' },
! 33: ],
! 34: entry => { text => 'ety', md5 => 'XXX md5 of ety XXX' },
! 35: );
! 36:
! 37: my %TESTS = (
! 38: undef => {
! 39: undef => {},
! 40: text => {},
! 41: md5 => {},
! 42: },
! 43:
! 44: files => {
! 45: undef => {
! 46: result => '/^Unable to handle \[render_files\] for format \[\]/',
! 47: },
! 48: text => {
! 49: result => undef,
! 50: data_result => "todo.txt\n"
! 51: },
! 52: md5 => {
! 53: result =>
! 54: '/^Unable to handle \[render_files\] for format \[md5\]/',
! 55: },
! 56: },
! 57:
! 58: list => {
! 59: undef => {
! 60: result => '/^Unable to handle \[render_list\] for format \[\]/',
! 61: },
! 62: text => {
! 63: result => undef,
! 64: data_result => ( join q{}, map "$_->{text}\n", @{ $data{list} } ),
! 65: },
! 66: md5 => {
! 67: result => undef,
! 68: data_result => ( join q{}, map "MD5 ($_->{text}) = $_->{md5}\n",
! 69: @{ $data{list} } ),
! 70: },
! 71: },
! 72:
! 73: entry => {
! 74: undef => {
! 75: result => '/^Unable to handle \[render_entry\] for format \[\]/',
! 76: },
! 77: text => {
! 78: result => undef,
! 79: data_result => ( join q{}, map "$_->{text}\n", $data{entry} ),
! 80: },
! 81: md5 => {
! 82: result => undef,
! 83: data_result => ( join q{}, map "MD5 ($_->{text}) = $_->{md5}\n",
! 84: $data{entry} ),
! 85: },
! 86: },
! 87: );
! 88:
! 89: foreach my $type ( sort keys %TESTS ) {
! 90: foreach my $format ( sort keys %{ $TESTS{$type} } ) {
! 91: foreach my $data ( undef, $data{$type} ) {
! 92: my $args;
! 93: if ( $type ne 'undef' ) {
! 94: $args->{type} = $type;
! 95: }
! 96: if ( $format ne 'undef' ) {
! 97: $args->{format} = $format;
! 98: }
! 99: if ($data) {
! 100: $args->{data} = $data;
! 101: }
! 102:
! 103: my $diag = "type [$type] format [$format]";
! 104: if ($data) {
! 105: $diag .= ' with data';
! 106: }
! 107:
! 108: test( $TESTS{$type}{$format}, $args, $diag );
! 109: }
! 110: }
! 111: }
! 112:
! 113: sub test {
! 114: my ( $test, $args, $diag ) = @_;
! 115:
! 116: if ( !exists $args->{type} ) {
! 117: ok( !eval { $class->new($args) }, "Create $class without type" );
! 118: like( $@, '/^option \[type\] required/', 'Got expected error' );
! 119: return 1;
! 120: }
! 121:
! 122: my $response = new_ok( $class, [$args] );
! 123:
! 124: my $expected = $test->{result};
! 125: if ( $args->{data} && exists $test->{data_result} ) {
! 126: $expected = $test->{data_result};
! 127: }
! 128:
! 129: my $result;
! 130: eval { $result = $response->render() };
! 131: if ($@) {
! 132: if (index $expected, '/') {
! 133: $expected = '/^$/';
! 134: }
! 135:
! 136: like( $@, $expected, 'Got expected eval_error - ' . $diag );
! 137: }
! 138: else {
! 139: is( $result, $expected, 'Got expected result - ' . $diag );
! 140: }
! 141: return 1;
! 142: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>