Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added tests for :with for List.(uniq|squish)
  • Loading branch information
lizmat committed Aug 4, 2013
1 parent f22dd02 commit 0f0ea4c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
48 changes: 47 additions & 1 deletion S32-list/squish.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 14;
plan 26;

=begin description
Expand Down Expand Up @@ -74,4 +74,50 @@ This test tests the C<squish> builtin and .squish method on Any/List.
"final result with :as in place";
} #4

#?pugs skip 'NYI'
#?niecza skip 'NYI'
{
my @array = <a aa b bb c d e f f a>;
my $with = { substr($^a,0,1) eq substr($^b,0,1) }
is_deeply @array.squish(:$with), <a b c d e f a>.list.item,
"method form of squish with :with works";
is_deeply squish(@array,:$with), <a b c d e f a>.list.item,
"subroutine form of squish with :with works";
is_deeply @array .= squish(:$with), [<a b c d e f a>],
"inplace form of squish with :with works";
is_deeply @array, [<a b c d e f a>],
"final result with :with in place";
} #4

#?pugs skip 'NYI'
#?niecza skip 'NYI'
{
my @array = <a aa b bb c d e f f a>;
my $as = *.substr(0,1).ord;
my $with = &[==];
is_deeply @array.squish(:$as, :$with), <a b c d e f a>.list.item,
"method form of squish with :as and :with works";
is_deeply squish(@array,:$as, :$with), <a b c d e f a>.list.item,
"subroutine form of squish with :as and :with works";
is_deeply @array .= squish(:$as, :$with), [<a b c d e f a>],
"inplace form of squish with :as and :with works";
is_deeply @array, [<a b c d e f a>],
"final result with :as and :with in place";
} #4

#?pugs skip 'NYI'
#?niecza skip 'NYI'
{
my @array = ({:a<1>}, {:a<1>}, {:b<1>});
my $with = &[eqv];
is_deeply @array.squish(:$with), ({:a<1>}, {:b<1>}).list.item,
"method form of squish with [eqv] and objects works";
is_deeply squish(@array,:$with), ({:a<1>}, {:b<1>}).list.item,
"subroutine form of squish with [eqv] and objects works";
is_deeply @array .= squish(:$with), [{:a<1>}, {:b<1>}],
"inplace form of squish with [eqv] and objects works";
is_deeply @array, [{:a<1>}, {:b<1>}],
"final result with [eqv] and objects in place";
} #4

# vim: ft=perl6
48 changes: 47 additions & 1 deletion S32-list/uniq.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 18;
plan 30;

=begin description
Expand Down Expand Up @@ -88,4 +88,50 @@ See the thread "[S32::Containers] uniq" on p6l, too.
"final result with :as in place";
} #4

#?pugs skip 'NYI'
#?niecza skip 'NYI'
{
my @array = <a b bb c d e b bbbb b b f b>;
my $with = { substr($^a,0,1) eq substr($^b,0,1) }
is_deeply @array.uniq(:$with), <a b c d e f>.list.item,
"method form of uniq with :with works";
is_deeply uniq(@array,:$with), <a b c d e f>.list.item,
"subroutine form of uniq with :with works";
is_deeply @array .= uniq(:$with), [<a b c d e f>],
"inplace form of uniq with :with works";
is_deeply @array, [<a b c d e f>],
"final result with :with in place";
} #4

#?pugs skip 'NYI'
#?niecza skip 'NYI'
{
my @array = <a b bb c d e b bbbb b b f b>;
my $as = *.substr(0,1).ord;
my $with = &[==];
is_deeply @array.uniq(:$as), <a b c d e f>.list.item,
"method form of uniq with :as works";
is_deeply uniq(@array,:$as), <a b c d e f>.list.item,
"subroutine form of uniq with :as works";
is_deeply @array .= uniq(:$as), [<a b c d e f>],
"inplace form of uniq with :as works";
is_deeply @array, [<a b c d e f>],
"final result with :as in place";
} #4

#?pugs skip 'NYI'
#?niecza skip 'NYI'
{
my @array = ({:a<1>}, {:b<1>}, {:a<1>});
my $with = &[eqv];
is_deeply @array.uniq(:$with), ({:a<1>}, {:b<1>}).list.item,
"method form of uniq with [eqv] and objects works";
is_deeply uniq(@array,:$with), ({:a<1>}, {:b<1>}).list.item,
"subroutine form of uniq with [eqv] and objects works";
is_deeply @array .= uniq(:$with), [{:a<1>}, {:b<1>}],
"inplace form of uniq with [eqv] and objects works";
is_deeply @array, [{:a<1>}, {:b<1>}],
"final result with [eqv] and objects in place";
} #4

# vim: ft=perl6

0 comments on commit 0f0ea4c

Please sign in to comment.