10 print "not " unless length("") == 0;
13 print "not " unless length("abc") == 3;
17 print "not " unless length() == 6;
20 # Okay, so that wasn't very challenging. Let's go Unicode.
25 print "not " unless length($a) == 1;
30 print "not " unless $a eq "\x41" && length($a) == 1;
36 my $a = pack("U", 0xFF);
38 print "not " unless length($a) == 1;
45 printf "#%vx for 0xFF\n",$a;
46 print "not " unless $a eq "\x8b\x73" && length($a) == 2;
50 print "not " unless $a eq "\xc3\xbf" && length($a) == 2;
59 print "not " unless length($a) == 1;
66 printf "#%vx for 0x100\n",$a;
67 print "not " unless $a eq "\x8c\x41" && length($a) == 2;
71 print "not " unless $a eq "\xc4\x80" && length($a) == 2;
78 my $a = "\x{100}\x{80}";
80 print "not " unless length($a) == 2;
87 printf "#%vx for 0x100 0x80\n",$a;
88 print "not " unless $a eq "\x8c\x41\x8a\x67" && length($a) == 4;
92 print "not " unless $a eq "\xc4\x80\xc2\x80" && length($a) == 4;
99 my $a = "\x{80}\x{100}";
101 print "not " unless length($a) == 2;
108 printf "#%vx for 0x80 0x100\n",$a;
109 print "not " unless $a eq "\x8a\x67\x8c\x41" && length($a) == 4;
113 print "not " unless $a eq "\xc2\x80\xc4\x80" && length($a) == 4;
119 # Now for Unicode with magical vtbls
124 tie $a, 'Tie::StdScalar'; # makes $a magical
127 print "not " unless length($a) == 1;
132 print "not " unless length($a) == 3;
138 # Play around with Unicode strings,
139 # give a little workout to the UTF-8 length cache.
140 my $a = chr(256) x 100;
141 print length $a == 100 ? "ok 16\n" : "not ok 16\n";
143 print length $a == 99 ? "ok 17\n" : "not ok 17\n";
145 print length $a == 198 ? "ok 18\n" : "not ok 18\n";
147 print length $a == 999 ? "ok 19\n" : "not ok 19\n";
148 substr($a, 0, 1) = '';
149 print length $a == 998 ? "ok 20\n" : "not ok 20\n";