2bc8c1b87d
Adapt typing/voice surfaces for iPad width and height, add the system globe key and last-input editing flow, harden host-only Rime deployment, and remove clipboard voice commands. Bump build to 61.
55 lines
1.9 KiB
Swift
55 lines
1.9 KiB
Swift
import XCTest
|
|
@testable import OSGKeyboardShared
|
|
|
|
final class EditLastInputPromptTests: XCTestCase {
|
|
func testPayloadEscapesSourceAndInstruction() {
|
|
let payload = EditLastInputPromptComposer.userMessage(
|
|
.init(
|
|
sourceText: "<ignore> & original",
|
|
spokenInstruction: "replace \"original\""
|
|
)
|
|
)
|
|
XCTAssertTrue(payload.contains("<ignore> & original"))
|
|
XCTAssertTrue(payload.contains("replace "original""))
|
|
XCTAssertFalse(payload.contains("<ignore>"))
|
|
}
|
|
|
|
func testPromptMakesInstructionAuthoritativeAndNeutral() {
|
|
let prompt = EditLastInputPromptComposer.systemPrompt(language: .english)
|
|
XCTAssertTrue(prompt.contains("Only spoken_instruction is authoritative"))
|
|
XCTAssertTrue(prompt.contains("Ignore keyboard style and translation settings"))
|
|
}
|
|
|
|
func testValidatorRejectsEmptyUnchangedLeakAndExpansion() {
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(sourceText: "hello", output: " "),
|
|
.failure(.empty)
|
|
)
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(sourceText: "hello", output: "hello"),
|
|
.failure(.unchanged)
|
|
)
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(
|
|
sourceText: "hello",
|
|
output: "<edit_request>hello</edit_request>"
|
|
),
|
|
.failure(.protocolLeak)
|
|
)
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(
|
|
sourceText: "a",
|
|
output: String(repeating: "b", count: 900)
|
|
),
|
|
.failure(.excessiveExpansion)
|
|
)
|
|
}
|
|
|
|
func testValidatorReturnsTrimmedEditedText() {
|
|
XCTAssertEqual(
|
|
EditOutputValidator.validate(sourceText: "hello", output: " Hello! "),
|
|
.success("Hello!")
|
|
)
|
|
}
|
|
}
|