summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-22 21:58:17 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-22 21:58:17 -0400
commit749851eda39056fde2452dc1de1ed089221c5695 (patch)
tree8ea99e54c962211bc47577c880688f28b4ef0a74
parenta1fc3589640dccc9c8753882dbb0c95d609b77e9 (diff)
downloadparse-keyword-749851eda39056fde2452dc1de1ed089221c5695.tar.gz
parse-keyword-749851eda39056fde2452dc1de1ed089221c5695.zip
add test for injecting scopes
-rw-r--r--t/scope-inject.t48
1 files changed, 48 insertions, 0 deletions
diff --git a/t/scope-inject.t b/t/scope-inject.t
new file mode 100644
index 0000000..625896f
--- /dev/null
+++ b/t/scope-inject.t
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ if (!eval { require B::Hooks::EndOfScope }) {
+ plan skip_all => "B::Hooks::EndOfScope is required for this test";
+ }
+}
+
+BEGIN {
+ package My::Parser;
+ use Exporter 'import';
+ our @EXPORT = 'foo';
+ use Parse::Keyword { foo => \&parse_foo };
+
+ sub foo { $_[0]->() }
+ sub parse_foo {
+ lex_read_space;
+ die "syntax error" unless lex_peek eq '{';
+ lex_read;
+ lex_stuff(
+ '{'
+ . 'my $foo = 42;'
+ . '{'
+ . 'BEGIN { B::Hooks::EndOfScope::on_scope_end {'
+ . 'Parse::Keyword::lex_stuff(q[}])'
+ . '} }'
+ );
+ my $body = parse_block;
+ return sub { $body };
+ }
+
+ $INC{'My/Parser.pm'} = __FILE__;
+}
+
+use My::Parser;
+
+is(foo { $foo }, 42);
+{
+ my $warnings;
+ local $SIG{__WARN__} = sub { $warnings .= $_[0] };
+ is(foo { my $foo = 12; $foo }, 12);
+ is($warnings, undef);
+}
+
+done_testing;