File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
Sources/FoundationEssentials/AttributedString
Tests/FoundationEssentialsTests/AttributedString Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -594,9 +594,6 @@ extension AttributedString.Runs {
594
594
// _strBounds.range(containing:) below validates that i._value is within the bounds of this slice
595
595
precondition ( !attributeNames. isEmpty)
596
596
let r = _guts. findRun ( at: i. _value)
597
- if r. runIndex. offset == endIndex. _runOffset {
598
- return ( i, r. runIndex)
599
- }
600
597
let currentRange = _strBounds. range ( containing: i. _value) . range
601
598
602
599
guard constraints. count != 1 || constraints. contains ( nil ) else {
Original file line number Diff line number Diff line change @@ -1983,6 +1983,34 @@ E {
1983
1983
}
1984
1984
}
1985
1985
}
1986
+
1987
+ @Test func runSliceSubscripting( ) {
1988
+ var str = AttributedString ( " Foo " , attributes: . init( ) . testInt ( 1 ) )
1989
+ str += AttributedString ( " Bar " , attributes: . init( ) . testInt ( 2 ) )
1990
+ str += AttributedString ( " Baz " , attributes: . init( ) . testInt ( 3 ) )
1991
+
1992
+ do {
1993
+ let runsSlice = str. runs [ \. testInt]
1994
+ for (value, range) in runsSlice {
1995
+ for idx in str. utf8 [ range] . indices {
1996
+ let subscriptResult = runsSlice [ idx]
1997
+ #expect( subscriptResult. 0 == value, " Subscript index \( idx) did not produce same value as runs slice " )
1998
+ #expect( subscriptResult. 1 == range, " Subscript index \( idx) did not produce same range as runs slice " )
1999
+ }
2000
+ }
2001
+ }
2002
+
2003
+ do {
2004
+ let runsSlice = str [ str. index ( afterCharacter: str. startIndex) ..< str. index ( beforeCharacter: str. endIndex) ] . runs [ \. testInt]
2005
+ for (value, range) in runsSlice {
2006
+ for idx in str. utf8 [ range] . indices {
2007
+ let subscriptResult = runsSlice [ idx]
2008
+ #expect( subscriptResult. 0 == value, " Subscript index \( idx) did not produce same value as runs slice " )
2009
+ #expect( subscriptResult. 1 == range, " Subscript index \( idx) did not produce same range as runs slice " )
2010
+ }
2011
+ }
2012
+ }
2013
+ }
1986
2014
1987
2015
// MARK: - Other Tests
1988
2016
You can’t perform that action at this time.
0 commit comments