4 if ($ENV{'PERL_CORE'}){
10 use Test::More tests => 116;
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 ('print', 'syswrite', 'syswrite len', 'syswrite off',
155 'syswrite len off') {
156 foreach my $layer ('', ':utf8') {
157 open my $fh, "+>$layer", $tmpfile or die $!;
158 my $pad = $operator =~ /\boff\b/ ? "\243" : "";
159 my $trail = $operator =~ /\blen\b/ ? "!" : "";
160 my $u = UTF8Toggle->new("$pad\311\n$trail");
161 my $l = UTF8Toggle->new("$pad\351\n$trail", 1);
162 if ($operator eq 'print') {
169 } elsif ($operator eq 'syswrite') {
176 } elsif ($operator eq 'syswrite len') {
183 } elsif ($operator eq 'syswrite off'
184 || $operator eq 'syswrite len off') {
185 syswrite $fh, $u, 2, 1;
186 syswrite $fh, $u, 2, 1;
187 syswrite $fh, $u, 2, 1;
188 syswrite $fh, $l, 2, 1;
189 syswrite $fh, $l, 2, 1;
190 syswrite $fh, $l, 2, 1;
195 seek $fh, 0, 0 or die $!;
197 chomp ($line = <$fh>);
198 is ($line, "\311", "$operator $layer");
199 chomp ($line = <$fh>);
200 is ($line, "\311", "$operator $layer");
201 chomp ($line = <$fh>);
202 is ($line, "\311", "$operator $layer");
203 chomp ($line = <$fh>);
204 is ($line, "\351", "$operator $layer");
205 chomp ($line = <$fh>);
206 is ($line, "\351", "$operator $layer");
207 chomp ($line = <$fh>);
208 is ($line, "\351", "$operator $layer");
211 unlink $tmpfile or die $!;
217 1 while -f $tmpfile and unlink $tmpfile || die "unlink '$tmpfile': $!";