From 9efeb7e339cc51bbdc3a96545b0d62504fa48b6a Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sat, 21 Oct 2023 09:22:07 +0200 Subject: [PATCH] add tests for string utils, see #230 --- .../inputmethod/latin/InputLogicTest.kt | 15 +++++++ .../inputmethod/latin/StringUtilsTest.kt | 42 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 app/src/test/java/org/dslul/openboard/inputmethod/latin/StringUtilsTest.kt diff --git a/app/src/test/java/org/dslul/openboard/inputmethod/latin/InputLogicTest.kt b/app/src/test/java/org/dslul/openboard/inputmethod/latin/InputLogicTest.kt index 7d5d197d1..aae65f24d 100644 --- a/app/src/test/java/org/dslul/openboard/inputmethod/latin/InputLogicTest.kt +++ b/app/src/test/java/org/dslul/openboard/inputmethod/latin/InputLogicTest.kt @@ -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 diff --git a/app/src/test/java/org/dslul/openboard/inputmethod/latin/StringUtilsTest.kt b/app/src/test/java/org/dslul/openboard/inputmethod/latin/StringUtilsTest.kt new file mode 100644 index 000000000..d9d399718 --- /dev/null +++ b/app/src/test/java/org/dslul/openboard/inputmethod/latin/StringUtilsTest.kt @@ -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 +}