=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/t/network_tests.t,v retrieving revision 1.12 retrieving revision 1.15 diff -u -r1.12 -r1.15 --- HOPE/Net-OpenAMD/t/network_tests.t 2010/07/13 07:10:31 1.12 +++ HOPE/Net-OpenAMD/t/network_tests.t 2010/07/17 13:10:48 1.15 @@ -1,7 +1,7 @@ #!perl package NetworkTests; -# $AFresh1: network_tests.t,v 1.11 2010/07/13 03:37:47 andrew Exp $ +# $AFresh1: network_tests.t,v 1.14 2010/07/17 11:46:47 andrew Exp $ use strict; use warnings; @@ -14,15 +14,14 @@ if ( !caller() ) { if ( $ENV{'NETWORK_TESTS'} ) { - plan tests => 31; + plan tests => 14; } else { plan skip_all => 'Network test. Set $ENV{NETWORK_TESTS} to a true value to run.'; } - my $amd - = Net::OpenAMD->new( { base_uri => 'http://api.hope.net/api/', } ); + my $amd = Net::OpenAMD->new(); run_tests($amd); #done_testing(); @@ -54,18 +53,20 @@ area => any('Engressia'), interests => any(@interests), all_interests => bag(@interests), - coordinate => re('^\d\d\.\d+$'), + coordinate => re('^\d{1,2}\.\d+$'), boolean => any( 'True', 'False' ), ); $cmp{user} = [ $cmp{single_line}, - { name => $cmp{single_line}, + superhashof( + { name => $cmp{single_line}, - #interests => array_each( $cmp{interests} ), - #x => $cmp{coordinate}, - #y => $cmp{coordinate}, - } + #interests => array_each( $cmp{interests} ), + #x => $cmp{coordinate}, + #y => $cmp{coordinate}, + } + ), ]; $cmp{speaker} = [ @@ -75,27 +76,31 @@ } ]; + $cmp{location} = superhashof( + { #area => $cmp{area}, + user => $cmp{single_line}, + + #button => $cmp{boolean}, + x => $cmp{coordinate}, + y => $cmp{coordinate}, + + #time => $cmp{single_line}, + } + ); + my %tests = ( location => [ { args => undef, - expect => array_each( - { area => $cmp{area}, - user => $cmp{digits}, - button => $cmp{boolean}, - x => $cmp{coordinate}, - y => $cmp{coordinate}, - time => $cmp{single_line}, - } - ), + expect => array_each( $cmp{location} ), }, { args => { user => 'user0' }, - expect => array_each(), + expect => qr/^Invalid \s JSON|$/xms, }, - { args => { user => 'user0', limit => 20 }, - expect => array_each(), + { args => { user => 'user0', limit => 5 }, + expect => qr/^Invalid \s JSON|$/xms, }, - { args => { area => 'Engressa' }, - expect => array_each(), + { args => { area => 'Lovelace' }, + expect => array_each( $cmp{location} ), }, ], speakers => [ @@ -165,10 +170,14 @@ like( $@, $test->{expect}, "AMD->$method($test->{args})" ); } elsif ( ref $test->{expect} ) { - is( $@, '', "AMD->$method($test->{args})" ); - cmp_deeply( $result, $test->{expect}, - "AMD->$method($test->{args}) - " - . 'got expected result' ); + if ($@) { + is( $@, '', "AMD->$method($test->{args})" ); + } + else { + cmp_deeply( $result, $test->{expect}, + "AMD->$method($test->{args}) - " + . 'got expected result' ); + } } else { is( $@, $test->{expect}, "AMD->$method($test->{args})" );