@@ -33,6 +33,14 @@ import AppKit
3333#endif
3434#endif
3535
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+
3644/// Regression and coverage tests for `AttributedString` and its associated objects
3745@Suite ( " AttributedString " )
3846private struct AttributedStringTests {
@@ -360,6 +368,15 @@ private struct AttributedStringTests {
360368 #expect( a2. characters. elementsEqual ( a3. characters) )
361369 }
362370
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+
363380 @Test func attributedSubstringEquality( ) {
364381 let emptyStr = AttributedString ( " 01234567890123456789 " )
365382
@@ -389,7 +406,19 @@ private struct AttributedStringTests {
389406
390407 #expect( emptyStr [ index0 ..< index5] == AttributedString ( " 01234 " ) )
391408 }
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+
393422 @Test func runEquality( ) {
394423 var attrStr = AttributedString ( " Hello " , attributes: AttributeContainer ( ) . testInt ( 1 ) )
395424 attrStr += AttributedString ( " " )
0 commit comments