@@ -508,6 +508,14 @@ class TestAttributedStringConstrainingBehavior: XCTestCase {
508508        result. characters. append ( contentsOf:  " ABC " ) 
509509        verify ( string:  result,  matches:  [ ( " Hello, world " ,  1 ,  2 ) ,  ( " ABC " ,  1 ,  nil ) ] ,  for:  \. testInt,  \. testCharacterDependent) 
510510
511+         result =  str
512+         result. characters. insert ( " A " ,  at:  result. startIndex) 
513+         verify ( string:  result,  matches:  [ ( " A " ,  1 ,  nil ) ,  ( " Hello, world " ,  1 ,  2 ) ] ,  for:  \. testInt,  \. testCharacterDependent) 
514+         
515+         result =  str
516+         result. characters. insert ( " A " ,  at:  result. index ( afterCharacter:  result. startIndex) ) 
517+         verify ( string:  result,  matches:  [ ( " HAello, world " ,  1 ,  nil ) ] ,  for:  \. testInt,  \. testCharacterDependent) 
518+         
511519        result =  str
512520        result. characters. removeSubrange ( result. index ( afterCharacter:  result. startIndex)  ..<  result. index ( beforeCharacter:  result. endIndex) ) 
513521        verify ( string:  result,  matches:  [ ( " Hd " ,  1 ,  nil ) ] ,  for:  \. testInt,  \. testCharacterDependent) 
@@ -566,5 +574,13 @@ class TestAttributedStringConstrainingBehavior: XCTestCase {
566574        result [ result. startIndex ..<  result. index ( afterCharacter:  result. startIndex) ]  =  replacement [ replacement. startIndex ..<  replacement. index ( afterCharacter:  str. startIndex) ] 
567575        verify ( string:  result,  matches:  [ ( " H " ,  nil ,  nil ,  " Hello " ) ,  ( " ello, world " ,  1 ,  nil ,  nil ) ] ,  for:  \. testInt,  \. testCharacterDependent,  \. testString) 
568576    } 
569- 
577+     
578+     func  testInvalidationCharacterInsertionBetweenRuns( )  { 
579+         var  str  =  AttributedString ( " Hello " ,  attributes:  . init( ) . testInt ( 1 ) . testCharacterDependent ( 2 ) ) 
580+         str +=  AttributedString ( " World " ,  attributes:  . init( ) . testInt ( 1 ) . testCharacterDependent ( 3 ) ) 
581+         
582+         // Inserting text between two runs should not invalidate text dependent attributes in either of the surrounding runs
583+         str. characters. insert ( " | " ,  at:  str. index ( str. startIndex,  offsetByCharacters:  5 ) ) 
584+         verify ( string:  str,  matches:  [ ( " Hello " ,  1 ,  2 ) ,  ( " | " ,  1 ,  nil ) ,  ( " World " ,  1 ,  3 ) ] ,  for:  \. testInt,  \. testCharacterDependent) 
585+     } 
570586} 
0 commit comments