]> git.vpit.fr Git - perl/modules/Sub-Nary.git/blobdiff - t/23-branch.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/Sub-Nary.git] / t / 23-branch.t
index 72451e40e80c45ecdff391facdcce0902df62e73..fef709dc1da61c42bddf566e42d0ca974b4c924e 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 17;
+use Test::More tests => 21 + ("$]" >= 5.010 ? 1 : 0);
 
 use Sub::Nary;
 
@@ -19,6 +19,19 @@ sub ret12 {
  }
 }
 
+sub ret12b {
+ if ($x) {
+  return 1
+ }
+ return 1, 2
+}
+
+sub ret12c {
+ if (@a) {
+  return 1, 2
+ }
+}
+
 sub ret1l { $x ? 1 : @_ }
 
 sub ret1234 {
@@ -27,11 +40,11 @@ sub ret1234 {
  } elsif ($h{foo}) {
   return 3, @a[4, 5];
  } elsif (@a) {
-  return @h{qw/a b c/}, $y
+  return @h{qw<a b c>}, $y
  }
 }
 
-sub retinif {
+sub retinif1 {
  if (return 1, 2) {
   return 1, 2, 3
  } else {
@@ -39,8 +52,16 @@ sub retinif {
  }
 }
 
+sub retinif2 {
+ if (do { return 2, 3 if $x }) {
+  return 4, 5, 6;
+ }
+}
+
 my @tests = (
  [ \&ret12,                    { 1 => 0.5, 2 => 0.5 } ],
+ [ \&ret12b,                   { 1 => 0.5, 2 => 0.5 } ],
+ [ \&ret12c,                   { 1 => 0.5, 2 => 0.5 } ],
  [ sub { 1, ret12 },           { 2 => 0.5, 3 => 0.5 } ],
  [ sub { 1, do { ret12, 3 } }, { 3 => 0.5, 4 => 0.5 } ],
  [ sub { @_[ret12()] },        { 1 => 0.5, 2 => 0.5 } ],
@@ -56,20 +77,23 @@ my @tests = (
  [ sub { $_[0], ret1l },        { 2 => 0.5, list => 0.5 } ],
  [ sub { ret1l, ret1l, ret1l }, { 3 => 0.125, list => 0.875 } ],
 
- [ \&ret1234, { map { $_ => 0.25 } 1 .. 4 } ],
-
- [ \&retinif, { 2 => 1 } ],
+ [ \&ret1234, { 2 => 0.5, 3 => 0.25, 4 => 0.125, 1 => 0.125 } ],
 
- [ sub { each %h }, { 0 => 0.5, 2 => 0.5 } ],
- [ sub { stat $0 }, { 0 => 0.5, 13 => 0.5 } ],
+ [ \&retinif1, { 2 => 1 } ],
+ [ \&retinif2, { 2 => 0.5, 3 => 0.25, 1 => 0.25 } ],
 
- [ sub { <*.*> }, { list => 1 / 3, 1 => 2 / 3 } ],
+ [ sub { $x || (3, 4) }, { 1 => 0.5, 2 => 0.5 } ],
+ [ sub { $x or (3, 4) }, { 1 => 0.5, 2 => 0.5 } ],
+ [ sub { $x &&  (3, 4) }, { 1 => 0.5, 2 => 0.5 } ],
+ [ sub { $x and (3, 4) }, { 1 => 0.5, 2 => 0.5 } ],
+ (([ eval 'sub { $x // (3, 4) }', { 1 => 0.5, 2 => 0.5 } ]) x ("$]" >= 5.010)),
 );
 
 my $i = 1;
 for (@tests) {
  my $r = $sn->nary($_->[0]);
- is_deeply($r, $_->[1], 'branch test ' . $i);
+ my $exp = ref $_->[1] ? $_->[1] : { $_->[1] => 1 };
+ is_deeply($r, $exp, 'branch test ' . $i);
  ++$i;
 }