1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8use List::UtilsBy qw( uniq_by );
9
10is_deeply( [ uniq_by { } ], [], 'empty list' );
11
12is_deeply( [ uniq_by { $_ } "a" ], [ "a" ], 'unit list' );
13
14is_deeply( [ uniq_by { my $ret = $_; undef $_; $ret } "a" ], [ "a" ], 'localises $_' );
15
16is_deeply( [ uniq_by { $_ } "a", "b" ], [ "a", "b" ], 'identity function no-op' );
17is_deeply( [ uniq_by { $_ } "b", "a" ], [ "b", "a" ], 'identity function on $_' );
18
19is_deeply( [ uniq_by { $_[0] } "b", "a" ], [ "b", "a" ], 'identity function on $_[0]' );
20
21is_deeply( [ uniq_by { length $_ } "a", "b", "cc", "dd", "eee" ], [ "a", "cc", "eee" ], 'length function' );
22
23done_testing;
24