This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_length should stringify before checking DO_UTF8
[perl5.git] / t / op / length.t
index c73d4c5..dffc583 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     @INC = '../lib';
 }
 
-plan (tests => 30);
+plan (tests => 39);
 
 print "not " unless length("")    == 0;
 print "ok 1\n";
@@ -193,9 +193,22 @@ 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?
+my $ul = 3;
+is(($ul = length(undef)), undef, 
+                    "Returned length of undef with result in TARG");
+is($ul, undef, "Assigned length of undef with result in TARG");
+
+$ul = 3;
+is(($ul = length($u)), undef,
+                "Returned length of tied undef with result in TARG");
+is($ul, undef, "Assigned length of tied undef with result in TARG");
+
+$ul = 3;
+is(($ul = length($uo)), undef,
+                "Returned length of overloaded undef with result in TARG");
+is($ul, undef, "Assigned length of overloaded undef with result in TARG");
 
-is($warnings, 0, "There were no warnings");
+# ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
 
 {
     my $y = "\x{100}BC";
@@ -203,3 +216,25 @@ is($warnings, 0, "There were no warnings");
     is(length $y, 3,
        'Check that sv_len_utf8() can take advantage of the offset cache');
 }
+
+{
+    local $SIG{__WARN__} = sub {
+        pass("'print length undef' warned");
+    };
+    print length undef;
+}
+
+{
+    local $SIG{__WARN__} = sub {
+       pass '[perl #106726] no crash with length @lexical warning'
+    };
+    eval ' sub { length my @forecasts } ';
+}
+
+# length could be fooled by UTF8ness of non-magical variables changing with
+# stringification.
+my $ref = [];
+bless $ref, "\x{100}";
+is length $ref, length "$ref", 'length on reference blessed to utf8 class';
+
+is($warnings, 0, "There were no other warnings");