Skip to content

Commit

Permalink
Fix assumption Str.ords.iterator always…
Browse files Browse the repository at this point in the history
…offers .count-only/.bool-only optimization methods.
  • Loading branch information
zoffixznet committed Feb 25, 2018
1 parent 4adee51 commit 95a7aca
Showing 1 changed file with 5 additions and 34 deletions.
39 changes: 5 additions & 34 deletions S32-str/ords.t
@@ -1,5 +1,7 @@
use v6;
use lib $?FILE.IO.parent(2).add: 'packages';
use Test;
use Test::Util;
plan 9;

# L<S32::Str/Str/ords>
Expand All @@ -18,7 +20,7 @@ is ".\x[301]".ords, (46, 769), 'ords does not lose NFG synthetics (method)';

# https://github.com/rakudo/rakudo/commit/8b7385d810
subtest 'optimization coverage' => {
plan 7;
plan 4;
my $s := "e\x[308]abc";
my @ords := 235, 97, 98, 99;

Expand All @@ -27,37 +29,6 @@ subtest 'optimization coverage' => {
is-deeply @target-s, [@ords], '.push-all (has chars)';
is-deeply @target-e, [], '.push-all (no chars)';

is-deeply +$s.ords, 4, '.count-only (has chars)';
is-deeply +"".ords, 0, '.count-only (no chars)';
is-deeply ?$s.ords, True, '.bool-only (has chars)';
is-deeply ?"".ords, False, '.bool-only (no chars)';

with $s.ords.iterator -> \iter {
subtest 'partially-iterated iterator' => {
plan 17;

is-deeply iter.count-only, 4, 'count (1)';
is-deeply iter.bool-only, True, 'bool (1)';

is-deeply iter.pull-one, @ords[0], 'char (2)';
is-deeply iter.count-only, 3, 'count (2)';
is-deeply iter.bool-only, True, 'bool (2)';

is-deeply iter.pull-one, @ords[1], 'char (3)';
is-deeply iter.count-only, 2, 'count (3)';
is-deeply iter.bool-only, True, 'bool (3)';

is-deeply iter.pull-one, @ords[2], 'char (4)';
is-deeply iter.count-only, 1, 'count (4)';
is-deeply iter.bool-only, True, 'bool (4)';

is-deeply iter.pull-one, @ords[3], 'char (5)';
is-deeply iter.count-only, 0, 'count (5)';
is-deeply iter.bool-only, False, 'bool (5)';

ok iter.pull-one =:= IterationEnd, 'char (6)';
is-deeply iter.count-only, 0, 'count (6)';
is-deeply iter.bool-only, False, 'bool (6)';
}
}
test-iter-opt $s.ords.iterator, @ords, 'has chars';
test-iter-opt "".ords.iterator, (), 'no chars';
}

0 comments on commit 95a7aca

Please sign in to comment.