54 lines
2.3 KiB
Swift
54 lines
2.3 KiB
Swift
import AppKit
|
|
import HelderCore
|
|
@testable import HelderUI
|
|
import Testing
|
|
|
|
@MainActor
|
|
@Suite struct DiffCanvasSelectionTests {
|
|
private func canvas() -> DiffCanvasView {
|
|
let view = DiffCanvasView(frame: NSRect(x: 0, y: 0, width: 800, height: 400))
|
|
view.load(rows: [
|
|
SplitRow(left: SideLine(no: 1, text: "old one"), right: SideLine(no: 1, text: "new one")),
|
|
SplitRow(left: nil, right: SideLine(no: 2, text: "added", mark: .added)),
|
|
SplitRow(left: SideLine(no: 2, text: "old two"), right: SideLine(no: 3, text: "new three")),
|
|
], language: nil, knownSymbols: [], scale: 1)
|
|
return view
|
|
}
|
|
|
|
private func mouse(_ type: NSEvent.EventType, row: Int, right: Bool) -> NSEvent {
|
|
let y = DiffOverlayLayout.topPadding + (CGFloat(row) + 0.5) * DiffOverlayLayout.rowHeight
|
|
return NSEvent.mouseEvent(with: type, location: NSPoint(x: right ? 600 : 200, y: y), modifierFlags: [],
|
|
timestamp: 0, windowNumber: 0, context: nil, eventNumber: 0, clickCount: 1, pressure: 1)!
|
|
}
|
|
|
|
@Test func draggingSelectsWholeLinesOnOneSide() {
|
|
let view = canvas()
|
|
view.mouseDown(with: mouse(.leftMouseDown, row: 0, right: true))
|
|
view.mouseDragged(with: mouse(.leftMouseDragged, row: 2, right: false))
|
|
#expect(view.selectedText == "new one\nadded\nnew three")
|
|
}
|
|
|
|
@Test func theOtherSidesBlankRowsAreSkipped() {
|
|
let view = canvas()
|
|
view.mouseDown(with: mouse(.leftMouseDown, row: 2, right: false))
|
|
view.mouseDragged(with: mouse(.leftMouseDragged, row: 0, right: false))
|
|
#expect(view.selectedText == "old one\nold two")
|
|
}
|
|
|
|
@Test func aClickWithoutADragSelectsNothing() {
|
|
let view = canvas()
|
|
view.mouseDown(with: mouse(.leftMouseDown, row: 1, right: true))
|
|
#expect(!view.hasSelection)
|
|
}
|
|
|
|
@Test func selectAllTakesTheSelectedSideElseTheOriginal() {
|
|
let view = canvas()
|
|
view.selectAll(nil)
|
|
#expect(view.selectedText == "old one\nold two")
|
|
view.mouseDown(with: mouse(.leftMouseDown, row: 0, right: true))
|
|
view.mouseDragged(with: mouse(.leftMouseDragged, row: 0, right: true))
|
|
view.selectAll(nil)
|
|
#expect(view.selectedText == "new one\nadded\nnew three")
|
|
}
|
|
}
|