Skip to content

Commit

Permalink
test: SimpleCachingIteratorAggregate inner loop traversals consume du…
Browse files Browse the repository at this point in the history
…plicated key values
  • Loading branch information
rela589n committed Jan 27, 2024
1 parent 1f66e86 commit d57e1b5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/unit/SimpleCachingIteratorAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,44 @@ public function testSecondTraversalEliminatesDuplicatedKeys(): void
], $secondIterationItems);
}

public function testInnerTraversalConsumesDuplicatedKeyValues(): void
{
$input = static function (): Generator {
yield 'a' => 1;
yield 'a' => 2;
yield 'a' => 3;
yield 'b' => 4;
yield 'b' => 5;
};

$iter = new SimpleCachingIteratorAggregate($input());

$outerItems = $innerItems = [];

foreach ($iter as $ko => $vo) {
if ($vo === 2) {
foreach ($iter as $ki => $vi) {
$innerItems[] = [$ki, $vi];
}
}

$outerItems[] = [$ko, $vo];
}

self::assertSame([
['a', 1],
['a', 2],
['b', 5],
], $outerItems);

self::assertSame([
['a', 2],
['a', 3],
['b', 4],
['b', 5],
], $innerItems);
}

public function testHasNext(): void
{
$range = range('a', 'c');
Expand Down

0 comments on commit d57e1b5

Please sign in to comment.