This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Add comment
[perl5.git] / lib / DBM_Filter / t / utf8.t
CommitLineData
0e9b1cbd
PM
1
2use strict;
3use warnings;
4use Carp;
5
6BEGIN
7{
8
9 eval { require Encode; };
10
11 if ($@) {
12 print "1..0 # Skip: Encode is not available\n";
13 exit 0;
14 }
15}
16
17require "dbm_filter_util.pl";
18
19use Test::More tests => 20;
20
21BEGIN { use_ok('DBM_Filter') };
e8ebc68a
JH
22my $db_file;
23BEGIN {
24 use Config;
25 foreach (qw/SDBM_File ODBM_File NDBM_File GDBM_File DB_File/) {
26 if ($Config{extensions} =~ /\b$_\b/) {
27 $db_file = $_;
28 last;
29 }
30 }
31 use_ok($db_file);
32};
0e9b1cbd
PM
33BEGIN { use_ok('Fcntl') };
34BEGIN { use_ok('charnames', qw{greek})};
35
36use charnames qw{greek};
37
38unlink <Op_dbmx*>;
39END { unlink <Op_dbmx*>; }
40
41my %h1 = () ;
e8ebc68a 42my $db1 = tie(%h1, $db_file,'Op_dbmx', O_RDWR|O_CREAT, 0640) ;
0e9b1cbd 43
e8ebc68a 44ok $db1, "tied to $db_file";
0e9b1cbd
PM
45
46eval { $db1->Filter_Push('utf8') };
47is $@, '', "push a 'utf8' filter" ;
48
49{
50 no warnings 'uninitialized';
51 StoreData(\%h1,
52 {
53 undef() => undef(),
54 "beta" => "\N{beta}",
55 'alpha' => "\N{alpha}",
56 "\N{gamma}"=> "gamma",
57 });
58
59}
60
61VerifyData(\%h1,
62 {
63 'alpha' => "\N{alpha}",
64 "beta" => "\N{beta}",
65 "\N{gamma}"=> "gamma",
66 "" => "",
67 });
68
69undef $db1;
70{
71 use warnings FATAL => 'untie';
72 eval { untie %h1 };
73 is $@, '', "untie without inner references" ;
74}
75
76# read the dbm file without the filter
77my %h2 = () ;
e8ebc68a 78my $db2 = tie(%h2, $db_file,'Op_dbmx', O_RDWR|O_CREAT, 0640) ;
0e9b1cbd 79
e8ebc68a 80ok $db2, "tied to $db_file";
0e9b1cbd 81
2f3efc97
JH
82if (ord('A') == 193) { # EBCDIC.
83 VerifyData(\%h2,
84 {
85 'alpha' => "\xB4\x58",
86 'beta' => "\xB4\x59",
87 "\xB4\x62"=> "gamma",
88 "" => "",
89 });
90} else {
91 VerifyData(\%h2,
92 {
93 'alpha' => "\xCE\xB1",
94 'beta' => "\xCE\xB2",
95 "\xCE\xB3"=> "gamma",
96 "" => "",
97 });
98}
0e9b1cbd
PM
99
100undef $db2;
101{
102 use warnings FATAL => 'untie';
103 eval { untie %h2 };
104 is $@, '', "untie without inner references" ;
105}
106