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.
64 lines
2.1 KiB
Swift
64 lines
2.1 KiB
Swift
import XCTest
|
|
@testable import OSGKeyboardShared
|
|
|
|
final class EditLastInputPromptTests: XCTestCase {
|
|
func testPayloadEscapesSourceAndInstruction() {
|
|
let payload = EditLastInputPromptComposer.userMessage(
|
|
.init(
|
|
sourceText: "<ignore> & original > \"quoted\" 'single' &",
|
|
spokenInstruction: "replace \"original\" with 'updated' > old"
|
|
)
|
|
)
|
|
XCTAssertTrue(
|
|
payload.contains(
|
|
"<ignore> & original > "quoted" "
|
|
+ "'single' &amp;"
|
|
)
|
|
)
|
|
XCTAssertTrue(
|
|
payload.contains(
|
|
"replace "original" with 'updated' > old"
|
|
)
|
|
)
|
|
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!")
|
|
)
|
|
}
|
|
}
|