Khk updates
[koha.git] / t / Labels_split_lccn.t
1 #!/usr/bin/perl
2 #
3 # for context, see http://bugs.koha.org/cgi-bin/bugzilla/show_bug.cgi?id=2691
4
5 use strict;
6 use warnings;
7
8 use Test::More tests => 44;
9
10 BEGIN {
11     use_ok('C4::Labels');
12 }
13 ok(defined C4::Labels::split_lccn, 'C4::Labels::split_lccn defined');
14
15 my $lccns = {
16     'HE8700.7 .P6T44 1983' => [qw(HE 8700.7 .P6 T44 1983)],
17     'BS2545.E8 H39 1996'   => [qw(BS 2545 .E8 H39 1996)],
18     'NX512.S85 A4 2006'    => [qw(NX 512 .S85 A4 2006)],
19 };
20
21 foreach my $lccn (sort keys %$lccns) {
22     my (@parts, @expected);
23     ok($lccn, "lccn: $lccn");
24     ok(@expected = @{$lccns->{$lccn}}, "split expected to produce " . scalar(@expected) . " pieces");
25     ok(@parts = C4::Labels::split_lccn($lccn), "C4::Labels::split_lccn($lccn)");
26     ok(scalar(@expected) == scalar(@parts), sprintf("%d of %d pieces produced", scalar(@parts), scalar(@expected)));
27     my $i = 0;
28     foreach my $unit (@expected) {
29         my $part;
30         ok($part = $parts[$i], "($lccn)[$i] populated: " . (defined($part) ? $part : 'UNDEF'));
31         ok((defined($part) and $part eq $unit),     "($lccn)[$i]   matches: $unit");
32         $i++;
33     }
34 }
35