Skip to content

Commit

Permalink
Copy of "uniq" tests for "squish"
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 3, 2013
1 parent abe3272 commit 9885e8d
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions S32-list/squish.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use v6;

use Test;

plan 14;

=begin description
This test tests the C<uniq> builtin.
See the thread "[S32::Containers] uniq" on p6l, too.
=end description

{
my @array = <a b b c d e b b b b f b>;
is_deeply @array.uniq, <a b c d e f>.list.item,
"method form of uniq works";
is_deeply uniq(@array), <a b c d e f>.list.item,
"subroutine form of uniq works";
is_deeply @array .= uniq, [<a b c d e f>],
"inplace form of uniq works";
is_deeply @array, [<a b c d e f>],
"final result of in place";
} #4

{
is_deeply uniq('a', 'b', 'b', 'c', 'd', 'e', 'b', 'b', 'b', 'b', 'f', 'b'),
<a b c d e f>.list.item,
'slurpy subroutine form of uniq works';
} #1

# With a userspecified criterion
#?rakudo skip "Not spec'd, and this seems unlikely to be how it will be spec'd"
#?pugs todo
{
my @array = <a b A c b d>;
# Semantics w/o junctions
is ~@array.uniq({ lc($^a) eq lc($^b) }), "a b c d",
"method form of uniq with own comparator works";
is ~uniq({ lc($^a) eq lc($^b) }, @array), "a b c d",
"subroutine form of uniq with own comparator works";

# Semantics w/ junctions
is eval('~@array.uniq({ lc $^a eq lc $^b }).values.sort'), "A b c d a b c d";
} #3

#?pugs todo 'bug'
{
is 42.uniq, 42, ".uniq can work on scalars";
is (42,).uniq, 42, ".uniq can work on one-elem arrays";
} #2

# http://irclog.perlgeek.de/perl6/2009-10-31#i_1669037
#?pugs todo
{
my $range = [1..4];
my @array = $range, $range.WHICH;
is @array.elems, 2, ".uniq does not use naive WHICH (1)";
is @array.uniq.elems, 2, ".uniq does not use naive WHICH (2)";
} #2

# RT #111360
{
my class A { method Str { '' } };
is (A.new, A.new).uniq.elems, 2, 'uniq has === semantics';
} #1

# RT #83454
{
my @list = 1, "1";
my @uniq = uniq(@list);
is @uniq, @list, "uniq has === semantics";
} #1

# vim: ft=perl6

0 comments on commit 9885e8d

Please sign in to comment.