d656bac8c3
Unify Bailian/Volcengine/OpenAI realtime streaming, ABE polish routing with fun styles, and a shared card-page Settings hierarchy; bump to 1.1 (build 32).
54 lines
2.0 KiB
Swift
54 lines
2.0 KiB
Swift
// UtteranceTranscriptStitcherTests.swift
|
|
// OSGKeyboardTests
|
|
|
|
import XCTest
|
|
@testable import OSGKeyboardShared
|
|
|
|
final class UtteranceTranscriptStitcherTests: XCTestCase {
|
|
|
|
func testMergeWithOverlapRemovesDuplicatedSuffixPrefix() {
|
|
let merged = UtteranceTranscriptStitcher.mergeWithOverlap(
|
|
previous: "今天天气很好",
|
|
next: "很好我们继续"
|
|
)
|
|
XCTAssertEqual(merged, "今天天气很好我们继续")
|
|
}
|
|
|
|
func testStitcherOrdersChunksByIndex() {
|
|
var stitcher = UtteranceTranscriptStitcher()
|
|
stitcher.append(index: 1, text: "第二段")
|
|
stitcher.append(index: 0, text: "第一段")
|
|
XCTAssertEqual(stitcher.composed(), "第一段 第二段")
|
|
}
|
|
|
|
func testComposedSafelyFallsBackWhenOverlapMergeShortensTooMuch() {
|
|
var stitcher = UtteranceTranscriptStitcher()
|
|
stitcher.append(index: 0, text: "今天天气很好我们")
|
|
stitcher.append(index: 1, text: "去公园")
|
|
let merged = stitcher.composed()
|
|
let safe = stitcher.composedSafely()
|
|
XCTAssertFalse(merged.isEmpty)
|
|
XCTAssertFalse(safe.isEmpty)
|
|
XCTAssertTrue(safe.contains("去公园"))
|
|
}
|
|
|
|
func testRemoveLastSegmentSupportsMergedTailRetranscription() {
|
|
var stitcher = UtteranceTranscriptStitcher()
|
|
stitcher.append(index: 0, text: "第一段")
|
|
stitcher.append(index: 1, text: "第二段")
|
|
stitcher.removeLastSegment()
|
|
stitcher.append(index: 1, text: "第二段合并")
|
|
XCTAssertEqual(stitcher.composed(), "第一段 第二段合并")
|
|
}
|
|
|
|
/// Documents the preMerge wipe hazard: append ignores empty text, so
|
|
/// removeLast + empty append leaves nothing. Pipeline must guard this.
|
|
func testEmptyAppendAfterRemoveLastWipesPriorSegment() {
|
|
var stitcher = UtteranceTranscriptStitcher()
|
|
stitcher.append(index: 0, text: "已识别内容")
|
|
stitcher.removeLastSegment()
|
|
stitcher.append(index: 0, text: "")
|
|
XCTAssertEqual(stitcher.composedSafely(), "")
|
|
}
|
|
}
|