4c929d8b8b
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.
55 lines
1.7 KiB
Swift
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
|
|
)
|
|
}
|
|
}
|