Skip to content

Commit 9af775b

Browse files
author
Russ Bishop
committed
Use existing flatMapToOptionalTests dataset
1 parent b7329df commit 9af775b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/1_stdlib/Inputs/flatMap.gyb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,29 @@ ${Test}.test("flatMap/${Kind}/Lazy") {
6464
+ "once per element")
6565
% end
6666
}
67+
68+
for test in flatMapToOptionalTests {
69+
let s = ${Minimal}<OpaqueValue<Int>>(elements:
70+
test.sequence.map(OpaqueValue.init))
71+
let closureLifetimeTracker = LifetimeTracked(0)
72+
var timesClosureWasCalled = 0
73+
74+
var result = s.lazy.flatMap {
75+
(element: OpaqueValue<Int>) -> OpaqueValue<Int32>? in
76+
_blackHole(closureLifetimeTracker)
77+
timesClosureWasCalled += 1
78+
return test.transform(element.value).map(OpaqueValue.init)
79+
}
80+
expectEqual(0, timesClosureWasCalled, "unexpected eagerness")
81+
82+
let expected = test.expected.map(OpaqueValue.init)
83+
expectEqualSequence(
84+
expected, result,
85+
stackTrace: SourceLocStack().with(test.loc)
86+
) { $0.value == $1.value }
87+
expectEqual(
88+
test.sequence.count, timesClosureWasCalled,
89+
"iterating lazy flatMap() should call closure once per element")
90+
}
6791
}
6892
% end

0 commit comments

Comments
 (0)