5 my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
7 print vec($foo,0,1) == 0 ? "ok 1\n" : "not ok 1\n";
8 print length($foo) == 0 ? "ok 2\n" : "not ok 2\n";
10 print length($foo) == 1 ? "ok 3\n" : "not ok 3\n";
11 print unpack('C',$foo) == 1 ? "ok 4\n" : "not ok 4\n";
12 print vec($foo,0,1) == 1 ? "ok 5\n" : "not ok 5\n";
14 print vec($foo,20,1) == 0 ? "ok 6\n" : "not ok 6\n";
16 print vec($foo,20,1) == 1 ? "ok 7\n" : "not ok 7\n";
17 print length($foo) == 3 ? "ok 8\n" : "not ok 8\n";
18 print vec($foo,1,8) == 0 ? "ok 9\n" : "not ok 9\n";
20 print vec($foo,1,8) == 0xf1 ? "ok 10\n" : "not ok 10\n";
21 print ((unpack('C',substr($foo,1,1)) & 255) == 0xf1 ? "ok 11\n" : "not ok 11\n");
22 print vec($foo,2,4) == 1 ? "ok 12\n" : "not ok 12\n";
23 print vec($foo,3,4) == 15 ? "ok 13\n" : "not ok 13\n";
24 vec($Vec, 0, 32) = 0xbaddacab;
25 print $Vec eq "\xba\xdd\xac\xab" ? "ok 14\n" : "not ok 14\n";
26 print vec($Vec, 0, 32) == 3135089835 ? "ok 15\n" : "not ok 15\n";
28 # ensure vec() handles numericalness correctly
29 $foo = $bar = $baz = 0;
30 vec($foo = 0,0,1) = 1;
31 vec($bar = 0,1,1) = 1;
33 print $foo eq "1" && $foo == 1 ? "ok 16\n" : "not ok 16\n";
34 print $bar eq "2" && $bar == 2 ? "ok 17\n" : "not ok 17\n";
35 print "$foo $bar $baz" eq "1 2 3" ? "ok 18\n" : "not ok 18\n";
39 $x = eval { vec $foo, 0, 3 };
40 print "not " if defined $x or $@ !~ /^Illegal number of bits in vec/;
42 $x = eval { vec $foo, 0, 0 };
43 print "not " if defined $x or $@ !~ /^Illegal number of bits in vec/;
45 $x = eval { vec $foo, 0, -13 };
46 print "not " if defined $x or $@ !~ /^Illegal number of bits in vec/;
48 $x = eval { vec($foo, -1, 4) = 2 };
49 print "not " if defined $x or $@ !~ /^Negative offset to vec in lvalue context/;
51 print "not " if vec('abcd', 7, 8);
55 # N.B. currently curiously coded to circumvent bugs elswhere in UTF8 handling
57 $foo = "\x{100}" . "\xff\xfe";
59 print "not " if vec($x, 0, 8) != 255;
61 eval { vec($foo, 1, 8) };
64 eval { vec($foo, 1, 8) = 13 };
68 print "not " if $foo ne "\x8c\x0d\xff\x8a\x69";
72 print "not " if $foo ne "\xc4\x0d\xc3\xbf\xc3\xbe";
75 $foo = "\x{100}" . "\xff\xfe";
78 print "not " if $x ne "\xff\xf7";
83 $foo = "\x61\x62\x63\x64\x65\x66";
84 print "not " if vec(substr($foo, 2, 2), 0, 16) != 25444;
86 vec(substr($foo, 1,3), 5, 4) = 3;
87 print "not " if $foo ne "\x61\x62\x63\x34\x65\x66";