@@ -1669,23 +1669,6 @@ private final class DataTests {
16691669 #expect( span [ span. indices. last!] == . max)
16701670 }
16711671
1672- @available( FoundationSpan 6.2 , * )
1673- @Test func largeSliceDataSpan( ) throws {
1674- #if _pointerBitWidth(_64)
1675- let count = Int ( Int32 . max)
1676- #elseif _pointerBitWidth(_32)
1677- let count = Int ( Int16 . max)
1678- #else
1679- #error("This test needs updating")
1680- #endif
1681-
1682- let source = Data ( repeating: 0 , count: count) . dropFirst ( )
1683- #expect( source. startIndex != 0 )
1684- let span = source. span
1685- let isEmpty = span. isEmpty
1686- #expect( !isEmpty)
1687- }
1688-
16891672 @available( FoundationSpan 6.2 , * )
16901673 @Test func inlineDataMutableSpan( ) throws {
16911674#if !canImport(Darwin) || FOUNDATION_FRAMEWORK
@@ -1695,7 +1678,7 @@ private final class DataTests {
16951678 #expect( isEmpty)
16961679
16971680 source. append ( contentsOf: [ 1 , 2 , 3 ] )
1698- var count = source. count
1681+ let count = source. count
16991682 span = source. mutableSpan
17001683 let indices = span. indices
17011684 let i = try #require( indices. randomElement ( ) )
@@ -1724,29 +1707,6 @@ private final class DataTests {
17241707#endif
17251708 }
17261709
1727- @available( FoundationSpan 6.2 , * )
1728- @Test func largeSliceDataMutableSpan( ) throws {
1729- #if _pointerBitWidth(_64)
1730- var count = Int ( Int32 . max)
1731- #elseif _pointerBitWidth(_32)
1732- var count = Int ( Int16 . max)
1733- #else
1734- #error("This test needs updating")
1735- #endif
1736-
1737- #if !canImport(Darwin) || FOUNDATION_FRAMEWORK
1738- var source = Data ( repeating: 0 , count: count) . dropFirst ( )
1739- #expect( source. startIndex != 0 )
1740- count = source. count
1741- var span = source. mutableSpan
1742- #expect( span. count == count)
1743- let i = try #require( span. indices. dropFirst ( ) . randomElement ( ) )
1744- span [ i] = . max
1745- #expect( source [ i] == 0 )
1746- #expect( source [ i+ 1 ] == . max)
1747- #endif
1748- }
1749-
17501710 @available( FoundationSpan 6.2 , * )
17511711 @Test func inlineDataMutableRawSpan( ) throws {
17521712 var source = Data ( )
@@ -1781,28 +1741,6 @@ private final class DataTests {
17811741 #expect( source [ i] == . max)
17821742 }
17831743
1784- @available( FoundationSpan 6.2 , * )
1785- @Test func largeSliceDataMutableRawSpan( ) throws {
1786- #if _pointerBitWidth(_64)
1787- var count = Int ( Int32 . max)
1788- #elseif _pointerBitWidth(_32)
1789- var count = Int ( Int16 . max)
1790- #else
1791- #error("This test needs updating")
1792- #endif
1793-
1794- var source = Data ( repeating: 0 , count: count) . dropFirst ( )
1795- #expect( source. startIndex != 0 )
1796- count = source. count
1797- var span = source. mutableBytes
1798- let byteCount = span. byteCount
1799- #expect( byteCount == count)
1800- let i = try #require( span. byteOffsets. dropFirst ( ) . randomElement ( ) )
1801- span. storeBytes ( of: - 1 , toByteOffset: i, as: Int8 . self)
1802- #expect( source [ i] == 0 )
1803- #expect( source [ i+ 1 ] == . max)
1804- }
1805-
18061744 #if FOUNDATION_EXIT_TESTS
18071745 @Test func bounding_failure_subdata( ) async {
18081746 await #expect( processExitsWith: . failure) {
@@ -2443,3 +2381,72 @@ extension DataTests {
24432381 }
24442382}
24452383#endif
2384+
2385+ // These tests require allocating an extremely large amount of data and are serialized to prevent the test runner from using all available memory at once
2386+ @Suite( " Large Data Tests " , . serialized)
2387+ struct LargeDataTests {
2388+ @Test
2389+ @available ( FoundationSpan 6 . 2 , * )
2390+ func largeSliceDataSpan( ) throws {
2391+ #if _pointerBitWidth(_64)
2392+ let count = Int ( Int32 . max)
2393+ #elseif _pointerBitWidth(_32)
2394+ let count = Int ( Int16 . max)
2395+ #else
2396+ #error("This test needs updating")
2397+ #endif
2398+
2399+ let source = Data ( repeating: 0 , count: count) . dropFirst ( )
2400+ #expect( source. startIndex != 0 )
2401+ let span = source. span
2402+ let isEmpty = span. isEmpty
2403+ #expect( !isEmpty)
2404+ }
2405+
2406+ @Test
2407+ @available ( FoundationSpan 6 . 2 , * )
2408+ func largeSliceDataMutableSpan( ) throws {
2409+ #if _pointerBitWidth(_64)
2410+ var count = Int ( Int32 . max)
2411+ #elseif _pointerBitWidth(_32)
2412+ var count = Int ( Int16 . max)
2413+ #else
2414+ #error("This test needs updating")
2415+ #endif
2416+
2417+ #if !canImport(Darwin) || FOUNDATION_FRAMEWORK
2418+ var source = Data ( repeating: 0 , count: count) . dropFirst ( )
2419+ #expect( source. startIndex != 0 )
2420+ count = source. count
2421+ var span = source. mutableSpan
2422+ #expect( span. count == count)
2423+ let i = try #require( span. indices. dropFirst ( ) . randomElement ( ) )
2424+ span [ i] = . max
2425+ #expect( source [ i] == 0 )
2426+ #expect( source [ i+ 1 ] == . max)
2427+ #endif
2428+ }
2429+
2430+ @Test
2431+ @available ( FoundationSpan 6 . 2 , * )
2432+ func largeSliceDataMutableRawSpan( ) throws {
2433+ #if _pointerBitWidth(_64)
2434+ var count = Int ( Int32 . max)
2435+ #elseif _pointerBitWidth(_32)
2436+ var count = Int ( Int16 . max)
2437+ #else
2438+ #error("This test needs updating")
2439+ #endif
2440+
2441+ var source = Data ( repeating: 0 , count: count) . dropFirst ( )
2442+ #expect( source. startIndex != 0 )
2443+ count = source. count
2444+ var span = source. mutableBytes
2445+ let byteCount = span. byteCount
2446+ #expect( byteCount == count)
2447+ let i = try #require( span. byteOffsets. dropFirst ( ) . randomElement ( ) )
2448+ span. storeBytes ( of: - 1 , toByteOffset: i, as: Int8 . self)
2449+ #expect( source [ i] == 0 )
2450+ #expect( source [ i+ 1 ] == . max)
2451+ }
2452+ }
0 commit comments