Suppress a few compilation warnings in pp_hot.c.
[p5sagit/p5-mst-13.2.git] / t / op / vec.t
CommitLineData
a687059c 1#!./perl
2
24aef97f 3print "1..31\n";
a687059c 4
210db7fc 5my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
6
a687059c 7print vec($foo,0,1) == 0 ? "ok 1\n" : "not ok 1\n";
8print length($foo) == 0 ? "ok 2\n" : "not ok 2\n";
9vec($foo,0,1) = 1;
10print length($foo) == 1 ? "ok 3\n" : "not ok 3\n";
a0ed51b3 11print unpack('C',$foo) == 1 ? "ok 4\n" : "not ok 4\n";
a687059c 12print vec($foo,0,1) == 1 ? "ok 5\n" : "not ok 5\n";
13
14print vec($foo,20,1) == 0 ? "ok 6\n" : "not ok 6\n";
15vec($foo,20,1) = 1;
16print vec($foo,20,1) == 1 ? "ok 7\n" : "not ok 7\n";
17print length($foo) == 3 ? "ok 8\n" : "not ok 8\n";
18print vec($foo,1,8) == 0 ? "ok 9\n" : "not ok 9\n";
19vec($foo,1,8) = 0xf1;
20print vec($foo,1,8) == 0xf1 ? "ok 10\n" : "not ok 10\n";
a0ed51b3 21print ((unpack('C',substr($foo,1,1)) & 255) == 0xf1 ? "ok 11\n" : "not ok 11\n");
a687059c 22print vec($foo,2,4) == 1 ? "ok 12\n" : "not ok 12\n";
23print vec($foo,3,4) == 15 ? "ok 13\n" : "not ok 13\n";
deb3007b 24vec($Vec, 0, 32) = 0xbaddacab;
25print $Vec eq "\xba\xdd\xac\xab" ? "ok 14\n" : "not ok 14\n";
26print vec($Vec, 0, 32) == 3135089835 ? "ok 15\n" : "not ok 15\n";
a687059c 27
4ebbc975 28# ensure vec() handles numericalness correctly
29$foo = $bar = $baz = 0;
30vec($foo = 0,0,1) = 1;
31vec($bar = 0,1,1) = 1;
32$baz = $foo | $bar;
33print $foo eq "1" && $foo == 1 ? "ok 16\n" : "not ok 16\n";
34print $bar eq "2" && $bar == 2 ? "ok 17\n" : "not ok 17\n";
35print "$foo $bar $baz" eq "1 2 3" ? "ok 18\n" : "not ok 18\n";
fe58ced6 36
37# error cases
38
39$x = eval { vec $foo, 0, 3 };
40print "not " if defined $x or $@ !~ /^Illegal number of bits in vec/;
41print "ok 19\n";
42$x = eval { vec $foo, 0, 0 };
43print "not " if defined $x or $@ !~ /^Illegal number of bits in vec/;
44print "ok 20\n";
45$x = eval { vec $foo, 0, -13 };
46print "not " if defined $x or $@ !~ /^Illegal number of bits in vec/;
47print "ok 21\n";
48$x = eval { vec($foo, -1, 4) = 2 };
ed9aa3b7 49print "not " if defined $x or $@ !~ /^Negative offset to vec in lvalue context/;
fe58ced6 50print "ok 22\n";
51print "not " if vec('abcd', 7, 8);
52print "ok 23\n";
246fae53 53
54# UTF8
55# N.B. currently curiously coded to circumvent bugs elswhere in UTF8 handling
56
57$foo = "\x{100}" . "\xff\xfe";
58$x = substr $foo, 1;
59print "not " if vec($x, 0, 8) != 255;
60print "ok 24\n";
61eval { vec($foo, 1, 8) };
33b45480 62print "not " if $@;
246fae53 63print "ok 25\n";
64eval { vec($foo, 1, 8) = 13 };
33b45480 65print "not " if $@;
246fae53 66print "ok 26\n";
210db7fc 67if ($Is_EBCDIC) {
68 print "not " if $foo ne "\x8c\x0d\xff\x8a\x69";
69 print "ok 27\n";
70}
71else {
72 print "not " if $foo ne "\xc4\x0d\xc3\xbf\xc3\xbe";
73 print "ok 27\n";
74}
33b45480 75$foo = "\x{100}" . "\xff\xfe";
246fae53 76$x = substr $foo, 1;
77vec($x, 2, 4) = 7;
78print "not " if $x ne "\xff\xf7";
79print "ok 28\n";
80
81# mixed magic
82
83$foo = "\x61\x62\x63\x64\x65\x66";
84print "not " if vec(substr($foo, 2, 2), 0, 16) != 25444;
85print "ok 29\n";
86vec(substr($foo, 1,3), 5, 4) = 3;
87print "not " if $foo ne "\x61\x62\x63\x34\x65\x66";
88print "ok 30\n";
24aef97f 89
90# A variation of [perl #20933]
91{
92 my $s = "";
93 vec($s, 0, 1) = 0;
94 vec($s, 1, 1) = 1;
95 my @r;
96 $r[$_] = \ vec $s, $_, 1 for (0, 1);
97 print "not " if (${ $r[0] } != 0 || ${ $r[1] } != 1);
98 print "ok 31\n";
99}