add tests related to #210

This commit is contained in:
Helium314 2025-02-03 20:44:30 +01:00
parent f2a46cfa9a
commit 7c77f4d1c4

View file

@ -642,6 +642,28 @@ class InputLogicTest {
assertEquals("", text)
}
@Test fun `revert autocorrect on delete`() {
reset()
chainInput("hullo")
getAutocorrectedWithSpaceAfter("hello", "hullo")
functionalKeyPress(KeyCode.DELETE)
assertEquals("hullo", text)
// todo: now we want some way to disable revert on backspace, either per setting or something else
// need to avoid getting into the mLastComposedWord.canRevertCommit() part of handleBackspaceEvent
}
@Test fun `remove glide typing word on delete`() {
reset()
glideTypingInput("hello")
assertEquals("hello", text)
functionalKeyPress(KeyCode.DELETE)
assertEquals("", text)
// todo: now we want some way to disable delete-all on backspace, either per setting or something else
// need to avoid getting into the mWordComposer.isBatchMode() part of handleBackspaceEvent
}
// ------- helper functions ---------
// should be called before every test, so the same state is guaranteed
@ -675,6 +697,7 @@ class InputLogicTest {
if (currentScript != ScriptUtils.SCRIPT_HANGUL // check fails if hangul combiner merges symbols
&& !(codePoint == Constants.CODE_SPACE && oldBefore.lastOrNull() == ' ') // check fails when 2 spaces are converted into a period
&& !latinIME.mInputLogic.mSuggestedWords.mWillAutoCorrect // autocorrect obviously creates inconsistencies
) {
if (phantomSpaceToInsert.isEmpty())
assertEquals(oldBefore + insert, textBeforeCursor)
@ -780,6 +803,22 @@ class InputLogicTest {
checkConnectionConsistency()
}
// only works when autocorrect is on, separator after word is required
private fun getAutocorrectedWithSpaceAfter(suggestion: String, typedWord: String?) {
val info = SuggestedWordInfo(suggestion, "", 0, 0, null, 0, 0)
val typedInfo = SuggestedWordInfo(typedWord, "", 0, 0, null, 0, 0)
val sw = SuggestedWords(ArrayList(listOf(typedInfo, info)), null, typedInfo, false, true, false, 0, 0)
latinIME.mInputLogic.setSuggestedWords(sw)
input(' ')
checkConnectionConsistency()
}
private fun glideTypingInput(word: String) {
val info = SuggestedWordInfo(word, "", 0, 0, null, 0, 0)
val sw = SuggestedWords(ArrayList(listOf(info)), null, info, true, false, false, 0, 0)
latinIME.mInputLogic.onUpdateTailBatchInputCompleted(settingsValues, sw, KeyboardSwitcher.getInstance())
}
private fun checkConnectionConsistency() {
// RichInputConnection only has composing text up to cursor, but InputConnection has full composing text
val expectedConnectionComposingText = if (composingStart == -1 || composingEnd == -1) ""
@ -998,11 +1037,12 @@ private val ic = object : InputConnection {
it.selectionEnd = selectionEnd
}
}
// only effect is flashing, so whatever...
override fun commitCorrection(p0: CorrectionInfo?): Boolean = true
// implement only when necessary
override fun getCursorCapsMode(p0: Int): Int = TODO("Not yet implemented")
override fun deleteSurroundingTextInCodePoints(p0: Int, p1: Int): Boolean = TODO("Not yet implemented")
override fun commitCompletion(p0: CompletionInfo?): Boolean = TODO("Not yet implemented")
override fun commitCorrection(p0: CorrectionInfo?): Boolean = TODO("Not yet implemented")
override fun performEditorAction(p0: Int): Boolean = TODO("Not yet implemented")
override fun performContextMenuAction(p0: Int): Boolean = TODO("Not yet implemented")
override fun clearMetaKeyStates(p0: Int): Boolean = TODO("Not yet implemented")