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