Adds tests.

This commit is contained in:
zonble 2022-02-04 05:19:25 +08:00
parent ef61acf563
commit 472b149020
2 changed files with 39 additions and 6 deletions

View File

@ -119,6 +119,36 @@ class KeyHandlerPlainBopomofoTests: XCTestCase {
}
}
func testEnterWithReading() {
let input = KeyHandlerInput(inputText: "s", keyCode: 0, charCode: charCode("s"), flags: .shift, isVerticalMode: false)
var state: InputState = InputState.Empty()
handler.handle(input: input, state: state) { newState in
state = newState
} errorCallback: {
}
XCTAssertTrue(state is InputState.Inputting, "\(state)")
if let state = state as? InputState.Inputting {
XCTAssertEqual(state.composingBuffer, "")
}
let enter = KeyHandlerInput(inputText: " ", keyCode: 0, charCode: 13, flags: [], isVerticalMode: false)
var count = 0
handler.handle(input: enter, state: state) { newState in
if count == 0 {
state = newState
}
count += 1
} errorCallback: {
}
XCTAssertTrue(state is InputState.Inputting, "\(state)")
if let state = state as? InputState.Inputting {
XCTAssertEqual(state.composingBuffer, "")
}
}
func testInputNe() {
let input = KeyHandlerInput(inputText: "s", keyCode: 0, charCode: charCode("s"), flags: .shift, isVerticalMode: false)
var state: InputState = InputState.Empty()

View File

@ -779,12 +779,15 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
return NO;
}
if (_inputMode == InputModePlainBopomofo) {
if (!_bpmfReadingBuffer->isEmpty()) {
errorCallback();
}
return YES;
}
// Actually the lines would not be reached. When there is BMPF reading and
// a user input enter, we just send the readings to the client app.
// if (_inputMode == InputModePlainBopomofo) {
// if (!_bpmfReadingBuffer->isEmpty()) {
// errorCallback();
// }
// return YES;
// }
[self clear];