Drop bad Iterable tests

This commit is contained in:
Karoy Lorentey committed 2026-09-22 19:19:20 -07:00
1 parent e2c040bcaa
commit 3cd6ca91d5
2 files changed
+5 -95

No files matched your search

@@ -1,90 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
import XCTest
#if COLLECTIONS_SINGLE_MODULE
import Collections
#else
import _CollectionsTestSupport
import ContainersPreview
#endif
#if compiler(>=6.4) && UnstableContainersPreview
final class IterableTests: XCTestCase {
@available(SwiftStdlib 6.4, *)
func testBasic() {
let array = [1, 2, 3, 4, 5, 6, 7, 8]
let span = array.span
let spanCollected = span.collectViaBorrowing()
XCTAssertTrue(span.elementsEqual(span))
XCTAssertTrue(span.elementsEqual(spanCollected))
XCTAssertTrue(spanCollected.elementsEqual(span))
// Array.elementsEqual is ambiguous:
// XCTAssertTrue(spanCollected.elementsEqual(spanCollected))
XCTAssertEqual(array.reduce(0, +), span.reduce(0, +))
XCTAssertEqual(array.reduce(into: 0, +=), span.reduce(into: 0, +=))
let inline: InlineArray = [1, 2, 3, 4, 5, 6, 7, 8]
let inlineCollected = inline.collectViaBorrowing()
XCTAssertTrue(inline.elementsEqual(inline))
XCTAssertTrue(inline.elementsEqual(inlineCollected))
XCTAssertTrue(inlineCollected.elementsEqual(inline))
// Array.elementsEqual is ambiguous:
// XCTAssertTrue(inlineCollected.elementsEqual(inlineCollected))
let nocopyInline: InlineArray = [
NoncopyableInt(value: 0),
NoncopyableInt(value: 1),
NoncopyableInt(value: 2),
NoncopyableInt(value: 3)
]
XCTAssertTrue(nocopyInline.elementsEqual(nocopyInline))
#if false // No BorrowingSequence conformance for UMBP yet...
let nocopyBuffer = UnsafeMutableBufferPointer<NoncopyableInt>.allocate(capacity: nocopyInline.count)
defer { nocopyBuffer.deallocate() }
for i in 0..<nocopyBuffer.count {
nocopyBuffer.initializeElement(at: i, to: NoncopyableInt(value: i))
}
#endif
}
}
@available(SwiftStdlib 6.4, *)
extension Iterable where Self: ~Copyable & ~Escapable, Element: Copyable {
func collectViaBorrowing() throws(Failure) -> [Element] {
var borrowIterator = makeBorrowingIterator()
var result: [Element] = []
while true {
let span = try borrowIterator.nextSpan(maxCount: .max)
if span.isEmpty { break }
for i in span.indices {
result.append(span[i])
}
}
return result
}
}
struct NoncopyableInt: ~Copyable, Equatable {
var value: Int
static func ==(lhs: borrowing Self, rhs: borrowing Self) -> Bool {
lhs.value == rhs.value
}
}
#endif
@@ -155,9 +155,9 @@ final class MutableSpanUpdateTests: CollectionTestCase {
let replacements1 = c ..< (c + subrange.count)
expected.replaceSubrange(subrange, with: replacements1)
var actual = tracker.instances(count: c, generator: { $0 })
let replacements2 = tracker.instances(
count: subrange.count, generator: { c + $0 })
var actual = RigidArray(copying: tracker.instances(count: c, generator: { $0 }))
let replacements2 = RigidArray(copying: tracker.instances(
count: subrange.count, generator: { c + $0 }))
var span = actual.mutableSpan
span._updateSubrange(subrange, copying: replacements2.span)
@@ -174,8 +174,8 @@ final class MutableSpanUpdateTests: CollectionTestCase {
withLifetimeTracking { tracker in
let expected = c ..< 2 * c
var actual = tracker.instances(count: c, generator: { $0 })
let replacements2 = tracker.instances(count: c, generator: { c + $0 })
var actual = RigidArray(copying: tracker.instances(count: c, generator: { $0 }))
let replacements2 = RigidArray(copying: tracker.instances(count: c, generator: { c + $0 }))
var span = actual.mutableSpan
span._updateAll(copying: replacements2.span)