bd44b5aa08
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Has been cancelled
Test / build-libghostty-vt-macos (aarch64-ios) (push) Has been cancelled
Test / build-libghostty-vt-macos (aarch64-macos) (push) Has been cancelled
Test / build-libghostty-vt-macos (x86_64-macos) (push) Has been cancelled
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Has been cancelled
Test / build-dist (push) Has been cancelled
Test / GTK x11=true wayland=true (push) Has been cancelled
Test / Build -Dsimd=false (push) Has been cancelled
Test / Build -Dsimd=true (push) Has been cancelled
Test / Build -Dsentry=false (push) Has been cancelled
Test / Build -Dsentry=true (push) Has been cancelled
Test / zig-fmt (push) Has been cancelled
Test / GitHub Actions Pins (push) Has been cancelled
Test / prettier (push) Has been cancelled
Test / swiftlint (push) Has been cancelled
Test / alejandra (push) Has been cancelled
Test / typos (push) Has been cancelled
Nix / Required Checks: Nix (push) Has been cancelled
Nix / check-zig-cache-hash (push) Has been cancelled
Test / skip (push) Has been cancelled
Test / Required Checks: Test (push) Has been cancelled
Test / build-bench (push) Has been cancelled
Test / list-examples (push) Has been cancelled
Test / Example ${{ matrix.dir }} (Windows) (push) Has been cancelled
Test / build-cmake (push) Has been cancelled
Test / test-lib-vt-pkgconfig (push) Has been cancelled
Test / build-flatpak (push) Has been cancelled
Test / build-snap (push) Has been cancelled
Test / build-libghostty-vt (aarch64-linux) (push) Has been cancelled
Test / build-libghostty-vt (aarch64-macos) (push) Has been cancelled
Test / build-libghostty-vt (wasm32-freestanding) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-linux) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-linux-musl) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-macos) (push) Has been cancelled
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Has been cancelled
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Has been cancelled
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Has been cancelled
Test / build-libghostty-vt-windows (push) Has been cancelled
Test / build-libghostty-windows-gnu (push) Has been cancelled
Test / build-linux (namespace-profile-ghostty-md) (push) Has been cancelled
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Has been cancelled
Test / build-linux-libghostty (push) Has been cancelled
Test / build-nix (namespace-profile-ghostty-md) (push) Has been cancelled
Test / build-dist-lib-vt (push) Has been cancelled
Test / trigger-snap (push) Has been cancelled
Test / trigger-flatpak (push) Has been cancelled
Test / build-macos (push) Has been cancelled
Test / build-macos-freetype (push) Has been cancelled
Test / test (push) Has been cancelled
Test / test-lib-vt (push) Has been cancelled
Test / GTK x11=false wayland=false (push) Has been cancelled
Test / GTK x11=true wayland=false (push) Has been cancelled
Test / GTK x11=false wayland=true (push) Has been cancelled
Test / test-macos (push) Has been cancelled
Test / test-windows (push) Has been cancelled
Test / Build -Di18n=false (push) Has been cancelled
Test / Build -Di18n=true (push) Has been cancelled
Test / Build test/fuzz-libghostty (push) Has been cancelled
Test / shellcheck (push) Has been cancelled
Test / translations (push) Has been cancelled
Test / blueprint-compiler (push) Has been cancelled
Test / Test pkg/wuffs (push) Has been cancelled
Test / Test build on Debian 13 (push) Has been cancelled
Test / valgrind (push) Has been cancelled
Test / Example ${{ matrix.dir }} (push) Has been cancelled
125 lines
4.4 KiB
Swift
125 lines
4.4 KiB
Swift
import Testing
|
|
import AppKit
|
|
import CoreTransferable
|
|
import UniformTypeIdentifiers
|
|
@testable import Ghostty
|
|
|
|
struct TransferablePasteboardTests {
|
|
// MARK: - Test Helpers
|
|
|
|
/// A simple Transferable type for testing pasteboard conversion.
|
|
private struct DummyTransferable: Transferable, Equatable {
|
|
let payload: String
|
|
|
|
static var transferRepresentation: some TransferRepresentation {
|
|
DataRepresentation(contentType: .utf8PlainText) { value in
|
|
value.payload.data(using: .utf8)!
|
|
} importing: { data in
|
|
let string = String(data: data, encoding: .utf8)!
|
|
return DummyTransferable(payload: string)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A Transferable type that registers multiple content types.
|
|
private struct MultiTypeTransferable: Transferable {
|
|
let text: String
|
|
|
|
static var transferRepresentation: some TransferRepresentation {
|
|
DataRepresentation(contentType: .utf8PlainText) { value in
|
|
value.text.data(using: .utf8)!
|
|
} importing: { data in
|
|
MultiTypeTransferable(text: String(data: data, encoding: .utf8)!)
|
|
}
|
|
DataRepresentation(contentType: .plainText) { value in
|
|
value.text.data(using: .utf8)!
|
|
} importing: { data in
|
|
MultiTypeTransferable(text: String(data: data, encoding: .utf8)!)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Basic Functionality
|
|
|
|
@Test func pasteboardItemIsCreated() {
|
|
let transferable = DummyTransferable(payload: "hello")
|
|
let item = transferable.pasteboardItem()
|
|
#expect(item != nil)
|
|
}
|
|
|
|
@Test func pasteboardItemContainsExpectedType() {
|
|
let transferable = DummyTransferable(payload: "hello")
|
|
guard let item = transferable.pasteboardItem() else {
|
|
Issue.record("Expected pasteboard item to be created")
|
|
return
|
|
}
|
|
|
|
let expectedType = NSPasteboard.PasteboardType(UTType.utf8PlainText.identifier)
|
|
#expect(item.types.contains(expectedType))
|
|
}
|
|
|
|
@Test func pasteboardItemProvidesCorrectData() {
|
|
let transferable = DummyTransferable(payload: "test data")
|
|
guard let item = transferable.pasteboardItem() else {
|
|
Issue.record("Expected pasteboard item to be created")
|
|
return
|
|
}
|
|
|
|
let pasteboardType = NSPasteboard.PasteboardType(UTType.utf8PlainText.identifier)
|
|
|
|
// Write to a pasteboard to trigger data provider
|
|
let pasteboard = NSPasteboard(name: .init("test-\(UUID().uuidString)"))
|
|
pasteboard.clearContents()
|
|
pasteboard.writeObjects([item])
|
|
|
|
// Read back the data
|
|
guard let data = pasteboard.data(forType: pasteboardType) else {
|
|
Issue.record("Expected data to be available on pasteboard")
|
|
return
|
|
}
|
|
|
|
let string = String(data: data, encoding: .utf8)
|
|
#expect(string == "test data")
|
|
}
|
|
|
|
// MARK: - Multiple Content Types
|
|
|
|
@Test func multipleTypesAreRegistered() {
|
|
let transferable = MultiTypeTransferable(text: "multi")
|
|
guard let item = transferable.pasteboardItem() else {
|
|
Issue.record("Expected pasteboard item to be created")
|
|
return
|
|
}
|
|
|
|
let utf8Type = NSPasteboard.PasteboardType(UTType.utf8PlainText.identifier)
|
|
let plainType = NSPasteboard.PasteboardType(UTType.plainText.identifier)
|
|
|
|
#expect(item.types.contains(utf8Type))
|
|
#expect(item.types.contains(plainType))
|
|
}
|
|
|
|
@Test func multipleTypesProvideCorrectData() {
|
|
let transferable = MultiTypeTransferable(text: "shared content")
|
|
guard let item = transferable.pasteboardItem() else {
|
|
Issue.record("Expected pasteboard item to be created")
|
|
return
|
|
}
|
|
|
|
let pasteboard = NSPasteboard(name: .init("test-\(UUID().uuidString)"))
|
|
pasteboard.clearContents()
|
|
pasteboard.writeObjects([item])
|
|
|
|
// Both types should provide the same content
|
|
let utf8Type = NSPasteboard.PasteboardType(UTType.utf8PlainText.identifier)
|
|
let plainType = NSPasteboard.PasteboardType(UTType.plainText.identifier)
|
|
|
|
if let utf8Data = pasteboard.data(forType: utf8Type) {
|
|
#expect(String(data: utf8Data, encoding: .utf8) == "shared content")
|
|
}
|
|
|
|
if let plainData = pasteboard.data(forType: plainType) {
|
|
#expect(String(data: plainData, encoding: .utf8) == "shared content")
|
|
}
|
|
}
|
|
}
|