11 my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
14 is(length($foo), undef);
17 is(unpack('C',$foo), 1);
20 is(vec($foo,20,1), 0);
22 is(vec($foo,20,1), 1);
26 is(vec($foo,1,8), 0xf1);
27 is((unpack('C',substr($foo,1,1)) & 255), 0xf1);
28 is(vec($foo,2,4), 1);;
29 is(vec($foo,3,4), 15);
30 vec($Vec, 0, 32) = 0xbaddacab;
31 is($Vec, "\xba\xdd\xac\xab");
32 is(vec($Vec, 0, 32), 3135089835);
34 # ensure vec() handles numericalness correctly
35 $foo = $bar = $baz = 0;
36 vec($foo = 0,0,1) = 1;
37 vec($bar = 0,1,1) = 1;
39 ok($foo eq "1" && $foo == 1);
40 ok($bar eq "2" && $bar == 2);
41 ok("$foo $bar $baz" eq "1 2 3");
45 $x = eval { vec $foo, 0, 3 };
46 like($@, qr/^Illegal number of bits in vec/);
48 $x = eval { vec $foo, 0, 0 };
49 like($@, qr/^Illegal number of bits in vec/);
51 $x = eval { vec $foo, 0, -13 };
52 like($@, qr/^Illegal number of bits in vec/);
54 $x = eval { vec($foo, -1, 4) = 2 };
55 like($@, qr/^Negative offset to vec in lvalue context/);
57 ok(! vec('abcd', 7, 8));
60 # N.B. currently curiously coded to circumvent bugs elswhere in UTF8 handling
62 $foo = "\x{100}" . "\xff\xfe";
64 is(vec($x, 0, 8), 255);
66 eval { vec($foo, 1, 8) };
69 eval { vec($foo, 1, 8) = 13 };
72 is($foo, "\x8c\x0d\xff\x8a\x69");
75 is($foo, "\xc4\x0d\xc3\xbf\xc3\xbe");
77 $foo = "\x{100}" . "\xff\xfe";
84 $foo = "\x61\x62\x63\x64\x65\x66";
85 is(vec(substr($foo, 2, 2), 0, 16), 25444);
86 vec(substr($foo, 1,3), 5, 4) = 3;
87 is($foo, "\x61\x62\x63\x34\x65\x66");
89 # A variation of [perl #20933]
95 $r[$_] = \ vec $s, $_, 1 for (0, 1);
96 ok(!(${ $r[0] } != 0 || ${ $r[1] } != 1));
101 { package Class; DESTROY { ++$destroyed; } }
107 $x = bless({}, 'Class');
109 is($destroyed, 1, 'Timely scalar destruction with lvalue vec');
111 use constant roref => \1;
112 eval { for (roref) { vec($_,0,1) = 1 } };
113 like($@, qr/^Modification of a read-only value attempted at /,
114 'err msg when modifying read-only refs');
118 # downgradeable utf8 strings should be downgraded before accessing
120 # See the p5p thread with Message-ID:
121 # <CAMx+QJ6SAv05nmpnc7bmp0Wo+sjcx=ssxCcE-P_PZ8HDuCQd9A@mail.gmail.com>
124 my $x = substr "\x{100}\xff\xfe", 1; # a utf8 string with all ords < 256
127 is($v, 255, "downgraded utf8 try 1");
129 is($v, 255, "downgraded utf8 try 2");