aec6a52871778d7f9421a86666b0089895f2fa7d
[p5sagit/p5-mst-13.2.git] / t / op / length.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7
8 print "1..13\n";
9
10 print "not " unless length("")    == 0;
11 print "ok 1\n";
12
13 print "not " unless length("abc") == 3;
14 print "ok 2\n";
15
16 $_ = "foobar";
17 print "not " unless length()      == 6;
18 print "ok 3\n";
19
20 # Okay, so that wasn't very challenging.  Let's go Unicode.
21
22 {
23     my $a = "\x{41}";
24
25     print "not " unless length($a) == 1;
26     print "ok 4\n";
27     $test++;
28
29     use bytes;
30     print "not " unless $a eq "\x41" && length($a) == 1;
31     print "ok 5\n";
32     $test++;
33 }
34
35 {
36     use utf8; # make "\x{80}" to produce UTF-8
37     my $a = "\x{80}";
38     
39     print "not " unless length($a) == 1;
40     print "ok 6\n";
41     $test++;
42     
43     use bytes;
44     print "not " unless $a eq "\xc2\x80" && length($a) == 2;
45     print "ok 7\n";
46     $test++;
47 }
48
49 {
50     my $a = "\x{100}";
51     
52     print "not " unless length($a) == 1;
53     print "ok 8\n";
54     $test++;
55     
56     use bytes;
57     print "not " unless $a eq "\xc4\x80" && length($a) == 2;
58     print "ok 9\n";
59     $test++;
60 }
61
62 {
63     my $a = "\x{100}\x{80}";
64     
65     print "not " unless length($a) == 2;
66     print "ok 10\n";
67     $test++;
68     
69     use bytes;
70     print "not " unless $a eq "\xc4\x80\xc2\x80" && length($a) == 4;
71     print "ok 11\n";
72     $test++;
73 }
74
75 {
76     my $a = "\x{80}\x{100}";
77     
78     print "not " unless length($a) == 2;
79     print "ok 12\n";
80     $test++;
81     
82     use bytes;
83     print "not " unless $a eq "\xc2\x80\xc4\x80" && length($a) == 4;
84     print "ok 13\n";
85     $test++;
86 }