File: 80await%2Bmatchcase.t

package info (click to toggle)
libfuture-asyncawait-perl 0.70-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 528 kB
  • sloc: perl: 2,647; ansic: 118; pascal: 34; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,093 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

BEGIN {
   plan skip_all => "Future is not available"
      unless eval { require Future };
   plan skip_all => "Future::AsyncAwait >= 0.10 is not available"
      unless eval { require Future::AsyncAwait;
                    Future::AsyncAwait->VERSION( '0.10' ) };
   plan skip_all => "Syntax::Keyword::Match is not available"
      unless eval { require Syntax::Keyword::Match; };

   Future::AsyncAwait->import;
   Syntax::Keyword::Match->import;

   diag( "Future::AsyncAwait $Future::AsyncAwait::VERSION, " .
         "Syntax::Keyword::Match $Syntax::Keyword::Match::VERSION" );
}

# await in match/case
{
   async sub with_matchcase
   {
      my $f = shift;

      match( ref $f : eq ) {
         case( "Future" ) {
            await $f;
         }
         default {
            die "await case did not run";
         }
      }

      return "result";
   }

   my $f1 = Future->new;
   my $fret = with_matchcase( $f1 );

   $f1->done;
   is( scalar $fret->get, "result", '$fret for await in sswitch/case' );
}

done_testing;