8 require './charset_tools.pl';
12 plan (tests => 46 + 3 * $::IS_ASCII);
19 # Okay, so that wasn't very challenging. Let's go Unicode.
30 if ($::IS_ASCII) { # Generally UTF-8 invariant on EBCDIC, so skip there
31 my $a = pack("U", 0xFF);
36 ok($a eq byte_utf8a_to_utf8n("\xc3\xbf"));
41 my $a = pack("U", 0xB6); # Works on both ASCII and EBCDIC
46 ok($a eq byte_utf8a_to_utf8n("\xc2\xb6"));
56 ok($a eq byte_utf8a_to_utf8n("\xc4\x80"));
61 my $a = "\x{100}\x{B6}";
66 ok($a eq byte_utf8a_to_utf8n("\xc4\x80\xc2\xb6"));
71 my $a = "\x{b6}\x{100}";
76 ok($a eq byte_utf8a_to_utf8n("\xc2\xb6\xc4\x80"));
80 # Now for Unicode with magical vtbls
85 tie $a, 'Tie::StdScalar'; # makes $a magical
95 # Play around with Unicode strings,
96 # give a little workout to the UTF-8 length cache.
97 my $a = chr(256) x 100;
105 substr($a, 0, 1) = '';
113 tie $u, 'Tie::StdScalar', chr 256;
115 is(length $u, 1, "Length of a UTF-8 scalar returned from tie");
116 is(length $u, 1, "Again! Again!");
122 $SIG{__WARN__} = sub {
127 is(length(undef), undef, "Length of literal undef");
131 is(length($u), undef, "Length of regular scalar");
135 tie $u, 'Tie::StdScalar';
137 is(length($u), undef, "Length of tied scalar (MAGIC)");
143 use overload '""' => sub {return undef;};
146 my $uo = bless [], 'U';
150 local $SIG{__WARN__} = sub { $w = shift };
151 is(length($uo), 0, "Length of overloaded reference");
152 like $w, qr/uninitialized/, 'uninit warning for stringifying as undef';
156 is(($ul = length(undef)), undef,
157 "Returned length of undef with result in TARG");
158 is($ul, undef, "Assigned length of undef with result in TARG");
161 is(($ul = length($u)), undef,
162 "Returned length of tied undef with result in TARG");
163 is($ul, undef, "Assigned length of tied undef with result in TARG");
168 local $SIG{__WARN__} = sub { $w = shift };
169 is(($ul = length($uo)), 0,
170 "Returned length of overloaded undef with result in TARG");
171 like $w, qr/uninitialized/, 'uninit warning for stringifying as undef';
173 is($ul, 0, "Assigned length of overloaded undef with result in TARG");
177 is(index($y, "B"), 1, 'adds an intermediate position to the offset cache');
179 'Check that sv_len_utf8() can take advantage of the offset cache');
183 local $SIG{__WARN__} = sub {
184 pass("'print length undef' warned");
190 local $SIG{__WARN__} = sub {
191 pass '[perl #106726] no crash with length @lexical warning'
193 eval ' sub { length my @forecasts } ';
196 # length could be fooled by UTF8ness of non-magical variables changing with
199 bless $ref, "\x{100}";
200 is length $ref, length "$ref", 'length on reference blessed to utf8 class';
202 is($warnings, 0, "There were no other warnings");