test: cover attachment-only rtfd image paste fallback
This commit is contained in:
parent
adcd0be0f7
commit
b7de225364
1 changed files with 53 additions and 0 deletions
|
|
@ -956,6 +956,59 @@ final class GhosttyPasteboardHelperTests: XCTestCase {
|
|||
XCTAssertTrue(imagePath.hasSuffix(".jpeg"))
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: imagePath))
|
||||
}
|
||||
|
||||
func testAttachmentOnlyRTFDClipboardFallsBackToImagePath() throws {
|
||||
let pasteboard = NSPasteboard(name: .init("cmux-test-rtfd-attachment-\(UUID().uuidString)"))
|
||||
pasteboard.clearContents()
|
||||
|
||||
let image = NSImage(size: NSSize(width: 1, height: 1))
|
||||
image.lockFocus()
|
||||
NSColor.orange.setFill()
|
||||
NSRect(x: 0, y: 0, width: 1, height: 1).fill()
|
||||
image.unlockFocus()
|
||||
|
||||
let attachment = NSTextAttachment()
|
||||
attachment.image = image
|
||||
let attributed = NSAttributedString(attachment: attachment)
|
||||
let data = try attributed.data(
|
||||
from: NSRange(location: 0, length: attributed.length),
|
||||
documentAttributes: [.documentType: NSAttributedString.DocumentType.rtfd]
|
||||
)
|
||||
pasteboard.setData(data, forType: .rtfd)
|
||||
|
||||
XCTAssertNil(cmuxPasteboardStringContentsForTesting(pasteboard))
|
||||
|
||||
let imagePath = try XCTUnwrap(cmuxPasteboardImagePathForTesting(pasteboard))
|
||||
defer { try? FileManager.default.removeItem(atPath: imagePath) }
|
||||
|
||||
XCTAssertTrue(imagePath.hasSuffix(".tiff"))
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: imagePath))
|
||||
}
|
||||
|
||||
func testRTFDClipboardWithVisibleTextPrefersText() throws {
|
||||
let pasteboard = NSPasteboard(name: .init("cmux-test-rtfd-text-\(UUID().uuidString)"))
|
||||
pasteboard.clearContents()
|
||||
|
||||
let image = NSImage(size: NSSize(width: 1, height: 1))
|
||||
image.lockFocus()
|
||||
NSColor.purple.setFill()
|
||||
NSRect(x: 0, y: 0, width: 1, height: 1).fill()
|
||||
image.unlockFocus()
|
||||
|
||||
let attachment = NSTextAttachment()
|
||||
attachment.image = image
|
||||
|
||||
let attributed = NSMutableAttributedString(string: "Hello ")
|
||||
attributed.append(NSAttributedString(attachment: attachment))
|
||||
let data = try attributed.data(
|
||||
from: NSRange(location: 0, length: attributed.length),
|
||||
documentAttributes: [.documentType: NSAttributedString.DocumentType.rtfd]
|
||||
)
|
||||
pasteboard.setData(data, forType: .rtfd)
|
||||
|
||||
XCTAssertEqual(cmuxPasteboardStringContentsForTesting(pasteboard), "Hello")
|
||||
XCTAssertNil(cmuxPasteboardImagePathForTesting(pasteboard))
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue