11 print "not " unless length("") == 0;
14 print "not " unless length("abc") == 3;
18 print "not " unless length() == 6;
21 # Okay, so that wasn't very challenging. Let's go Unicode.
26 print "not " unless length($a) == 1;
31 print "not " unless $a eq "\x41" && length($a) == 1;
37 my $a = pack("U", 0xFF);
39 print "not " unless length($a) == 1;
46 printf "#%vx for 0xFF\n",$a;
47 print "not " unless $a eq "\x8b\x73" && length($a) == 2;
51 print "not " unless $a eq "\xc3\xbf" && length($a) == 2;
60 print "not " unless length($a) == 1;
67 printf "#%vx for 0x100\n",$a;
68 print "not " unless $a eq "\x8c\x41" && length($a) == 2;
72 print "not " unless $a eq "\xc4\x80" && length($a) == 2;
79 my $a = "\x{100}\x{80}";
81 print "not " unless length($a) == 2;
88 printf "#%vx for 0x100 0x80\n",$a;
89 print "not " unless $a eq "\x8c\x41\x8a\x67" && length($a) == 4;
93 print "not " unless $a eq "\xc4\x80\xc2\x80" && length($a) == 4;
100 my $a = "\x{80}\x{100}";
102 print "not " unless length($a) == 2;
109 printf "#%vx for 0x80 0x100\n",$a;
110 print "not " unless $a eq "\x8a\x67\x8c\x41" && length($a) == 4;
114 print "not " unless $a eq "\xc2\x80\xc4\x80" && length($a) == 4;
120 # Now for Unicode with magical vtbls
125 tie $a, 'Tie::StdScalar'; # makes $a magical
128 print "not " unless length($a) == 1;
133 print "not " unless length($a) == 3;
139 # Play around with Unicode strings,
140 # give a little workout to the UTF-8 length cache.
141 my $a = chr(256) x 100;
142 print length $a == 100 ? "ok 16\n" : "not ok 16\n";
144 print length $a == 99 ? "ok 17\n" : "not ok 17\n";
146 print length $a == 198 ? "ok 18\n" : "not ok 18\n";
148 print length $a == 999 ? "ok 19\n" : "not ok 19\n";
149 substr($a, 0, 1) = '';
150 print length $a == 998 ? "ok 20\n" : "not ok 20\n";
159 tie $u, 'Tie::StdScalar', chr 256;
161 is(length $u, 1, "Length of a UTF-8 scalar returned from tie");
162 is(length $u, 1, "Again! Again!");
168 $SIG{__WARN__} = sub {
173 is(length(undef), undef, "Length of literal undef");
177 is(length($u), undef, "Length of regular scalar");
181 tie $u, 'Tie::StdScalar';
183 is(length($u), undef, "Length of tied scalar (MAGIC)");
189 use overload '""' => sub {return undef;};
192 my $uo = bless [], 'U';
194 is(length($uo), undef, "Length of overloaded reference");
196 # ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
198 is($warnings, 0, "There were no warnings");