bug 3120: tweak splitting of Dewey call number
[koha.git] / t / Labels_split_ddcn.t
1 #!/usr/bin/perl
2 #
3 # for context, see http://bugs.koha.org
4
5 use strict;
6 use warnings;
7
8 use Test::More tests => 62;
9
10 BEGIN {
11     use_ok('C4::Labels');
12 }
13 ok(defined C4::Labels::split_ddcn, 'C4::Labels::split_ddcn defined');
14
15 my $ddcns = {
16     'BIO JP2 R5c.1'         => [qw(BIO JP2 R5 c.1 )],
17     'FIC GIR J5c.1'         => [qw(FIC GIR J5 c.1 )],
18     'J DAR G7c.11'          => [qw( J  DAR G7 c.11)],
19     'R220.3 H2793Z H32 c.2' => [qw(R 220.3 H2793Z H32 c.2)],
20     'CD-ROM 787.87 EAS'     => [qw(CD-ROM 787.87 EAS)],
21 };
22
23 foreach my $ddcn (sort keys %$ddcns) {
24     my (@parts, @expected);
25     ok($ddcn, "ddcn: $ddcn");
26     ok(@expected = @{$ddcns->{$ddcn}}, "split expected to produce " . scalar(@expected) . " pieces");
27     ok(@parts = C4::Labels::split_ddcn($ddcn), "C4::Labels::split_ddcn($ddcn)");
28     ok(scalar(@expected) == scalar(@parts), sprintf("%d of %d pieces produced", scalar(@parts), scalar(@expected)));
29     my $i = 0;
30     foreach my $unit (@expected) {
31         my $part;
32         ok($part = $parts[$i], "($ddcn)[$i] populated: " . (defined($part) ? $part : 'UNDEF'));
33         ok((defined($part) and $part eq $unit),     "($ddcn)[$i]   matches: $unit");
34         $i++;
35     }
36 }
37