1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/usr/bin/perl
use Test::More;
use File::Spec::Functions qw(catfile);
subtest 'setup' => sub {
use_ok( 'Business::ISBN::Data' );
ok( %Business::ISBN::country_data );
};
subtest 'included_range_message' => sub {
plan skip_all => "Debian doesn't include a RangeMessage.xml that could be tested here" if $ENV{AUTOPKGTEST_TMP};
# Test with included RangeMessage.xml in the same spot as the module
like( $Business::ISBN::country_data{_source}, qr/RangeMessage\.xml/ );
like( $Business::ISBN::country_data{_source}, qr/blib/ );
foreach my $isbn_prefix ("978", "979") {
foreach my $key ( sort { $a <=> $b } grep { ! /\A_/ } keys %{ $Business::ISBN::country_data{$isbn_prefix} } ) {
my $value = $Business::ISBN::country_data{$isbn_prefix}->{$key};
isa_ok( $value, ref [], "Value is array ref for country $key" );
my( $country, $ranges ) = @$value;
my $count = @$ranges;
ok( ($count % 2) == 0, "Even number of elements ($count) for country $key" );
}
}
};
subtest 'env_range_message' => sub {
# Test with RangeMessage.xml set in ISBN_RANGE_MESSAGE
local $ENV{ISBN_RANGE_MESSAGE} = catfile( qw(lib Business ISBN RangeMessage.xml) );
local %Business::ISBN::country_data = Business::ISBN::Data::_get_data();
ok( -e $ENV{ISBN_RANGE_MESSAGE}, 'Alternate RangeMessage.xml exists' );
unlike( $Business::ISBN::country_data{_source}, qr/blib/ );
like( $Business::ISBN::country_data{_source}, qr/RangeMessage\.xml/ );
foreach my $isbn_prefix ("978", "979") {
foreach my $key ( sort { $a <=> $b } grep { ! /\A_/ } keys %{ $Business::ISBN::country_data{$isbn_prefix} } ) {
my $value = $Business::ISBN::country_data{$isbn_prefix}->{$key};
isa_ok( $value, ref [], "Value is array ref for country $key" );
my( $country, $ranges ) = @$value;
my $count = @$ranges;
ok( ($count % 2) == 0, "Even number of elements ($count) for country $key" );
}
}
};
subtest 'missing_range_message' => sub {
# Test with RangeMessage.xml set in ISBN_RANGE_MESSAGE
my $file = catfile( qw(blib lib Business ISBN RangeMessage.xml) );
my $out_of_the_way = $file . '.hidden';
rename $file => $out_of_the_way unless $ENV{AUTOPKGTEST_TMP};
ok( ! -e $file, 'RangeMessage.xml is out of the way' );
local %Business::ISBN::country_data = Business::ISBN::Data::_get_data();
like( $Business::ISBN::country_data{_source}, qr/\bData\.pm/, 'Data source is the default data structure' );
rename $out_of_the_way => $file unless $ENV{AUTOPKGTEST_TMP};
};
subtest 'default_data' => sub {
# Test with default data
local %Business::ISBN::country_data = Business::ISBN::Data::_default_data();
like( $Business::ISBN::country_data{_source}, qr/Data\.pm/ );
foreach my $isbn_prefix ("978", "979") {
foreach my $key ( sort { $a <=> $b } grep { ! /\A_/ } keys %{ $Business::ISBN::country_data{$isbn_prefix} } ) {
my $value = $Business::ISBN::country_data{$isbn_prefix}->{$key};
isa_ok( $value, ref [], "Value is array ref for country $key" );
my( $country, $ranges ) = @$value;
my $count = @$ranges;
ok( ($count % 2) == 0, "Even number of elements ($count) for country $key" );
}
}
};
done_testing();
|