@@ -1494,66 +1494,54 @@ private final class DataTests {
14941494 @Test func validateGeneralizedParameters_withUnsafeBytes( ) {
14951495 var data : Data
14961496
1497- do throws ( LocalError ) {
1498- data = Data ( repeating : 2 , count : 12 )
1499- let value = data . withUnsafeBytes {
1500- let sum = $0 . withMemoryRebound ( to : UInt8 . self ) { Int ( $0 . reduce ( 0 , + ) ) }
1501- return Value ( sum )
1502- }
1503- #expect( value . stored == 24 )
1497+ data = Data ( repeating : 2 , count : 12 )
1498+ let value = data. withUnsafeBytes {
1499+ let sum = $0 . withMemoryRebound ( to : UInt8 . self ) { Int ( $0 . reduce ( 0 , + ) ) }
1500+ return Value ( sum )
1501+ }
1502+ #expect ( value . stored == 24 )
1503+ #expect( throws : LocalError . error ) {
15041504 try data. withUnsafeBytes { _ throws ( LocalError) in throw ( LocalError . error) }
1505- Issue . record ( " Should be unreachable " )
1506- } catch {
1507- #expect( error == . error)
15081505 }
15091506
1510- do throws ( LocalError ) {
1511- data = Data ( repeating : 1 , count : 128 )
1512- let value = data . withUnsafeBytes {
1513- let sum = $0 . withMemoryRebound ( to : UInt8 . self ) { Int ( $0 . reduce ( 0 , + ) ) }
1514- return Value ( sum )
1515- }
1516- #expect( value . stored == 128 )
1507+ data = Data ( repeating : 1 , count : 128 )
1508+ let value = data. withUnsafeBytes {
1509+ let sum = $0 . withMemoryRebound ( to : UInt8 . self ) { Int ( $0 . reduce ( 0 , + ) ) }
1510+ return Value ( sum )
1511+ }
1512+ #expect ( value . stored == 128 )
1513+ #expect( throws : LocalError . error ) {
15171514 try data. withUnsafeBytes { _ throws ( LocalError) in throw ( LocalError . error) }
1518- Issue . record ( " Should be unreachable " )
1519- } catch {
1520- #expect( error == . error)
15211515 }
15221516 }
15231517
15241518 @Test func validateGeneralizedParameters_withUnsafeMutableBytes( ) {
15251519 var data : Data
15261520
1527- do throws ( LocalError) {
1528- data = Data ( count: 12 )
1529- let value = data. withUnsafeMutableBytes {
1530- $0. withMemoryRebound ( to: UInt8 . self) {
1531- for i in $0. indices { $0 [ i] = 2 }
1532- }
1533- let sum = $0. withMemoryRebound ( to: UInt8 . self) { Int ( $0. reduce ( 0 , + ) ) }
1534- return Value ( sum)
1521+ data = Data ( count: 12 )
1522+ let value = data. withUnsafeMutableBytes {
1523+ $0. withMemoryRebound ( to: UInt8 . self) {
1524+ for i in $0. indices { $0 [ i] = 2 }
15351525 }
1536- #expect( value. stored == 24 )
1526+ let sum = $0. withMemoryRebound ( to: UInt8 . self) { Int ( $0. reduce ( 0 , + ) ) }
1527+ return Value ( sum)
1528+ }
1529+ #expect( value. stored == 24 )
1530+ #expect( throws: LocalError . error) {
15371531 try data. withUnsafeBytes { _ throws ( LocalError) in throw ( LocalError . error) }
1538- Issue . record ( " Should be unreachable " )
1539- } catch {
1540- #expect( error == . error)
15411532 }
15421533
1543- do throws( LocalError) {
1544- data = Data ( count: 128 )
1545- let value = data. withUnsafeMutableBytes {
1546- $0. withMemoryRebound ( to: UInt8 . self) {
1547- for i in $0. indices { $0 [ i] = 1 }
1548- }
1549- let sum = $0. withMemoryRebound ( to: UInt8 . self) { Int ( $0. reduce ( 0 , + ) ) }
1550- return Value ( sum)
1534+ data = Data ( count: 128 )
1535+ let value = data. withUnsafeMutableBytes {
1536+ $0. withMemoryRebound ( to: UInt8 . self) {
1537+ for i in $0. indices { $0 [ i] = 1 }
15511538 }
1552- #expect( value. stored == 128 )
1539+ let sum = $0. withMemoryRebound ( to: UInt8 . self) { Int ( $0. reduce ( 0 , + ) ) }
1540+ return Value ( sum)
1541+ }
1542+ #expect( value. stored == 128 )
1543+ #expect( throws: LocalError . error) {
15531544 try data. withUnsafeBytes { _ throws ( LocalError) in throw ( LocalError . error) }
1554- Issue . record ( " Should be unreachable " )
1555- } catch {
1556- #expect( error == . error)
15571545 }
15581546 }
15591547
0 commit comments