chore(android): Add logging and adjust unit test constant

This commit is contained in:
Darcy Wong 2019-11-12 22:18:52 +07:00
parent 002f378a51
commit c4c85af98f
2 changed files with 16 additions and 6 deletions

View file

@ -412,6 +412,7 @@ public final class KMManager {
if (Character.isHighSurrogate(charsBackup.charAt(charsBackup.length()-1))) {
// Firefox sometimes splits a surrogate pair so move the cursor back
ic.commitText("", -1);
Log.d(TAG, "adjust trimming high surrogate pair from charsBackup: " + charsBackup.toString());
charsBackup = ic.getTextBeforeCursor(originalBufferLength, 0);
}
@ -2207,7 +2208,7 @@ public final class KMManager {
CharSequence charsBefore = ic.getTextBeforeCursor(s.length()*2, 0);
int move = adjustCursorPosition(charsBefore, s);
if (move > 0) {
Log.d(TAG, "charsBefore: " + charsBefore.toString() + ", s: " + s + ", move: " + move);
Log.d(TAG, "adjusting cursor charsBefore: " + charsBefore.toString() + ", s: " + s + ", move: " + move);
ic.commitText("", -move);
}
}

View file

@ -17,6 +17,7 @@ public class RestoreCharsTest {
private final String COMPOSING_DOT_ABOVE = "\u0307";
private final String COMPOSING_CIRCUMFLEX_ACCENT = "\u0302";
private final String P_COMPOSING_CIRCUMFLEX_ACCENT = "p" + COMPOSING_CIRCUMFLEX_ACCENT;
@Test
public void test_invalid_input() {
@ -33,12 +34,20 @@ public class RestoreCharsTest {
charsToRestore = KMManager.restoreChars(expectedChars, currentContext);
Assert.assertEquals("", charsToRestore);
expectedChars = "qwerty";
expectedChars = WINK;
currentContext = "notamatch";
charsToRestore = KMManager.restoreChars(expectedChars, currentContext);
Assert.assertEquals("", charsToRestore);
}
@Test
public void test_split_surrogate_pair() {
CharSequence expectedChars = "o" + P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT + WINK + "p";
CharSequence currentContext = P_COMPOSING_CIRCUMFLEX_ACCENT + "\uD800";
CharSequence charsToRestore = KMManager.restoreChars(expectedChars, currentContext);
Assert.assertEquals("\uDC3C" + "p", charsToRestore);
}
@Test
public void test_chars() {
@ -47,14 +56,14 @@ public class RestoreCharsTest {
CharSequence charsToRestore = KMManager.restoreChars(expectedChars, currentContext);
Assert.assertEquals(SMILEY + COMPOSING_DOT_ABOVE, charsToRestore);
expectedChars = "qwertyp" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT;
expectedChars = "qwerty" + P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT;
currentContext = "qwertyp";
charsToRestore = KMManager.restoreChars(expectedChars, currentContext);
Assert.assertEquals(COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore);
Assert.assertEquals(COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore);
expectedChars = "qwertyp" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT;
expectedChars = "qwerty" + P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT;
currentContext = "qwerty";
charsToRestore = KMManager.restoreChars(expectedChars, currentContext);
Assert.assertEquals("p" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore);
Assert.assertEquals(P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore);
}
}