Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
GLR-ify squish.t
  • Loading branch information
moritz committed Aug 26, 2015
1 parent a554c9f commit acb9760
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions S32-list/squish.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 37;
plan 38;

=begin description
Expand All @@ -13,9 +13,9 @@ This test tests the C<squish> builtin and .squish method on Any/List.
#?niecza skip 'NYI'
{
my @array = <a b b c d e f f a>;
is-deeply @array.squish, <a b c d e f a>.list.item,
is-deeply @array.squish.list, <a b c d e f a>,
"method form of squish works";
is-deeply squish(@array), <a b c d e f a>.list.item,
is-deeply squish(@array).list, <a b c d e f a>,
"subroutine form of squish works";
is-deeply @array .= squish, [<a b c d e f a>],
"inplace form of squish works";
Expand All @@ -24,8 +24,8 @@ This test tests the C<squish> builtin and .squish method on Any/List.
} #4

{
is-deeply squish(Any,'a', 'b', 'b', 'c', 'd', 'e', 'f', 'f', 'a'),
(Any, <a b c d e f a>.list).list.item,
is-deeply squish(Any,'a', 'b', 'b', 'c', 'd', 'e', 'f', 'f', 'a').list,
(flat Any, <a b c d e f a>),
'slurpy subroutine form of squish works';
} #1

Expand All @@ -50,17 +50,18 @@ This test tests the C<squish> builtin and .squish method on Any/List.

#?niecza skip 'NYI'
{
my @a := squish( 1..Inf );
is @a[3], 4, "make sure squish is lazy";
my \a := squish( 1..Inf );
ok a.is-lazy, 'squish knows itself to be lazy';
is a[3], 4, '... can access elements from lazy iterator';
} #1

#?niecza skip 'NYI'
{
my @array = <a b bb c d e f f a>;
my $as = *.substr: 0,1;
is-deeply @array.squish(:$as), <a b c d e f a>.list.item,
is-deeply @array.squish(:$as).list, <a b c d e f a>,
"method form of squish with :as works";
is-deeply squish(@array,:$as), <a b c d e f a>.list.item,
is-deeply squish(@array,:$as).list, <a b c d e f a>,
"subroutine form of squish with :as works";
is-deeply @array .= squish(:$as), [<a b c d e f a>],
"inplace form of squish with :as works";
Expand All @@ -72,14 +73,14 @@ This test tests the C<squish> builtin and .squish method on Any/List.
{
my @rt124204 = ('', '', Any, Any);
#?rakudo todo 'RT #124204'
is-deeply @rt124204.squish(:as(-> $x {$x})), ('', Any).list.item,
is-deeply @rt124204.squish(:as(-> $x {$x})).list, ('', Any),
"method form of squish with :as does not needlessly stringify";
is-deeply @rt124204.squish, ('', Any).list.item,
is-deeply @rt124204.squish.list, ('', Any),
"method form of squish without :as does not needlessly stringify";
#?rakudo todo 'RT #124204'
is-deeply @rt124204.squish(:as(-> $x {$x}), :with({$^b === $^a})), ('', Any).list.item,
is-deeply @rt124204.squish(:as(-> $x {$x}), :with({$^b === $^a})).list, ('', Any),
"method form of squish with :as and :with does not needlessly stringify";
is-deeply @rt124204.squish(:with({$^b === $^a})), ('', Any).list.item,
is-deeply @rt124204.squish(:with({$^b === $^a})).list, ('', Any),
"method form of squish with :with does not needlessly stringify";
} #4

Expand All @@ -88,19 +89,19 @@ This test tests the C<squish> builtin and .squish method on Any/List.
{
my @rt124205 = <a a>;

is-deeply @rt124205.squish(:as(-> $x {1}), :with(-> $a, $b {1})), <a>.list.item,
is-deeply @rt124205.squish(:as(-> $x {1}), :with(-> $a, $b {1})).list, <a>.list,
"method form of squish with :as and :with always returns at least the first element";
is-deeply @rt124205.squish(:with(-> $a, $b {1})), <a>.list.item,
is-deeply @rt124205.squish(:with(-> $a, $b {1})).list, <a>.list,
"method form of squish with :with always returns at least the first element";

# somewhat more real-world examples:

my @rt124205_b = '', '', <b b B B>;

is-deeply @rt124205_b.squish(:with(*.Str eq *.Str)), ('', 'b', 'B').list.item,
is-deeply @rt124205_b.squish(:with(*.Str eq *.Str)).list, ('', 'b', 'B'),
"method form of squish with :with preserves the first element even if it stringifies to ''";

is-deeply @rt124205_b.squish(:as(*.Str), :with(&infix:<eq>)), ('', 'b', 'B').list.item,
is-deeply @rt124205_b.squish(:as(*.Str), :with(&infix:<eq>)).list, ('', 'b', 'B'),
"method form of squish with :as and :with preserves the first element even if it stringifies to ''";

} #4
Expand All @@ -109,9 +110,9 @@ This test tests the C<squish> builtin and .squish method on Any/List.
{
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,
is-deeply @array.squish(:$with).list, <a b c d e f a>,
"method form of squish with :with works";
is-deeply squish(@array,:$with), <a b c d e f a>.list.item,
is-deeply squish(@array,:$with).list, <a b c d e f a>,
"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";
Expand All @@ -124,9 +125,9 @@ This test tests the C<squish> builtin and .squish method on Any/List.
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,
is-deeply @array.squish(:$as, :$with).list, <a b c d e f a>,
"method form of squish with :as and :with works";
is-deeply squish(@array,:$as, :$with), <a b c d e f a>.list.item,
is-deeply squish(@array,:$as, :$with).list, <a b c d e f a>,
"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";
Expand All @@ -138,9 +139,9 @@ This test tests the C<squish> builtin and .squish method on Any/List.
{
my @array = ({:a<1>}, {:a<1>}, {:b<1>});
my $with = &[eqv];
is-deeply @array.squish(:$with), ({:a<1>}, {:b<1>}).list.item,
is-deeply @array.squish(:$with).list, ({:a<1>}, {:b<1>}),
"method form of squish with [eqv] and objects works";
is-deeply squish(@array,:$with), ({:a<1>}, {:b<1>}).list.item,
is-deeply squish(@array,:$with).list, ({:a<1>}, {:b<1>}),
"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";
Expand All @@ -152,11 +153,11 @@ This test tests the C<squish> builtin and .squish method on Any/List.
{
my $a = <a b b c>;
$a .= squish;
is-deeply( $a, <a b c>.list.item, '.= squish in sink context works on $a' );
is-deeply( $a.list, <a b c>, '.= squish in sink context works on $a' );
my @a = <a b b c>;
@a .= squish;
is-deeply( @a, [<a b c>], '.= squish in sink context works on @a' );
} #2

is ((3,3,1),(1,2),(1,2)).squish, '3 3 1 1 2', ".squish doesn't flatten";
is ((3,3,1),(1,2),(1,2)).squish.list.Str, '3 3 1 1 2', ".squish doesn't flatten";
# vim: ft=perl6

0 comments on commit acb9760

Please sign in to comment.