forked from Koha-Community/Koha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharset.t
executable file
·74 lines (57 loc) · 2.68 KB
/
Charset.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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 => 16;
use Encode qw( is_utf8 );
use MARC::Record;
use utf8;
use open ':std', ':encoding(utf8)';
BEGIN {
use_ok('C4::Charset');
}
my $string;
ok(!defined(NormalizeString($string,undef,1)),'Uninitialized string case 1 normalizes to uninitialized string.');
$string = 'Sample';
ok(defined(NormalizeString($string,undef,0)), 'Initialized string case 1 normalizes to some string.');
ok(defined(NormalizeString($string,undef,1)), 'Initialized string case 2 normalizes to some string.');
ok(defined(NormalizeString($string,1,0)), 'Initialized string case 3 normalizes to some string.');
ok(defined(NormalizeString($string,1,1)), 'Initialized string case 4 normalizes to some string.');
my $octets = "abc";
ok(IsStringUTF8ish($octets), "verify octets are valid UTF-8 (ASCII)");
$octets = "flamb\xc3\xa9";
ok(!Encode::is_utf8($octets), "verify that string does not have Perl UTF-8 flag on");
ok(IsStringUTF8ish($octets), "verify octets are valid UTF-8 (LATIN SMALL LETTER E WITH ACUTE)");
ok(!Encode::is_utf8($octets), "verify that IsStringUTF8ish does not magically turn Perl UTF-8 flag on");
$octets = "a\xc2" . "c";
ok(!IsStringUTF8ish($octets), "verify octets are not valid UTF-8");
ok( !SetUTF8Flag(), 'SetUTF8Flag returns undef if no record passed' );
my $record = MARC::Record->new();
ok( !SetUTF8Flag($record), 'SetUTF8Flag returns undef if the record has no subfields' );
# Add some fields/subfields
$record->append_fields(
MARC::Field->new('100', ' ', ' ', a => 'Julio Cortazar'),
MARC::Field->new('245', ' ', ' ', a => 'Rayuela'),
);
# Verify our data serves its purpose
ok( !Encode::is_utf8($record->subfield('100','a')) &&
!Encode::is_utf8($record->subfield('245','a')),
'Verify that the subfields are NOT set the UTF-8 flag yet' );
SetUTF8Flag($record);
ok( Encode::is_utf8($record->subfield('100','a')) &&
Encode::is_utf8($record->subfield('245','a')),
'SetUTF8Flag sets the UTF-8 flag to all subfields' );
is( nsb_clean("Le Moyen Âge"), "Le Moyen Âge", "nsb_clean removes and " );
1;