M2: TranslationAdapter/AdapterRegistry with documented Hy-MT3 prompts and publisher sampling; all 102 languages with BCP-47 variants, RTL and dense-script flags; normalisation, NLLanguage detection, content classification and exact-join script-aware chunking; protected-token scanning and output validation; prompt policy with one documented fallback; shared TranslationPipeline with Core error mapping. The CLI now reports sourceLanguage and warning codes. M3: pure DoubleCopyDetector, 120 ms PasteboardWatcher with 750 ms own-write suppression, SystemPasteboard snapshot/restore and markers, CapturePolicy for the 4000/2000 limits, ServicesProvider and the menu-bar action. T3.5 (10-app manual matrix) remains intentionally open. Docs: ARCHITECTURE, TRANSLATION_OUTPUT, HYMT3_MODEL (§7 spike), SELECTION_AND_CLIPBOARD, PROGRESS; ADR-016 superseded by ADR-017/018. Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, package tests); live 7B CLI en→de/de→en/Markdown/JSON/placeholders; empty input exits 2 and unreachable exits 3.
79 lines
2.8 KiB
Swift
79 lines
2.8 KiB
Swift
import Foundation
|
|
import SprachmittlerCapture
|
|
import SprachmittlerTestSupport
|
|
import Testing
|
|
|
|
@Suite("Clipboard snapshot")
|
|
@MainActor
|
|
struct ClipboardSnapshotTests {
|
|
@Test func snapshotCapturesEveryItemAndType() throws {
|
|
let text = Data("Hello".utf8)
|
|
let rich = Data("rich".utf8)
|
|
let image = Data([0x01, 0x02, 0x03])
|
|
let pasteboard = FakePasteboard(
|
|
changeCount: 3,
|
|
text: "Hello",
|
|
items: [
|
|
ClipboardItemData(data: ["public.utf8-plain-text": text, "public.rtf": rich]),
|
|
ClipboardItemData(data: ["public.png": image]),
|
|
]
|
|
)
|
|
|
|
let snapshot = try #require(pasteboard.snapshot())
|
|
#expect(snapshot.changeCount == 3)
|
|
#expect(snapshot.items.count == 2)
|
|
#expect(snapshot.items[0].data["public.utf8-plain-text"] == text)
|
|
#expect(snapshot.items[0].data["public.rtf"] == rich)
|
|
#expect(snapshot.items[1].data["public.png"] == image)
|
|
}
|
|
|
|
@Test func restoreOnlyWhenChangeCountMatches() throws {
|
|
let text = Data("Hello".utf8)
|
|
let pasteboard = FakePasteboard(
|
|
changeCount: 3,
|
|
text: "Hello",
|
|
items: [ClipboardItemData(data: ["public.utf8-plain-text": text])]
|
|
)
|
|
let snapshot = try #require(pasteboard.snapshot())
|
|
#expect(pasteboard.restore(snapshot, onlyIfChangeCountMatches: 3))
|
|
#expect(pasteboard.text == "Hello")
|
|
#expect(!pasteboard.hasOwnWriteMarkers)
|
|
}
|
|
|
|
@Test func anotherAppChangingTheClipboardPreventsRestore() throws {
|
|
let text = Data("Hello".utf8)
|
|
let pasteboard = FakePasteboard(
|
|
changeCount: 3,
|
|
text: "Hello",
|
|
items: [ClipboardItemData(data: ["public.utf8-plain-text": text])]
|
|
)
|
|
let snapshot = try #require(pasteboard.snapshot())
|
|
|
|
pasteboard.simulateCopy("Other")
|
|
#expect(!pasteboard.restore(snapshot, onlyIfChangeCountMatches: 3))
|
|
#expect(pasteboard.text == "Other")
|
|
}
|
|
|
|
@Test func restoreFailureIsReported() throws {
|
|
let pasteboard = FakePasteboard(changeCount: 1, text: "Hello")
|
|
let snapshot = try #require(pasteboard.snapshot())
|
|
pasteboard.restoreSucceeds = false
|
|
#expect(!pasteboard.restore(snapshot, onlyIfChangeCountMatches: 1))
|
|
}
|
|
|
|
@Test func snapshotFailureReturnsNil() {
|
|
let pasteboard = FakePasteboard()
|
|
pasteboard.snapshotSucceeds = false
|
|
#expect(pasteboard.snapshot() == nil)
|
|
}
|
|
|
|
@Test func writeAddsOwnAndTransientMarkers() {
|
|
let pasteboard = FakePasteboard()
|
|
let newCount = pasteboard.write("Hallo")
|
|
#expect(newCount == 1)
|
|
#expect(pasteboard.text == "Hallo")
|
|
#expect(pasteboard.hasOwnWriteMarkers)
|
|
#expect(pasteboard.writtenTexts == ["Hallo"])
|
|
}
|
|
}
|