This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
APItest: Add comprehensive UTF-8 validity tests
[perl5.git] / ext / XS-APItest / t / lexsub.t
CommitLineData
59f30b2e 1use Test::More tests => 5;
0be5d18d
FC
2use XS::APItest;
3
4
5sub fribbler { 2*shift }
6{
7 BEGIN { lexical_import fribbler => sub { 3*shift } }
8 is fribbler(15), 45, 'lexical subs via pad_add_name';
9}
10is fribbler(15), 30, 'XS-allocated lexical subs falling out of scope';
11
12{
13 BEGIN { lexical_import fribbler => sub { 3*shift } }
14 is fribbler(15), 45, 'lexical subs via pad_add_name';
15 no warnings;
16 use feature 'lexical_subs';
17 our sub fribbler;
18 is fribbler(15), 30, 'our sub overrides XS-registered lexical sub';
19}
59f30b2e
FC
20
21# With ‘use’ rather than explicit BEGIN:
22package Lexical::Exporter {
23 sub import { shift; ::lexical_import @_; return }
24}
25BEGIN { ++$INC{"Lexical/Exporter.pm"} }
26
27{
28 use Lexical::Exporter fribbler => sub { shift() . "foo" };
29 is fribbler("bar"), "barfoo";
30}