Bug 26384: Fix executable flags
[koha.git] / t / Koha / Util / Normalize.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 => 6;
21 use Test::Warn;
22
23 BEGIN {
24     use_ok('Koha::Util::Normalize');
25 }
26
27 subtest 'pass undef' => sub {
28     plan tests => 8;
29
30     is( legacy_default(), undef, 'legacy_default returns undef' );
31     warning_is { legacy_default() } undef, 'no warn from legacy_default';
32
33     is( remove_spaces(), undef, 'remove_spaces returns undef' );
34     warning_is { remove_spaces() } undef, 'no warn from remove_spaces';
35
36     is( upper_case(), undef, 'upper_case returns undef' );
37     warning_is { upper_case() } undef, 'no warn from upper_case';
38
39     is( lower_case(), undef, 'lower_case returns undef' );
40     warning_is { lower_case() } undef, 'no warn from lower_case';
41 };
42
43
44 subtest 'legacy_default() normalizer' => sub {
45
46     plan tests => 1;
47
48     my $string = '  .; kY[]:,  (l)/E\'"';
49
50     is( Koha::Util::Normalize::legacy_default( $string ), 'KY LE',
51         'The \'legacy_default\' normalizer removes: .;:,][)(/\'" and shifts characters upper-case.
52          Also removes spaces from the beginning and ending, and replaces multiple spaces with a single one.' );
53 };
54
55 subtest 'remove_spaces() normalizer' => sub {
56
57     plan tests => 1;
58
59     my $string = '  .; kY[]:,  (l)/E\'"';
60
61     is( Koha::Util::Normalize::remove_spaces( $string ), '.;kY[]:,(l)/E\'"',
62         'The \'remove_spaces\' normalizer removes all spaces' );
63 };
64
65 subtest 'upper_case() normalizer' => sub {
66
67     plan tests => 1;
68
69     my $string = '  .; kY[]:,  (l)/E\'"';
70
71     is( Koha::Util::Normalize::upper_case( $string ), '  .; KY[]:,  (L)/E\'"',
72         'The \'upper_case\' normalizer only makes characters upper-case' );
73 };
74
75 subtest 'lower_case() normalizer' => sub {
76
77     plan tests => 1;
78
79     my $string = '  .; kY[]:,  (l)/E\'"';
80
81     is( Koha::Util::Normalize::lower_case( $string ), '  .; ky[]:,  (l)/e\'"',
82         'The \'lower_case\' normalizer only makes characters lower-case' );
83 };
84