Skip to content

Commit bdf2c3b

Browse files
committed
test(keyhandler): add tone key reading change tests
1 parent eb9adcd commit bdf2c3b

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

McBopomofoTests/KeyHandlerBopomofoTests.swift

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,3 +2706,87 @@ extension KeyHandlerBopomofoTests {
27062706
}
27072707
}
27082708
}
2709+
2710+
extension KeyHandlerBopomofoTests {
2711+
2712+
func testChnagingReadingUsingToneKey1() {
2713+
let associatedPhrasesEnabled = Preferences.associatedPhrasesEnabled
2714+
Preferences.associatedPhrasesEnabled = false
2715+
2716+
defer {
2717+
Preferences.associatedPhrasesEnabled = associatedPhrasesEnabled
2718+
}
2719+
2720+
var state: InputState = InputState.Empty()
2721+
let keys = Array("vul3a943").map {
2722+
String($0)
2723+
}
2724+
for key in keys {
2725+
let input = KeyHandlerInput(
2726+
inputText: key, keyCode: 0, charCode: charCode(key), flags: [],
2727+
isVerticalMode: false)
2728+
handler.handle(input: input, state: state) { newState in
2729+
state = newState
2730+
} errorCallback: {
2731+
}
2732+
}
2733+
XCTAssertTrue(state is InputState.Inputting, "\(state)")
2734+
if let state = state as? InputState.Inputting {
2735+
XCTAssertEqual(state.composingBuffer, "小買")
2736+
}
2737+
}
2738+
2739+
func testChnagingReadingUsingToneKey2() {
2740+
let associatedPhrasesEnabled = Preferences.associatedPhrasesEnabled
2741+
Preferences.associatedPhrasesEnabled = false
2742+
2743+
defer {
2744+
Preferences.associatedPhrasesEnabled = associatedPhrasesEnabled
2745+
}
2746+
2747+
var state: InputState = InputState.Empty()
2748+
let keys = Array("vul3a946").map {
2749+
String($0)
2750+
}
2751+
for key in keys {
2752+
let input = KeyHandlerInput(
2753+
inputText: key, keyCode: 0, charCode: charCode(key), flags: [],
2754+
isVerticalMode: false)
2755+
handler.handle(input: input, state: state) { newState in
2756+
state = newState
2757+
} errorCallback: {
2758+
}
2759+
}
2760+
XCTAssertTrue(state is InputState.Inputting, "\(state)")
2761+
if let state = state as? InputState.Inputting {
2762+
XCTAssertEqual(state.composingBuffer, "小埋")
2763+
}
2764+
}
2765+
2766+
func testChnagingReadingUsingToneKey3() {
2767+
let associatedPhrasesEnabled = Preferences.associatedPhrasesEnabled
2768+
Preferences.associatedPhrasesEnabled = false
2769+
2770+
defer {
2771+
Preferences.associatedPhrasesEnabled = associatedPhrasesEnabled
2772+
}
2773+
2774+
var state: InputState = InputState.Empty()
2775+
let keys = Array("vul3a947").map {
2776+
String($0)
2777+
}
2778+
for key in keys {
2779+
let input = KeyHandlerInput(
2780+
inputText: key, keyCode: 0, charCode: charCode(key), flags: [],
2781+
isVerticalMode: false)
2782+
handler.handle(input: input, state: state) { newState in
2783+
state = newState
2784+
} errorCallback: {
2785+
}
2786+
}
2787+
XCTAssertTrue(state is InputState.Inputting, "\(state)")
2788+
if let state = state as? InputState.Inputting {
2789+
XCTAssertEqual(state.composingBuffer, "小麥˙")
2790+
}
2791+
}
2792+
}

0 commit comments

Comments
 (0)