Koha/t/Labels_split_ddcn.t
Joe Atzberger 657371808a DDCN callnumber splitting with test.
Similar to previous patch for LCCN splitting, this patch incorporates
changes to split_ddcn and supplies a test file for verifying proper
operation.  Note that the only previously documented example for intended
operation is included as one of the tests.

This regexps are created to be rather forgiving.  For example, the function
will not choke if two spaces were included where the "spec" (such as it is)
expects one.  Obviously this is because for CN splitting purposes, it doesn't
matter, we're not going to ever split in the middle of whitespace.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
2009-04-03 18:47:48 -05:00

36 lines
1.1 KiB
Perl
Executable file

#!/usr/bin/perl
#
# for context, see http://bugs.koha.org
use strict;
use warnings;
use Test::More tests => 52;
BEGIN {
use_ok('C4::Labels');
}
ok(defined C4::Labels::split_ddcn, 'C4::Labels::split_ddcn defined');
my $ddcns = {
'BIO JP2 R5c.1' => [qw(BIO JP2 R5 c.1 )],
'FIC GIR J5c.1' => [qw(FIC GIR J5 c.1 )],
'J DAR G7c.11' => [qw( J DAR G7 c.11)],
'R220.3 H2793Z H32 c.2' => [qw(R 220.3 H2793Z H32 c.2)],
};
foreach my $ddcn (sort keys %$ddcns) {
my (@parts, @expected);
ok($ddcn, "ddcn: $ddcn");
ok(@expected = @{$ddcns->{$ddcn}}, "split expected to produce " . scalar(@expected) . " pieces");
ok(@parts = C4::Labels::split_ddcn($ddcn), "C4::Labels::split_ddcn($ddcn)");
ok(scalar(@expected) == scalar(@parts), sprintf("%d of %d pieces produced", scalar(@parts), scalar(@expected)));
my $i = 0;
foreach my $unit (@expected) {
my $part;
ok($part = $parts[$i], "($ddcn)[$i] populated: " . (defined($part) ? $part : 'UNDEF'));
ok((defined($part) and $part eq $unit), "($ddcn)[$i] matches: $unit");
$i++;
}
}