@@ -138,7 +138,7 @@ struct TextLayoutManagerTests {
138138 ///
139139 /// Related implementation: ``TextLayoutManager/Iterator``
140140 @Test
141- func iteratorDoesNotSkipEmptyLines ( ) {
141+ func yPositionIteratorDoesNotSkipEmptyLines ( ) {
142142 // Layout manager keeps 1-length lines at the 2nd and 4th lines.
143143 textStorage. mutableString. setString ( " A \n \n B \n \n C " )
144144 layoutManager. layoutLines ( in: NSRect ( x: 0 , y: 0 , width: 1000 , height: 1000 ) )
@@ -158,4 +158,27 @@ struct TextLayoutManagerTests {
158158 lastLineIndex = lineIndex
159159 }
160160 }
161+
162+ /// See comment for `yPositionIteratorDoesNotSkipEmptyLines`.
163+ @Test
164+ func rangeIteratorDoesNotSkipEmptyLines( ) {
165+ // Layout manager keeps 1-length lines at the 2nd and 4th lines.
166+ textStorage. mutableString. setString ( " A \n \n B \n \n C " )
167+ layoutManager. layoutLines ( in: NSRect ( x: 0 , y: 0 , width: 1000 , height: 1000 ) )
168+
169+ var lineIndexes : [ Int ] = [ ]
170+ for line in layoutManager. linesInRange ( textView. documentRange) {
171+ lineIndexes. append ( line. index)
172+ }
173+
174+ var lastLineIndex : Int ?
175+ for lineIndex in lineIndexes {
176+ if let lastIndex = lastLineIndex {
177+ #expect( lineIndex - 1 == lastIndex, " Skipped an index when iterating. " )
178+ } else {
179+ #expect( lineIndex == 0 , " First index was not 0 " )
180+ }
181+ lastLineIndex = lineIndex
182+ }
183+ }
161184}
0 commit comments