4 if ($ENV{'PERL_CORE'}){
10 use Test::More tests => 68;
15 use overload '""' => 'stringify';
21 return bless [$value, $state], $class;
26 $self->[1] = ! $self->[1];
28 utf8::downgrade($self->[0]);
30 utf8::upgrade($self->[0]);
38 foreach my $t ("ASCII", "B\366se") {
39 my $length = length $t;
41 my $u = UTF8Toggle->new($t);
42 is (length $u, $length, "length of '$t'");
43 is (length $u, $length, "length of '$t'");
44 is (length $u, $length, "length of '$t'");
45 is (length $u, $length, "length of '$t'");
48 my $u = UTF8Toggle->new("\311");
51 is ($lc, "\311", "E accute -> e accute");
54 is ($lc, "\351", "E accute -> e accute");
57 is ($lc, "\311", "E accute -> e accute");
59 $u = UTF8Toggle->new("\351");
62 is ($uc, "\351", "e accute -> E accute");
65 is ($uc, "\311", "e accute -> E accute");
68 is ($uc, "\351", "e accute -> E accute");
70 $u = UTF8Toggle->new("\311");
73 is ($lc, "\311", "E accute -> e accute");
76 is ($lc, "\351", "E accute -> e accute");
79 is ($lc, "\311", "E accute -> e accute");
81 $u = UTF8Toggle->new("\351");
84 is ($uc, "\351", "e accute -> E accute");
87 is ($uc, "\311", "e accute -> E accute");
90 is ($uc, "\351", "e accute -> E accute");
92 my $have_setlocale = 0;
95 import POSIX ':locale_h';
100 if (!$have_setlocale) {
101 skip "No setlocale", 24;
102 } elsif (!setlocale(&POSIX::LC_ALL, "en_GB.ISO8859-1")) {
103 skip "Could not setlocale to en_GB.ISO8859-1", 24;
106 my $u = UTF8Toggle->new("\311");
109 is ($lc, "\351", "E accute -> e accute");
112 is ($lc, "\351", "E accute -> e accute");
115 is ($lc, "\351", "E accute -> e accute");
117 $u = UTF8Toggle->new("\351");
120 is ($uc, "\311", "e accute -> E accute");
123 is ($uc, "\311", "e accute -> E accute");
126 is ($uc, "\311", "e accute -> E accute");
128 $u = UTF8Toggle->new("\311");
131 is ($lc, "\351", "E accute -> e accute");
134 is ($lc, "\351", "E accute -> e accute");
137 is ($lc, "\351", "E accute -> e accute");
139 $u = UTF8Toggle->new("\351");
142 is ($uc, "\311", "e accute -> E accute");
145 is ($uc, "\311", "e accute -> E accute");
148 is ($uc, "\311", "e accute -> E accute");
152 my $tmpfile = 'overload.tmp';
154 foreach my $operator (qw (print)) {
155 foreach my $layer ('', ':utf8') {
156 open my $fh, "+>$layer", $tmpfile or die $!;
157 my $u = UTF8Toggle->new("\311\n");
161 my $l = UTF8Toggle->new("\351\n", 1);
166 seek $fh, 0, 0 or die $!;
168 chomp ($line = <$fh>);
169 is ($line, "\311", "$operator $layer");
170 chomp ($line = <$fh>);
171 is ($line, "\311", "$operator $layer");
172 chomp ($line = <$fh>);
173 is ($line, "\311", "$operator $layer");
174 chomp ($line = <$fh>);
175 is ($line, "\351", "$operator $layer");
176 chomp ($line = <$fh>);
177 is ($line, "\351", "$operator $layer");
178 chomp ($line = <$fh>);
179 is ($line, "\351", "$operator $layer");
182 unlink $tmpfile or die $!;
188 1 while -f $tmpfile and unlink $tmpfile || die "unlink '$tmpfile': $!";