From: Vincent Pit Date: Mon, 4 Aug 2008 21:56:55 +0000 (+0200) Subject: Add support and tests for eval { } X-Git-Tag: v0.02~17 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=da043a17ae41baa2154227a2689d31671f055165;p=perl%2Fmodules%2FSub-Nary.git Add support and tests for eval { } --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index f2b5343..c44a10e 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -279,7 +279,7 @@ sub expect_any { return ($self->expect_list($op))[0] => 1 if name($op) eq 'return'; - if (class($op) eq 'LOGOP') { + if (class($op) eq 'LOGOP' and not null $op->first) { my @res; my ($p, $r); diff --git a/t/20-return.t b/t/20-return.t index ac62ce5..a3eeed6 100644 --- a/t/20-return.t +++ b/t/20-return.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 47; use Sub::Nary; @@ -60,6 +60,14 @@ my @tests = ( [ sub { while (1) { return 1, 2 } }, 2 ], [ sub { while (1) { last; return 1, 2 } }, 2 ], [ sub { return 1, 2 while 1 }, 2 ], + + [ sub { eval { return } }, 0 ], + [ sub { eval { return 1, 2 } }, 2 ], + [ sub { eval { }; return $x, 2 }, 2 ], + [ sub { return eval { 1, $x }; }, 2 ], + [ sub { return 1, eval { $x, eval { $h{foo} } } }, 3 ], + [ sub { return eval { return $x, eval { $y } } }, 2 ], + [ sub { return eval { do { eval { @a } } } }, 'list' ], ); my $i = 1; diff --git a/t/21-list.t b/t/21-list.t index 71edefb..e5bbc40 100644 --- a/t/21-list.t +++ b/t/21-list.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 33; use Sub::Nary; @@ -50,6 +50,12 @@ my @tests = ( [ sub { while (1) { } }, 0 ], [ sub { while (1) { 1; } 1, 2 }, 2 ], + + [ sub { eval { } }, 0 ], + [ sub { eval { 1, 2 } }, 2 ], + [ sub { eval { }; $x, 2 }, 2 ], + [ sub { 1, eval { $x, eval { $h{foo} } } }, 3 ], + [ sub { eval { 1, do { eval { @a }, 2 } } }, 'list' ], ); my $i = 1;