@@ -496,31 +496,78 @@ suite.test("withUnsafeBytes()")
496496 }
497497}
498498
499- suite. test ( " isIdentical (to:)" )
499+ suite. test ( " isTriviallyIdentical (to:)" )
500500. skip ( . custom(
501501 { if #available( SwiftStdlib 6 . 2 , * ) { false } else { true } } ,
502502 reason: " Requires Swift 6.2's standard library "
503503) )
504504. code {
505505 guard #available( SwiftStdlib 6 . 2 , * ) else { return }
506506
507+ func checkTriviallyIdentical< T: BitwiseCopyable > (
508+ _ x: UnsafeMutableBufferPointer < T > ,
509+ _ y: UnsafeMutableBufferPointer < T > ,
510+ _ expected: Bool ,
511+ stackTrace: SourceLocStack = SourceLocStack ( ) ,
512+ showFrame: Bool = true ,
513+ file: String = #file,
514+ line: UInt = #line
515+ ) {
516+ let stackTrace = stackTrace. pushIf ( showFrame, file: file, line: line)
517+ do {
518+ expectEqual ( expected, x. isTriviallyIdentical ( to: y) , stackTrace: stackTrace)
519+ }
520+ do {
521+ let x = UnsafeBufferPointer < T > ( x)
522+ let y = UnsafeBufferPointer < T > ( y)
523+ expectEqual ( expected, x. isTriviallyIdentical ( to: y) , stackTrace: stackTrace)
524+ }
525+ do {
526+ let x = UnsafeRawBufferPointer ( x)
527+ let y = UnsafeRawBufferPointer ( y)
528+ expectEqual ( expected, x. isTriviallyIdentical ( to: y) , stackTrace: stackTrace)
529+ }
530+ do {
531+ let x = UnsafeMutableRawBufferPointer ( x)
532+ let y = UnsafeMutableRawBufferPointer ( y)
533+ expectEqual ( expected, x. isTriviallyIdentical ( to: y) , stackTrace: stackTrace)
534+ }
535+ do {
536+ let x : Span < T > = unsafe x. span
537+ let y : Span < T > = unsafe y. span
538+ expectEqual ( expected, x. isTriviallyIdentical ( to: y) , stackTrace: stackTrace)
539+ expectEqual ( expected, x. isIdentical ( to: y) , stackTrace: stackTrace)
540+ }
541+ do {
542+ let x : RawSpan = unsafe x. span . bytes
543+ let y : RawSpan = unsafe y. span . bytes
544+ expectEqual ( expected, x. isTriviallyIdentical ( to: y) , stackTrace: stackTrace)
545+ expectEqual ( expected, x. isIdentical ( to: y) , stackTrace: stackTrace)
546+ }
547+ }
548+
549+ let a = UnsafeMutableBufferPointer < Int > ( start: nil , count: 0 )
507550 let b = UnsafeMutableBufferPointer< Int> . allocate( capacity: 8 )
551+ let c = b. extracting ( ..< 6 ) // FIXME: (first: 6)
552+ let d = b. extracting ( 2 ... ) // FIXME: (last: 6)
553+ let e = c. extracting ( 2 ... ) // FIXME: (last: 4)
554+ let f = d. extracting ( ..< 4 ) // FIXME: (first: 4)
555+
508556 _ = b. initialize ( fromContentsOf: 0 ..< 8 )
509557 defer { b. deallocate ( ) }
510558
511- let span = Span ( _unsafeElements: b)
512- let pre = span. extracting ( first: 6 )
513- let suf = span. extracting ( last: 6 )
514-
515- expectFalse (
516- pre. isIdentical ( to: suf)
517- )
518- expectFalse (
519- pre. isIdentical ( to: span)
520- )
521- expectTrue (
522- pre. extracting ( last: 4 ) . isIdentical ( to: suf. extracting ( first: 4 ) )
523- )
559+ checkTriviallyIdentical ( a, a, true )
560+ checkTriviallyIdentical ( b, b, true )
561+ checkTriviallyIdentical ( c, c, true )
562+ checkTriviallyIdentical ( d, d, true )
563+ checkTriviallyIdentical ( e, e, true )
564+ checkTriviallyIdentical ( f, f, true )
565+
566+ checkTriviallyIdentical ( a, b, false )
567+ checkTriviallyIdentical ( b, c, false )
568+ checkTriviallyIdentical ( c, d, false )
569+ checkTriviallyIdentical ( d, e, false )
570+ checkTriviallyIdentical ( e, f, true )
524571}
525572
526573suite. test ( " indices(of:) " )
0 commit comments