summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/t/op/length.t
blob: ceb005ecc4a8145c6da8fd868a3661ad731fd5a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!./perl

BEGIN {
    chdir 't' if -d 't';
    @INC = '../lib';
}

print "1..13\n";

print "not " unless length("")    == 0;
print "ok 1\n";

print "not " unless length("abc") == 3;
print "ok 2\n";

$_ = "foobar";
print "not " unless length()      == 6;
print "ok 3\n";

# Okay, so that wasn't very challenging.  Let's go Unicode.

{
    my $a = "\x{41}";

    print "not " unless length($a) == 1;
    print "ok 4\n";
    $test++;

    use bytes;
    print "not " unless $a eq "\x41" && length($a) == 1;
    print "ok 5\n";
    $test++;
}

{
    my $a = "\x{80}";
    
    print "not " unless length($a) == 1;
    print "ok 6\n";
    $test++;
    
    use bytes;
    print "not " unless $a eq "\xc2\x80" && length($a) == 2;
    print "ok 7\n";
    $test++;
}

{
    my $a = "\x{100}";
    
    print "not " unless length($a) == 1;
    print "ok 8\n";
    $test++;
    
    use bytes;
    print "not " unless $a eq "\xc4\x80" && length($a) == 2;
    print "ok 9\n";
    $test++;
}

{
    my $a = "\x{100}\x{80}";
    
    print "not " unless length($a) == 2;
    print "ok 10\n";
    $test++;
    
    use bytes;
    print "not " unless $a eq "\xc4\x80\xc2\x80" && length($a) == 4;
    print "ok 11\n";
    $test++;
}

{
    my $a = "\x{80}\x{100}";
    
    print "not " unless length($a) == 2;
    print "ok 12\n";
    $test++;
    
    use bytes;
    print "not " unless $a eq "\xc2\x80\xc4\x80" && length($a) == 4;
    print "ok 13\n";
    $test++;
}
OpenPOWER on IntegriCloud