Files

38 lines
1.6 KiB
Swift

import AppKit
import Testing
@testable import Conjure
@Test @MainActor
func vimNormalCursorIsWideButInsertAndDisabledCursorsStayThin() throws {
_ = NSApplication.shared
let editor = NotesTextView(frame: NSRect(x: 0, y: 0, width: 100, height: 50))
editor.font = NotesAppearance.font
editor.drawsBackground = false
editor.setDocumentContents(NSAttributedString(string: "text"))
func paintedWidth() throws -> Int {
let bitmap = try #require(NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: 100, pixelsHigh: 50,
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false,
colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0))
let context = try #require(NSGraphicsContext(bitmapImageRep: bitmap))
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current = context
NSColor.clear.setFill()
NSRect(x: 0, y: 0, width: 100, height: 50).fill(using: .copy)
editor.drawInsertionPoint(in: NSRect(x: 10, y: 10, width: 1, height: 20), color: .orange, turnedOn: true)
context.flushGraphics()
NSGraphicsContext.restoreGraphicsState()
return (0..<100).filter { x in
(0..<50).contains { y in (bitmap.colorAt(x: x, y: y)?.alphaComponent ?? 0) > 0.1 }
}.count
}
let native = try paintedWidth()
editor.vimEnabled = true
let normal = try paintedWidth()
#expect(normal >= 8)
#expect(normal > native)
editor.vimState.mode = .insert
#expect(try paintedWidth() == native)
editor.vimEnabled = false
#expect(try paintedWidth() == native)
}