Skip to content

Commit 9ed87ab

Browse files
committed
compile out MutableSpan mutations when unsupported by deployment target
1 parent 9913bdd commit 9ed87ab

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,7 @@ class DataTests : XCTestCase {
16831683
func test_InlineDataMutableSpan() throws {
16841684
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
16851685

1686+
#if !canImport(Darwin) || FOUNDATION_FRAMEWORK
16861687
#if compiler(>=6.2) && $InoutLifetimeDependence && $LifetimeDependenceMutableAccessors
16871688
var source = Data()
16881689
var span = source.mutableSpan
@@ -1696,21 +1697,27 @@ class DataTests : XCTestCase {
16961697
XCTAssertEqual(span.count, count)
16971698
let v = UInt8.random(in: 10..<100)
16981699
span[i] = v
1700+
var sub = span.extracting(i ..< i+1)
1701+
sub.update(repeating: v)
16991702
XCTAssertEqual(source[i], v)
1703+
#endif
17001704
#endif
17011705
}
17021706

17031707
func test_InlineSliceDataMutableSpan() throws {
17041708
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
17051709

1710+
#if !canImport(Darwin) || FOUNDATION_FRAMEWORK
17061711
#if compiler(>=6.2) && $InoutLifetimeDependence && $LifetimeDependenceMutableAccessors
17071712
var source = Data(0..<100)
17081713
let count = source.count
17091714
var span = source.mutableSpan
17101715
XCTAssertEqual(span.count, count)
17111716
let i = try XCTUnwrap(span.indices.randomElement())
1712-
span[i] = .max
1717+
var sub = span.extracting(i..<i+1)
1718+
sub.update(repeating: .max)
17131719
XCTAssertEqual(source[i], .max)
1720+
#endif
17141721
#endif
17151722
}
17161723

@@ -1725,6 +1732,7 @@ class DataTests : XCTestCase {
17251732
#error("This test needs updating")
17261733
#endif
17271734

1735+
#if !canImport(Darwin) || FOUNDATION_FRAMEWORK
17281736
#if compiler(>=6.2) && $InoutLifetimeDependence && $LifetimeDependenceMutableAccessors
17291737
var source = Data(repeating: 0, count: count).dropFirst()
17301738
XCTAssertNotEqual(source.startIndex, 0)
@@ -1735,6 +1743,7 @@ class DataTests : XCTestCase {
17351743
span[i] = .max
17361744
XCTAssertEqual(source[i], 0)
17371745
XCTAssertEqual(source[i+1], .max)
1746+
#endif
17381747
#endif
17391748
}
17401749

@@ -1753,7 +1762,8 @@ class DataTests : XCTestCase {
17531762
XCTAssertFalse(span.isEmpty)
17541763
XCTAssertEqual(span.byteCount, count)
17551764
let v = UInt8.random(in: 10..<100)
1756-
span.storeBytes(of: v, toByteOffset: i, as: UInt8.self)
1765+
var sub = span.extracting(i..<i+1)
1766+
sub.storeBytes(of: v, as: UInt8.self)
17571767
XCTAssertEqual(source[i], v)
17581768
#endif
17591769
}

0 commit comments

Comments
 (0)