Skip to content

Commit 42337d3

Browse files
committed
[test] removeAll() from an empty OutputSpan
1 parent 8a77cba commit 42337d3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

test/stdlib/Span/OutputSpanTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ struct Allocation<T>: ~Copyable {
3535
_ body: (inout OutputSpan<T>) throws(E) -> Void
3636
) throws(E) {
3737
if count != nil { fatalError() }
38-
var outputBuffer = OutputSpan<T>(buffer: allocation, initializedCount: 0)
38+
var allocation = allocation
39+
if allocation.count == 0 { allocation = .init(start: nil, count: 0) }
40+
var outputBuffer = OutputSpan(buffer: allocation, initializedCount: 0)
3941
do {
4042
try body(&outputBuffer)
4143
let initialized = outputBuffer.finalize(for: allocation)
@@ -188,6 +190,20 @@ suite.test("deinitialize buffer")
188190
catch {
189191
expectTrue(false)
190192
}
193+
194+
a = Allocation(of: 0, Int.self)
195+
do {
196+
try a.initialize {
197+
expectEqual($0.freeCapacity, 0)
198+
throw MyTestError.error
199+
}
200+
}
201+
catch MyTestError.error {
202+
expectEqual(a.isEmpty, true)
203+
}
204+
catch {
205+
expectTrue(false)
206+
}
191207
}
192208

193209
suite.test("InlineArray initialization")

0 commit comments

Comments
 (0)