X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScope-Context.git;a=blobdiff_plain;f=t%2F15-info.t;fp=t%2F15-info.t;h=8c01137155cf3f64089bf380a11511f0ecc9e0c3;hp=0000000000000000000000000000000000000000;hb=f4699824df48f41d756111418704fca0d6d4d89e;hpb=5b9348f0f624efc3e24b83a3fb731aaf1962968b diff --git a/t/15-info.t b/t/15-info.t new file mode 100644 index 0000000..8c01137 --- /dev/null +++ b/t/15-info.t @@ -0,0 +1,61 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 5 + 2 + 3 + 2; + +use Scope::Context; + +{ + package Scope::Context::TestA; + { + my $line = __LINE__; + package Scope::Context::TestB; + my $cxt = Scope::Context->new; + package Scope::Context::TestC; + ::is $cxt->package, 'Scope::Context::TestA'; + ::is $cxt->file, __FILE__; + ::is $cxt->line, $line; + ::is $cxt->sub_name, undef; + ::is $cxt->eval_text, undef; + } +} + +sub flurbz { + my $cxt = Scope::Context->new; + [ $cxt->sub_name, $cxt->sub_has_args ] +} + +{ + my $info = flurbz(); + is($info->[0], 'main::flurbz'); + is($info->[1], !!1); +} + +{ + { + is(Scope::Context->new->gimme, undef, 'gimme in void context'); + } + my $s = do { + is(Scope::Context->new->gimme, !!'', 'gimme in scalar context'); + }; + my @a = do { + is(Scope::Context->new->gimme, !!1, 'gimme in list context'); + } +} + +{ + my $src = <<' SRC'; + my $cxt = Scope::Context->new; + [ $cxt->eval_text, $cxt->is_require ]; + SRC + my $info = do { + local $@; + eval $src; + }; + my $eval_text = $info->[0]; + s/[\s;]*$//g for $eval_text, $src; + is $eval_text, $src, 'eval_text in eval'; + is $info->[1], !!'', 'is_require in eval'; +}