Skip to content

Commit 6e17498

Browse files
committed
Add tests that exercise iteration API
1 parent 246ff1b commit 6e17498

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public enum UnderestimatedCountBehavior {
8383
///
8484
/// This sequence is consumed when its generator is advanced.
8585
public struct MinimalSequence<T> : Sequence, CustomDebugStringConvertible {
86+
public typealias Element = T
87+
8688
public init<S : Sequence>(
8789
elements: S,
8890
underestimatedCount: UnderestimatedCountBehavior = .value(0)

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,8 @@ public enum StdLibVersion: String {
22412241
case stdlib_6_0 = "6.0"
22422242
case stdlib_6_1 = "6.1"
22432243
case stdlib_6_2 = "6.2"
2244-
2244+
case stdlib_6_3 = "6.3"
2245+
22452246
var isAvailable: Bool {
22462247
switch self {
22472248
case .stdlib_5_7:
@@ -2258,6 +2259,8 @@ public enum StdLibVersion: String {
22582259
return if #available(SwiftStdlib 6.1, *) { true } else { false }
22592260
case .stdlib_6_2:
22602261
return if #available(SwiftStdlib 6.2, *) { true } else { false }
2262+
case .stdlib_6_3:
2263+
return if #available(SwiftStdlib 6.3, *) { true } else { false }
22612264
}
22622265
}
22632266
}

stdlib/public/StringProcessing/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(swift_string_processing_compile_flags)
2020
# will be built with library evolution.
2121
list(APPEND swift_string_processing_compile_flags
2222
"-DRESILIENT_LIBRARIES")
23+
list(APPEND swift_string_processing_compile_flags "-Xfrontend" "-disable-availability-checking")
2324

2425
if(SWIFT_BUILD_STATIC_STDLIB)
2526
# Explicitly autolink swift_RegexParser because it's imported with @_implementationOnly

test/stdlib/Span/SpanTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,35 @@ suite.test("Span Sendability")
607607
let span = Span(_unsafeElements: buffer)
608608
send(span)
609609
}
610+
611+
@available(SwiftStdlib 6.3, *)
612+
extension Sequence { // Copyable only
613+
func collectViaBorrowing() -> [Element] {
614+
var borrowIterator = makeBorrowingIterator()
615+
var result: [Element] = []
616+
while true {
617+
let span = borrowIterator.nextSpan(maximumCount: .max)
618+
if span.isEmpty { break }
619+
for i in span.indices {
620+
result.append(span[i])
621+
}
622+
}
623+
return result
624+
}
625+
}
626+
627+
suite.test("BORROWING")
628+
.require(.stdlib_6_3).code {
629+
guard #available(SwiftStdlib 6.3, *) else {
630+
expectTrue(false)
631+
return
632+
}
633+
634+
let array = [1, 2, 3, 4, 5, 6, 7, 8]
635+
let arrayCollected = array.collectViaBorrowing()
636+
expectEqual(array, arrayCollected)
637+
638+
let inline: [8 of Int] = [1, 2, 3, 4, 5, 6, 7, 8]
639+
let inlineCollected = inline.collectViaBorrowing()
640+
expectEqualSequence(inline, inlineCollected)
641+
}

0 commit comments

Comments
 (0)