Skip to content

Commit d86b59d

Browse files
committed
Add Range Iterator Tests
1 parent 1d09ede commit d86b59d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Tests/CodeEditTextViewTests/LayoutManager/TextLayoutManagerTests.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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\nB\n\nC")
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\nB\n\nC")
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

Comments
 (0)