Handle [A-Z] if input state is not empty (#292)
This fixes the regression, first introduced in 2.2, from 2.0.x behavior.
This commit is contained in:
parent
7563568e7f
commit
ea2e76e107
|
@ -266,17 +266,40 @@ class KeyHandlerBopomofoTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLetter() {
|
// Regression test for #292.
|
||||||
let input = KeyHandlerInput(inputText: "A", keyCode: 0, charCode: charCode("A"), flags: .shift, isVerticalMode: false)
|
func testUppercaseLetterWhenEmpty() {
|
||||||
|
let input = KeyHandlerInput(inputText: "A", keyCode: KeyCode.enter.rawValue, charCode: charCode("A"), flags: [], isVerticalMode: false)
|
||||||
var state: InputState = InputState.Empty()
|
var state: InputState = InputState.Empty()
|
||||||
handler.handle(input: input, state: state) { newState in
|
let result = handler.handle(input: input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
XCTAssertFalse(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regression test for #292.
|
||||||
|
func testUppercaseLetterWhenNotEmpty() {
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let keys = Array("u6").map {
|
||||||
|
String($0)
|
||||||
|
}
|
||||||
|
for key in keys {
|
||||||
|
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input: input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let letterInput = KeyHandlerInput(inputText: "A", keyCode: 0, charCode: charCode("A"), flags: .shift, isVerticalMode: false)
|
||||||
|
handler.handle(input: letterInput, state: state) { newState in
|
||||||
state = newState
|
state = newState
|
||||||
} errorCallback: {
|
} errorCallback: {
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||||
if let state = state as? InputState.Inputting {
|
if let state = state as? InputState.Inputting {
|
||||||
XCTAssertEqual(state.composingBuffer, "a")
|
XCTAssertEqual(state.composingBuffer, "一a")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,17 @@ class KeyHandlerPlainBopomofoTests: XCTestCase {
|
||||||
Preferences.keyboardLayout = savedKeyboardLayout
|
Preferences.keyboardLayout = savedKeyboardLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for #292.
|
||||||
|
func testUppercaseLetterWhenEmpty() {
|
||||||
|
let input = KeyHandlerInput(inputText: "A", keyCode: KeyCode.enter.rawValue, charCode: charCode("A"), flags: [], isVerticalMode: false)
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let result = handler.handle(input: input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
XCTAssertFalse(result)
|
||||||
|
}
|
||||||
|
|
||||||
func testPunctuationTable() {
|
func testPunctuationTable() {
|
||||||
let input = KeyHandlerInput(inputText: "`", keyCode: 0, charCode: charCode("`"), flags: .shift, isVerticalMode: false)
|
let input = KeyHandlerInput(inputText: "`", keyCode: 0, charCode: charCode("`"), flags: .shift, isVerticalMode: false)
|
||||||
var state: InputState = InputState.Empty()
|
var state: InputState = InputState.Empty()
|
||||||
|
|
|
@ -541,7 +541,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((char) charCode >= 'A' && (char) charCode <= 'Z') {
|
if ([state isKindOfClass:[InputStateNotEmpty class]] && (char) charCode >= 'A' && (char) charCode <= 'Z') {
|
||||||
string letter = string("_letter_") + string(1, (char) charCode);
|
string letter = string("_letter_") + string(1, (char) charCode);
|
||||||
if ([self _handlePunctuation:letter state:state usingVerticalMode:input.useVerticalMode stateCallback:stateCallback errorCallback:errorCallback]) {
|
if ([self _handlePunctuation:letter state:state usingVerticalMode:input.useVerticalMode stateCallback:stateCallback errorCallback:errorCallback]) {
|
||||||
return YES;
|
return YES;
|
||||||
|
|
Loading…
Reference in New Issue