Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from-loop tests #120

Merged
merged 4 commits into from
May 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion S32-list/seq.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 28;
plan 35;

my @result = 1,2,3;

Expand Down Expand Up @@ -126,3 +126,19 @@ is-deeply @searches[0].Array, @expected-searches, 'seq => array works 3';
throws-like { roundtripped.list }, X::Seq::Consumed,
'.perl on an iterated sequence faithfully reproduces such a sequence';
}

{
my $a = Seq.from-loop({ 1 });
isa-ok $a, Seq, 'from-loop(&body) returns a Seq';
ok $a.is-lazy, 'the Seq object is lazy';

$a = Seq.from-loop({ 1 }, { state $count = 0; $count++ < 10 });
isa-ok $a, Seq, 'from-loop(&body, &condition) returns a Seq';
is $a, (1) xx 10, 'from-loop(&body, &condition) terminates calling &body if &condition returns False';

my $count = 0;
$a = Seq.from-loop({ 1 }, { $count < 10 }, { $count++ });
isa-ok $a, Seq, 'from-loop(&body, &condition, &afterward) returns a Seq';
is $a, (1) xx 10, 'from-loop(&body, &condition, &afterward) terminates calling &body if &condition returns False';
is $count, 10, '&afterward is called after each call to &body.';
}