This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deprecate above \xFF in bitwise string ops
[perl5.git] / t / op / evalbytes.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     require './test.pl';
6     set_up_inc('../lib');
7     require './charset_tools.pl';
8 }
9
10 plan(tests => 9);
11
12 {
13     local $SIG{__WARN__} = sub {};
14     eval "evalbytes 'foo'";
15     like $@, qr/syntax error/, 'evalbytes outside feature scope';
16 }
17
18 # We enable unicode_eval just to test that it does not interfere.
19 use feature 'evalbytes', 'unicode_eval';
20
21 is evalbytes("1+7"), 8, 'evalbytes basic sanity check';
22
23 my $code = qq('\xff\xfe');
24 is evalbytes($code), "\xff\xfe", 'evalbytes on extra-ASCII bytes';
25 chop((my $upcode = $code) .= chr 256);
26 is evalbytes($upcode), "\xff\xfe", 'evalbytes on upgraded extra-ASCII';
27 {
28     use utf8;
29     is evalbytes($code), "\xff\xfe", 'evalbytes ignores outer utf8 pragma';
30 }
31 my $U_100 = byte_utf8a_to_utf8n("\xc4\x80");
32 is evalbytes "use utf8; $U_100", chr 256, 'use utf8 within evalbytes';
33 chop($upcode = "use utf8; $U_100" . chr 256);
34 is evalbytes $upcode, chr 256, 'use utf8 within evalbytes on utf8 string';
35 eval { evalbytes chr 256 };
36 like $@, qr/Wide character/, 'evalbytes croaks on non-bytes';
37
38 eval 'evalbytes S';
39 ok 1, '[RT #129196] evalbytes S should not segfault';
40