Bugzilla – Attachment 55649 Details for
Bug 17302
Add Koha::Util::Normalize for normalization functions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 17302: Add Koha::Util::Normalize for normalization functions
PASSED-QA-Bug-17302-Add-KohaUtilNormalize-for-norm.patch (text/plain), 5.35 KB, created by
Katrin Fischer
on 2016-09-18 10:59:22 UTC
(
hide
)
Description:
[PASSED QA] Bug 17302: Add Koha::Util::Normalize for normalization functions
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2016-09-18 10:59:22 UTC
Size:
5.35 KB
patch
obsolete
>From bea7195b7138db386603c2f4736e8c2a0b268634 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 14 Sep 2016 14:48:00 -0300 >Subject: [PATCH] [PASSED QA] Bug 17302: Add Koha::Util::Normalize for > normalization functions > >This patch introduces Koha::Util::Normalize, which includes the following normalization routines >that need no explanation: > >- remove_spaces >- upper_case >- lower_case > >and it also includes: > >- legacy_default: which basically does what C4::Matcher::_normalize does. > >All routines functionality are fully tested with the included in the included tests. > >To test: >- Apply the patch >- Run: > $ prove t/Koha/Util/Normalize.t >=> SUCCESS: All tests pass >- Sign off :-D > >Edit: Added Exporter to explicitly export the routines. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> >--- > Koha/Util/Normalize.pm | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ > t/Koha/Util/Normalize.t | 67 ++++++++++++++++++++++++++++++ > 2 files changed, 172 insertions(+) > create mode 100644 Koha/Util/Normalize.pm > create mode 100644 t/Koha/Util/Normalize.t > >diff --git a/Koha/Util/Normalize.pm b/Koha/Util/Normalize.pm >new file mode 100644 >index 0000000..487d5da >--- /dev/null >+++ b/Koha/Util/Normalize.pm >@@ -0,0 +1,105 @@ >+package Koha::Util::Normalize; >+ >+# Copyright 2016 Koha Development Team >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use parent qw( Exporter ); >+ >+our @EXPORT = qw( >+ legacy_default >+ remove_spaces >+ upper_case >+ lower_case >+); >+ >+=head1 NAME >+ >+Koha::Util::Normalize - utility class with string normalization routines >+ >+=head1 METHODS >+ >+=head2 legacy_default >+ >+Default normalization function >+ >+=cut >+ >+sub legacy_default { >+ >+ my $string = uc shift; >+ >+ $string =~ s/[.;:,\]\[\)\(\/'"]//g; >+ $string =~ s/^\s+//; >+ $string =~ s/\s+$//; >+ $string =~ s/\s+/ /g; >+ >+ return $string; >+} >+ >+=head2 remove_spaces >+ >+Normalization function removing spaces >+ >+=cut >+ >+sub remove_spaces { >+ >+ my $string = shift; >+ >+ $string =~ s/\s+//g; >+ >+ return $string; >+} >+ >+=head2 upper_case >+ >+Normalization function converting characters into upper-case >+ >+=cut >+ >+sub upper_case { >+ >+ my $string = uc shift; >+ >+ return $string; >+} >+ >+=head2 lower_case >+ >+Normalization function converting characters into lower-case >+ >+=cut >+ >+sub lower_case { >+ >+ my $string = lc shift; >+ >+ return $string; >+} >+ >+1; >+__END__ >+ >+=head1 AUTHOR >+ >+Koha Development Team <http://koha-community.org/> >+ >+Tomas Cohen Arazi <tomascohen@theke.io> >+ >+=cut >diff --git a/t/Koha/Util/Normalize.t b/t/Koha/Util/Normalize.t >new file mode 100644 >index 0000000..9ebdf06 >--- /dev/null >+++ b/t/Koha/Util/Normalize.t >@@ -0,0 +1,67 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 5; >+ >+BEGIN { >+ use_ok('Koha::Util::Normalize'); >+} >+ >+subtest 'legacy_default() normalizer' => sub { >+ >+ plan tests => 1; >+ >+ my $string = ' .; kY[]:, (l)/E\'"'; >+ >+ is( Koha::Util::Normalize::legacy_default( $string ), 'KY LE', >+ 'The \'legacy_default\' normalizer removes: .;:,][)(/\'" and shifts characters upper-case. >+ Also removes spaces from the beginning and ending, and replaces multiple spaces with a single one.' ); >+}; >+ >+subtest 'remove_spaces() normalizer' => sub { >+ >+ plan tests => 1; >+ >+ my $string = ' .; kY[]:, (l)/E\'"'; >+ >+ is( Koha::Util::Normalize::remove_spaces( $string ), '.;kY[]:,(l)/E\'"', >+ 'The \'remove_spaces\' normalizer removes all spaces' ); >+}; >+ >+subtest 'upper_case() normalizer' => sub { >+ >+ plan tests => 1; >+ >+ my $string = ' .; kY[]:, (l)/E\'"'; >+ >+ is( Koha::Util::Normalize::upper_case( $string ), ' .; KY[]:, (L)/E\'"', >+ 'The \'upper_case\' normalizer only makes characters upper-case' ); >+}; >+ >+subtest 'lower_case() normalizer' => sub { >+ >+ plan tests => 1; >+ >+ my $string = ' .; kY[]:, (l)/E\'"'; >+ >+ is( Koha::Util::Normalize::lower_case( $string ), ' .; ky[]:, (l)/e\'"', >+ 'The \'lower_case\' normalizer only makes characters lower-case' ); >+}; >+ >+1; >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17302
:
55571
|
55591
|
55600
|
55601
| 55649 |
55650