Skip to content

Commit 0f8f721

Browse files
committed
Add Test Cases
1 parent d8f9a21 commit 0f8f721

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Tests/CodeEditTextViewTests/LayoutManager/TextLayoutManagerTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,26 @@ struct TextLayoutManagerTests {
228228
let invalidatedLineIds = layoutManager.layoutLines()
229229
#expect(Set(expectedLineIds) == invalidatedLineIds)
230230
}
231+
232+
@Test
233+
func rectForOffsetReturnsValueAfterEndOfDoc() throws {
234+
layoutManager.layoutLines(in: NSRect(x: 0, y: 0, width: 1000, height: 1000))
235+
236+
for idx in 0..<10 {
237+
// This should return something even after the end of the document.
238+
#expect(layoutManager.rectForOffset(idx) != nil, "Failed to find rect for offset: \(idx)")
239+
}
240+
}
241+
242+
@Test
243+
func textOffsetForPointReturnsValuesEverywhere() throws {
244+
layoutManager.layoutLines(in: NSRect(x: 0, y: 0, width: 1000, height: 1000))
245+
246+
// textOffsetAtPoint is valid *everywhere*. It should always return something.
247+
for xPos in 0..<1000 {
248+
for yPos in 0..<1000 {
249+
#expect(layoutManager.textOffsetAtPoint(CGPoint(x: xPos, y: yPos)) != nil)
250+
}
251+
}
252+
}
231253
}

Tests/CodeEditTextViewTests/TextSelectionManagerTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,10 @@ final class TextSelectionManagerTests: XCTestCase {
217217
)
218218
}
219219
}
220+
221+
func test_selectionEndOfDocumentHasXPos() {
222+
let selectionManager = selectionManager("1\n2\n3\n")
223+
selectionManager.setSelectedRange(NSRange(location: 6, length: 0)) // Beyond text.length, end of doc
224+
XCTAssertNotNil(selectionManager.textSelections.first?.suggestedXPos)
225+
}
220226
}

0 commit comments

Comments
 (0)