This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
anonsub.t: Improve test for [perl #71154]
[perl5.git] / t / op / evalbytes.t
CommitLineData
7d789282
FC
1#!./perl
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9plan(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.
18use feature 'evalbytes', 'unicode_eval';
19
20is evalbytes("1+7"), 8, 'evalbytes basic sanity check';
21
547ae129 22my $code = qq('\xff\xfe');
7d789282
FC
23is evalbytes($code), "\xff\xfe", 'evalbytes on extra-ASCII bytes';
24chop((my $upcode = $code) .= chr 256);
25is 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}
30is evalbytes "use utf8; '\xc4\x80'", chr 256, 'use utf8 within evalbytes';
31chop($upcode = "use utf8; '\xc4\x80'" . chr 256);
32is evalbytes $upcode, chr 256, 'use utf8 within evalbytes on utf8 string';
33eval { evalbytes chr 256 };
34like $@, qr/Wide character/, 'evalbytes croaks on non-bytes';