File: 20ngrep.t

package info (click to toggle)
liblist-keywords-perl 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 192 kB
  • sloc: perl: 445; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;
use Test::Refcount;

use List::Keywords 'ngrep';

# 2-at-a-time
{
   is( [ngrep my ($k, $v) { } ()], [], 'ngrep empty in list context');
   is( scalar(ngrep my ($k, $v) { } ()), 0, 'ngrep empty in scalar context');

   my @values;
   is( [ngrep my ($k, $v) { @values = ($k, $v); length $k == 3 } ( one => 1, two => 2, three => 3 )],
       [one => 1, two => 2],
       'ngrep in list context' );
   is( \@values, [ three => 3 ], 'ngrep code block saw correct values' );

   is( scalar(ngrep my ($k, $v) { length $k == 3 } ( one => 1, two => 2, three => 3 )), 4,
       'ngrep in scalar context' );

   is( [ngrep my ($k, $v) { @values = ($k, $v) } ( one => 1, missing => )],
       [one => 1, missing => ],
       'ngrep with short list does not invent undef' );
   is( \@values, [ missing => undef ],
       'ngrep code block still saw missing value as undef' );
}

# stack discipline
{
   is( [1, (ngrep my ($x) { 1 } 2), 3], [1, 2, 3],
      'ngrep behaves correctly as list operator' );
}

done_testing;