Add some unit tests.

- Type "tgis", manually pick "thus", press backspace.
  Backspace should revert the manual pick.
  Check "tgis" is the result.
- Type "tgis" followed by a period.
  Period should trigger auto-correct to "this".
  Check "this" is the result.
- Type "tgis" followed by a period, then backspace.
  Period should trigger auto-correct to "this", and backspace should
  revert the auto-correction.
  Check "tgis." is the result.

Change-Id: I7e23c8a26fbdbe23336149a05ff01bc51707422e
main
Jean Chalard 2012-02-22 01:17:26 -08:00
parent 5935950d44
commit bb15f92d4f
1 changed files with 51 additions and 0 deletions

View File

@ -169,6 +169,22 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
mTextView.getText().toString());
}
public void testPickAutoCorrectionThenBackspace() {
final String WORD_TO_TYPE = "tgis";
final String WORD_TO_PICK = "this";
final String EXPECTED_RESULT = "tgis";
type(WORD_TO_TYPE);
// Choose the auto-correction, which is always in position 0. For "tgis", the
// auto-correction should be "this".
mLatinIME.pickSuggestionManually(0, WORD_TO_PICK);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK,
mTextView.getText().toString());
type(Keyboard.CODE_DELETE);
assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testPickTypedWordOverAutoCorrectionThenBackspace() {
final String WORD_TO_TYPE = "tgis";
final String EXPECTED_RESULT = "tgis";
@ -177,11 +193,29 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
// be occupied by the "this" auto-correction, as checked by testAutoCorrect())
mLatinIME.pickSuggestionManually(1, WORD_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE,
mTextView.getText().toString());
type(Keyboard.CODE_DELETE);
assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testPickDifferentSuggestionThenBackspace() {
final String WORD_TO_TYPE = "tgis";
final String WORD_TO_PICK = "thus";
final String EXPECTED_RESULT = "tgis";
type(WORD_TO_TYPE);
// Choose the second suggestion, which should be in position 2 and should be "thus"
// when "tgis is typed.
mLatinIME.pickSuggestionManually(2, WORD_TO_PICK);
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
assertEquals("pick different suggestion then backspace", WORD_TO_PICK,
mTextView.getText().toString());
type(Keyboard.CODE_DELETE);
assertEquals("pick different suggestion then backspace", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testDeleteSelection() {
final String STRING_TO_TYPE = "some text delete me some text";
final int SELECTION_START = 10;
@ -207,6 +241,23 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
assertEquals("simple auto-correct", EXPECTED_RESULT, mTextView.getText().toString());
}
public void testAutoCorrectWithPeriod() {
final String STRING_TO_TYPE = "tgis.";
final String EXPECTED_RESULT = "this.";
type(STRING_TO_TYPE);
assertEquals("auto-correct with period", EXPECTED_RESULT, mTextView.getText().toString());
}
public void testAutoCorrectWithPeriodThenRevert() {
final String STRING_TO_TYPE = "tgis.";
final String EXPECTED_RESULT = "tgis.";
type(STRING_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
type(Keyboard.CODE_DELETE);
assertEquals("auto-correct with period then revert", EXPECTED_RESULT,
mTextView.getText().toString());
}
public void testDoubleSpace() {
final String STRING_TO_TYPE = "this ";
final String EXPECTED_RESULT = "this. ";