From 472b149020b5350f1efcc6d7f1cf9db0ed635e20 Mon Sep 17 00:00:00 2001 From: zonble Date: Fri, 4 Feb 2022 05:19:25 +0800 Subject: [PATCH] Adds tests. --- .../KeyHandlerPlainBopomofoTests.swift | 30 +++++++++++++++++++ Source/KeyHandler.mm | 15 ++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/McBopomofoTests/KeyHandlerPlainBopomofoTests.swift b/McBopomofoTests/KeyHandlerPlainBopomofoTests.swift index edd7ba08..4e99ebbd 100644 --- a/McBopomofoTests/KeyHandlerPlainBopomofoTests.swift +++ b/McBopomofoTests/KeyHandlerPlainBopomofoTests.swift @@ -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() diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index 123f50b8..34efb93e 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -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];