9f308fadd2
Rotate AI idle suggestions with optional remote packs, move history/dictionary onto self-sizing Home preview cards, harden clipboard capture/prompting, and simplify keyboard chrome by dropping most liquid-glass shadows.
82 lines
2.9 KiB
Swift
82 lines
2.9 KiB
Swift
// ProgressiveDictationTranscriptAccumulatorTests.swift
|
|
// OSGKeyboardTests
|
|
|
|
import CoreMedia
|
|
import XCTest
|
|
@testable import OSGKeyboardShared
|
|
|
|
final class ProgressiveDictationTranscriptAccumulatorTests: XCTestCase {
|
|
|
|
private func range(start: Double, duration: Double = 30) -> CMTimeRange {
|
|
CMTimeRange(
|
|
start: CMTime(seconds: start, preferredTimescale: 600),
|
|
duration: CMTime(seconds: duration, preferredTimescale: 600)
|
|
)
|
|
}
|
|
|
|
func testCumulativePartialsWithinSameRangeUpdateSegment() {
|
|
var acc = ProgressiveDictationTranscriptAccumulator()
|
|
let r0 = range(start: 0)
|
|
|
|
XCTAssertEqual(acc.ingest(range: r0, text: "今天天气"), "今天天气")
|
|
XCTAssertEqual(acc.ingest(range: r0, text: "今天天气很好"), "今天天气很好")
|
|
XCTAssertEqual(acc.finalize(), "今天天气很好")
|
|
}
|
|
|
|
func testNewRangeAppendsInsteadOfReplacingEarlierSpeech() {
|
|
var acc = ProgressiveDictationTranscriptAccumulator()
|
|
let r0 = range(start: 0)
|
|
let r30 = range(start: 30)
|
|
|
|
_ = acc.ingest(range: r0, text: "前三十秒的内容")
|
|
_ = acc.ingest(range: r30, text: "后二十秒的内容")
|
|
|
|
XCTAssertEqual(acc.finalize(), "前三十秒的内容后二十秒的内容")
|
|
}
|
|
|
|
func testDuplicateEmissionIsSuppressed() {
|
|
var acc = ProgressiveDictationTranscriptAccumulator()
|
|
let r0 = range(start: 0)
|
|
|
|
XCTAssertNotNil(acc.ingest(range: r0, text: "hello"))
|
|
XCTAssertNil(acc.ingest(range: r0, text: "hello"))
|
|
}
|
|
|
|
func testPunctuationRevisionWithRangeDriftReplacesPriorSegment() {
|
|
var acc = ProgressiveDictationTranscriptAccumulator()
|
|
|
|
_ = acc.ingest(
|
|
range: range(start: 0.0, duration: 2.5),
|
|
text: "先这样用着就算目前的可用性"
|
|
)
|
|
_ = acc.ingest(
|
|
range: range(start: 0.25, duration: 2.5),
|
|
text: "先这样用着,就算目前的可用性已经"
|
|
)
|
|
_ = acc.ingest(
|
|
range: range(start: 2.8, duration: 2.5),
|
|
text: "提升很多了"
|
|
)
|
|
|
|
XCTAssertEqual(acc.finalize(), "先这样用着,就算目前的可用性已经提升很多了")
|
|
}
|
|
|
|
func testComposerDropsOverlappingSuffixAndPrefix() {
|
|
let composed = DictationTextComposer.compose(
|
|
anchor: "先这样用着,就算目前的可用性已经",
|
|
live: "可用性已经提升很多了"
|
|
)
|
|
|
|
XCTAssertEqual(composed, "先这样用着,就算目前的可用性已经提升很多了")
|
|
}
|
|
|
|
func testComposerMapsNormalizedOverlapThroughRawPunctuation() {
|
|
let composed = DictationTextComposer.compose(
|
|
anchor: "先这样用着,就算目前的可用性已经",
|
|
live: "可用性,已经提升很多了"
|
|
)
|
|
|
|
XCTAssertEqual(composed, "先这样用着,就算目前的可用性已经提升很多了")
|
|
}
|
|
}
|