add tests for string utils, see #230

This commit is contained in:
Helium314 2023-10-21 09:22:07 +02:00
parent 9975a7d8f6
commit 9efeb7e339
2 changed files with 57 additions and 0 deletions

View file

@ -463,6 +463,8 @@ class InputLogicTest {
assertEquals("b", composingText)
}
// https://github.com/Helium314/openboard/issues/215
// https://github.com/Helium314/openboard/issues/229
@Test fun `autospace works in URL field when input isn't URL, also for multiple suggestions`() {
reset()
DeviceProtectedUtils.getSharedPreferences(latinIME).edit { putBoolean(Settings.PREF_URL_DETECTION, true) }
@ -508,6 +510,19 @@ class InputLogicTest {
assertEquals("hi ${StringUtils.newSingleCodePointString(0x1F36D)}", text)
}
// https://github.com/Helium314/openboard/issues/230
// todo: make it work
@Test fun `no autospace after opening quotes`() {
reset()
chainInput("\"Hi\" \"h")
assertEquals("\"Hi\" \"h", text)
assertEquals("h", composingText)
reset()
chainInput("\"Hi\", \"h")
assertEquals("\"Hi\", \"h", text)
assertEquals("", composingText)
}
// ------- helper functions ---------
// should be called before every test, so the same state is guaranteed

View file

@ -0,0 +1,42 @@
package org.dslul.openboard.inputmethod.latin
import org.dslul.openboard.inputmethod.latin.common.StringUtils
import org.junit.Test
// todo: actually this test could/should be significantly expanded...
class StringUtilsTest {
@Test fun `not inside double quotes without quotes`() {
assert(!StringUtils.isInsideDoubleQuoteOrAfterDigit("hello yes"))
}
@Test fun `inside double quotes after opening a quote`() {
assert(StringUtils.isInsideDoubleQuoteOrAfterDigit("hello \"yes"))
}
// maybe this is not that bad, should be correct after entering next text
@Test fun `not inside double quotes directly after closing quote`() {
assert(!StringUtils.isInsideDoubleQuoteOrAfterDigit("hello \"yes\""))
}
@Test fun `not inside double quotes after closing quote0`() {
assert(!StringUtils.isInsideDoubleQuoteOrAfterDigit("hello \"yes\" "))
}
// todo: fix it!
@Test fun `not inside double quotes after closing quote1`() {
assert(!StringUtils.isInsideDoubleQuoteOrAfterDigit("hello \"yes\", "))
}
@Test fun `inside double quotes after opening another quote`() {
assert(StringUtils.isInsideDoubleQuoteOrAfterDigit("hello \"yes\" \"h"))
}
@Test fun `inside double quotes after opening another quote2`() {
assert(StringUtils.isInsideDoubleQuoteOrAfterDigit("hello \"yes\", \"h"))
}
// todo: add tests for emoji detection?
// could help towards fully fixing https://github.com/Helium314/openboard/issues/22
// though this might be tricky, as some emojis will show as one on new Android versions, and
// as two on older versions
}