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