Bug 28385: Add tests
[koha.git] / t / Labels_split_Regex.t
1 #!/usr/bin/perl
2 #
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 5;
21 use C4::ClassSplitRoutine::RegEx;
22
23 my $callnumbers = {
24     '830 Han'          => [qw{830 Han}],
25     '159.9 (091) Gesh' => [qw{159.9 (091) Gesh}],
26     'J 3 Kin =774'     => ['J 3', 'Kin', '=774'],
27     '830 Hil =774 4'   => [qw{830 Hil =774 4}],
28     '830 Las=20 4'     => [qw{830 Las =20 4}],
29 };
30
31 # Split on spaces and before =
32 # If starts with J or K then do not split the first 2 groups
33 my @regexs = ('s/\s/\n/g', 's/(\s?=)/\n=/g', 's/^(J|K)\n/$1 /');
34 foreach my $cn (sort keys %$callnumbers) {
35     my @parts = C4::ClassSplitRoutine::RegEx::split_callnumber($cn, \@regexs);
36     my @expected = @{$callnumbers->{$cn}};
37     is_deeply(\@parts, \@expected);
38 }