BEGIN {
chdir 't' if -d 't';
+ require './test.pl';
@INC = '../lib';
}
-print "1..13\n";
+plan (tests => 28);
print "not " unless length("") == 0;
print "ok 1\n";
}
{
- my $a = pack("U", 0x80);
+ my $a = pack("U", 0xFF);
print "not " unless length($a) == 1;
print "ok 6\n";
use bytes;
if (ord('A') == 193)
{
- printf "#%vx for 0x80\n",$a;
- print "not " unless $a eq "\x8a\x67" && length($a) == 2;
+ printf "#%vx for 0xFF\n",$a;
+ print "not " unless $a eq "\x8b\x73" && length($a) == 2;
}
else
{
- print "not " unless $a eq "\xc2\x80" && length($a) == 2;
+ print "not " unless $a eq "\xc3\xbf" && length($a) == 2;
}
print "ok 7\n";
$test++;
print "ok 15\n";
$test++;
}
+
+{
+ # Play around with Unicode strings,
+ # give a little workout to the UTF-8 length cache.
+ my $a = chr(256) x 100;
+ print length $a == 100 ? "ok 16\n" : "not ok 16\n";
+ chop $a;
+ print length $a == 99 ? "ok 17\n" : "not ok 17\n";
+ $a .= $a;
+ print length $a == 198 ? "ok 18\n" : "not ok 18\n";
+ $a = chr(256) x 999;
+ print length $a == 999 ? "ok 19\n" : "not ok 19\n";
+ substr($a, 0, 1) = '';
+ print length $a == 998 ? "ok 20\n" : "not ok 20\n";
+}
+
+curr_test(21);
+
+require Tie::Scalar;
+
+$u = "ASCII";
+
+tie $u, 'Tie::StdScalar', chr 256;
+
+is(length $u, 1, "Length of a UTF-8 scalar returned from tie");
+is(length $u, 1, "Again! Again!");
+
+$^W = 1;
+
+my $warnings = 0;
+
+$SIG{__WARN__} = sub {
+ $warnings++;
+ warn @_;
+};
+
+is(length(undef), undef, "Length of literal undef");
+
+my $u;
+
+is(length($u), undef, "Length of regular scalar");
+
+$u = "Gotcha!";
+
+tie $u, 'Tie::StdScalar';
+
+is(length($u), undef, "Length of tied scalar (MAGIC)");
+
+is($u, undef);
+
+{
+ package U;
+ use overload '""' => sub {return undef;};
+}
+
+my $uo = bless [], 'U';
+
+is(length($uo), undef, "Length of overloaded reference");
+
+# ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
+
+is($warnings, 0, "There were no warnings");