aboutsummaryrefslogtreecommitdiff
path: root/t/words.t
blob: 59387b72326a5c97ea33f9a119636b2ff8e55ca5 (plain)
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
#!perl -T

use strict;
use warnings;
use utf8;

use Test::More tests => 1;

use List::Breakdown 'breakdown';

our $VERSION = '0.20';

my @words   = qw(foo bar baz quux wibble florb);
my $filters = {
    all    => sub { 1 },
    has_b  => sub { m/ b /msx },
    has_w  => sub { m/ w /msx },
    length => {
        3    => sub { length == 3 },
        4    => sub { length == 4 },
        long => sub { length > 4 },
    },
    has_ba => qr/ba/msx,
};
my %filtered = breakdown $filters, @words;

my %expected = (
    all    => [qw(foo bar baz quux wibble florb)],
    has_b  => [qw(bar baz wibble florb)],
    has_w  => [qw(wibble)],
    length => {
        3    => [qw(foo bar baz)],
        4    => [qw(quux)],
        long => [qw(wibble florb)],
    },
    has_ba => [qw(bar baz)],
);

is_deeply( \%filtered, \%expected, 'words' );