Re: [PATCH] Make the 'sort' pragma lexically scoped
[p5sagit/p5-mst-13.2.git] / lib / DBM_Filter / t / encode.t
CommitLineData
0e9b1cbd 1
2use strict;
3use warnings;
4use Carp;
5
6
7BEGIN
8{
9
10 eval { require Encode; };
11
12 if ($@) {
13 print "1..0 # Skip: Encode is not available\n";
14 exit 0;
15 }
16}
17
18
19require "dbm_filter_util.pl";
20
21use Test::More tests => 26;
22
23BEGIN { use_ok('DBM_Filter') };
24BEGIN { use_ok('SDBM_File') };
25BEGIN { use_ok('Fcntl') };
26BEGIN { use_ok('charnames', qw{greek})};
27
28use charnames qw{greek};
29
30unlink <Op_dbmx*>;
31END { unlink <Op_dbmx*>; }
32
33my %h1 = () ;
34my $db1 = tie(%h1, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
35
36ok $db1, "tied to SDBM_File";
37
38eval { $db1->Filter_Push('encode' => 'blah') };
39like $@, qr/^Encoding 'blah' is not available/, "push an illigal filter" ;
40
41eval { $db1->Filter_Push('encode') };
42is $@, '', "push an 'encode' filter (default to utf-8)" ;
43
44
45{
46 no warnings 'uninitialized';
47 StoreData(\%h1,
48 {
49 undef() => undef(),
50 'alpha' => "\N{alpha}",
51 "\N{gamma}"=> "gamma",
52 "beta" => "\N{beta}",
53 });
54
55}
56
57VerifyData(\%h1,
58 {
59 'alpha' => "\N{alpha}",
60 "beta" => "\N{beta}",
61 "\N{gamma}"=> "gamma",
62 "" => "",
63 });
64
65eval { $db1->Filter_Pop() };
66is $@, '', "pop the 'utf8' filter" ;
67
68eval { $db1->Filter_Push('encode' => 'iso-8859-16') };
69is $@, '', "push an 'encode' filter (specify iso-8859-16)" ;
70
71use charnames qw{:full};
72StoreData(\%h1,
73 {
74 'euro' => "\N{EURO SIGN}",
75 });
76
77undef $db1;
78{
79 use warnings FATAL => 'untie';
80 eval { untie %h1 };
81 is $@, '', "untie without inner references" ;
82}
83
84# read the dbm file without the filter
85my %h2 = () ;
86my $db2 = tie(%h2, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
87
88ok $db2, "tied to SDBM_File";
89
90VerifyData(\%h2,
91 {
92 'alpha' => "\xCE\xB1",
93 'beta' => "\xCE\xB2",
94 "\xCE\xB3"=> "gamma",
95 'euro' => "\xA4",
96 "" => "",
97 });
98
99undef $db2;
100{
101 use warnings FATAL => 'untie';
102 eval { untie %h2 };
103 is $@, '', "untie without inner references" ;
104}
105