@@ -33,6 +33,14 @@ import AppKit
33
33
#endif
34
34
#endif
35
35
36
+ func createManyAttributesString( ) -> AttributedString {
37
+ var str = AttributedString ( " a " )
38
+ for i in 0 ..< 10000 {
39
+ str += AttributedString ( " a " , attributes: AttributeContainer ( ) . testInt ( i) )
40
+ }
41
+ return str
42
+ }
43
+
36
44
/// Regression and coverage tests for `AttributedString` and its associated objects
37
45
@Suite ( " AttributedString " )
38
46
private struct AttributedStringTests {
@@ -360,6 +368,15 @@ private struct AttributedStringTests {
360
368
#expect( a2. characters. elementsEqual ( a3. characters) )
361
369
}
362
370
371
+ @Test func attributedStringIdentical( ) {
372
+ let manyAttributesString = createManyAttributesString ( )
373
+ let manyAttributesString2 = createManyAttributesString ( )
374
+ #expect( manyAttributesString. isIdentical ( to: manyAttributesString) )
375
+ #expect( manyAttributesString2. isIdentical ( to: manyAttributesString2) )
376
+ #expect( !( manyAttributesString. isIdentical ( to: manyAttributesString2) ) )
377
+ #expect( !( manyAttributesString2. isIdentical ( to: manyAttributesString) ) )
378
+ }
379
+
363
380
@Test func attributedSubstringEquality( ) {
364
381
let emptyStr = AttributedString ( " 01234567890123456789 " )
365
382
@@ -389,7 +406,19 @@ private struct AttributedStringTests {
389
406
390
407
#expect( emptyStr [ index0 ..< index5] == AttributedString ( " 01234 " ) )
391
408
}
392
-
409
+
410
+ @Test func attributedSubstringIdentical( ) {
411
+ let manyAttributesString = createManyAttributesString ( )
412
+ let manyAttributesString2 = createManyAttributesString ( )
413
+ let manyAttributesStringRange = manyAttributesString. characters. index ( manyAttributesString. startIndex, offsetBy: manyAttributesString. characters. count / 2 ) ...
414
+ let manyAttributesSubstring = manyAttributesString [ manyAttributesStringRange]
415
+ let manyAttributes2Substring = manyAttributesString2 [ manyAttributesStringRange]
416
+ #expect( manyAttributesSubstring. isIdentical ( to: manyAttributesSubstring) )
417
+ #expect( manyAttributes2Substring. isIdentical ( to: manyAttributes2Substring) )
418
+ #expect( !( manyAttributesSubstring. isIdentical ( to: manyAttributes2Substring) ) )
419
+ #expect( !( manyAttributes2Substring. isIdentical ( to: manyAttributesSubstring) ) )
420
+ }
421
+
393
422
@Test func runEquality( ) {
394
423
var attrStr = AttributedString ( " Hello " , attributes: AttributeContainer ( ) . testInt ( 1 ) )
395
424
attrStr += AttributedString ( " " )
0 commit comments