Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Transmogrified "uniq" tests to "squish"
  • Loading branch information
lizmat committed Jul 3, 2013
1 parent 9885e8d commit 98b0260
Showing 1 changed file with 20 additions and 47 deletions.
67 changes: 20 additions & 47 deletions S32-list/squish.t
Expand Up @@ -2,75 +2,48 @@ use v6;

use Test;

plan 14;
plan 9;

=begin description
This test tests the C<uniq> builtin.
See the thread "[S32::Containers] uniq" on p6l, too.
This test tests the C<squish> builtin.
=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>],
my @array = <a b b c d e f f a>;
is_deeply @array.squish, <a b c d e f a>.list.item,
"method form of squish works";
is_deeply squish(@array), <a b c d e f a>.list.item,
"subroutine form of squish works";
is_deeply @array .= squish, [<a b c d e f a>],
"inplace form of squish works";
is_deeply @array, [<a b c d e f a>],
"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';
is_deeply squish(Any,'a', 'b', 'b', 'c', 'd', 'e', 'f', 'f', 'a'),
(Any, <a b c d e f a>.list).list.item,
'slurpy subroutine form of squish 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
#?pugs todo 'bug'
#?niecza todo 'NYI'
{
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)";
is 42.squish, 42, ".squish can work on scalars";
is (42,).squish, 42, ".squish can work on one-elem arrays";
} #2

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

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

# vim: ft=perl6

0 comments on commit 98b0260

Please sign in to comment.