Files
OSGKeyboard/OSGKeyboardMacTests/MacTextInsertionServiceTests.swift
T
Rocky 4c929d8b8b fix(mac,asr): harden menu-bar delivery, chunk retry, and polish validator
Retain the external target app for menu-bar paste and polish context, retry
failed middle ASR chunks once, and stop false-positive path/number violations.
2026-07-29 18:30:36 +08:00

55 lines
1.7 KiB
Swift

// MacTextInsertionServiceTests.swift
// OSGKeyboard · Mac tests
//
// Regression coverage for clipboard preservation and captured-app context.
import AppKit
import XCTest
@testable import OSGKeyboard
final class MacTextInsertionServiceTests: XCTestCase {
func testRestoreRequiresTranscriptToStillOwnPasteboard() {
XCTAssertTrue(
MacTextInsertionService.shouldRestorePasteboard(
transcriptChangeCount: 12,
currentChangeCount: 12
)
)
XCTAssertFalse(
MacTextInsertionService.shouldRestorePasteboard(
transcriptChangeCount: 12,
currentChangeCount: 13
),
"A newer clipboard write must not be overwritten by restoration."
)
}
func testRestoringOriginallyEmptyPasteboardClearsTranscript() {
let pasteboard = NSPasteboard(
name: NSPasteboard.Name("MacTextInsertionServiceTests.\(UUID().uuidString)")
)
pasteboard.clearContents()
pasteboard.setString("transcript", forType: .string)
MacTextInsertionService.restoreItems([], to: pasteboard)
XCTAssertNil(pasteboard.string(forType: .string))
}
func testCapturedBundleIdentifierDrivesPolishContext() {
XCTAssertEqual(
MacAppContextService.detectContext(bundleIdentifier: "com.apple.dt.Xcode"),
.code
)
XCTAssertEqual(
MacAppContextService.detectContext(bundleIdentifier: "com.tencent.xinWeChat"),
.chat
)
XCTAssertEqual(
MacAppContextService.detectContext(bundleIdentifier: "com.osgkeyboard.mac"),
.unknown
)
}
}