use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class RichInputConnectionAndTextRangeTests method testGetWordRangeAtCursor.
public void testGetWordRangeAtCursor() {
/**
* Test logic in getting the word range at the cursor.
*/
final SpacingAndPunctuations SPACE = new SpacingAndPunctuations(mSpacingAndPunctuations, new int[] { Constants.CODE_SPACE });
final SpacingAndPunctuations TAB = new SpacingAndPunctuations(mSpacingAndPunctuations, new int[] { Constants.CODE_TAB });
// A character that needs surrogate pair to represent its code point (U+2008A).
final String SUPPLEMENTARY_CHAR_STRING = "𠂊";
final SpacingAndPunctuations SUPPLEMENTARY_CHAR = new SpacingAndPunctuations(mSpacingAndPunctuations, StringUtils.toSortedCodePointArray(SUPPLEMENTARY_CHAR_STRING));
// あいうえお
final String HIRAGANA_WORD = "あいうえお";
// και
final String GREEK_WORD = "και";
ExtractedText et = new ExtractedText();
final MockInputMethodService mockInputMethodService = new MockInputMethodService();
final RichInputConnection ic = new RichInputConnection(mockInputMethodService);
mockInputMethodService.setInputConnection(new MockConnection("word wo", "rd", et));
et.startOffset = 0;
et.selectionStart = 7;
TextRange r;
ic.beginBatchEdit();
// basic case
r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
assertTrue(TextUtils.equals("word", r.mWord));
// tab character instead of space
mockInputMethodService.setInputConnection(new MockConnection("one\tword\two", "rd", et));
ic.beginBatchEdit();
r = ic.getWordRangeAtCursor(TAB, ScriptUtils.SCRIPT_LATIN);
ic.endBatchEdit();
assertTrue(TextUtils.equals("word", r.mWord));
// splitting on supplementary character
mockInputMethodService.setInputConnection(new MockConnection("one word" + SUPPLEMENTARY_CHAR_STRING + "wo", "rd", et));
ic.beginBatchEdit();
r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_LATIN);
ic.endBatchEdit();
assertTrue(TextUtils.equals("word", r.mWord));
// split on chars outside the specified script
mockInputMethodService.setInputConnection(new MockConnection(HIRAGANA_WORD + "wo", "rd" + GREEK_WORD, et));
ic.beginBatchEdit();
r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_LATIN);
ic.endBatchEdit();
assertTrue(TextUtils.equals("word", r.mWord));
// likewise for greek
mockInputMethodService.setInputConnection(new MockConnection("text" + GREEK_WORD, "text", et));
ic.beginBatchEdit();
r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_GREEK);
ic.endBatchEdit();
assertTrue(TextUtils.equals(GREEK_WORD, r.mWord));
}
use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class RichInputConnectionAndTextRangeTests method testCursorTouchingWord.
public void testCursorTouchingWord() {
final MockInputMethodService ims = new MockInputMethodService();
final RichInputConnection ic = new RichInputConnection(ims);
final SpacingAndPunctuations sap = mSpacingAndPunctuations;
ims.setInputConnection(new MockConnection("users", 5));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("users'", 5));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("users'", 6));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("'users'", 6));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("'users'", 7));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("users '", 6));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("users '", 7));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("re-", 3));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("re--", 4));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("-", 1));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection("--", 2));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" -", 2));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" --", 3));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" users '", 1));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" users '", 3));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" users '", 7));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" users are", 7));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertTrue(ic.isCursorTouchingWord(sap, true));
ims.setInputConnection(new MockConnection(" users 'are", 7));
ic.resetCachesUponCursorMoveAndReturnSuccess(ims.cursorPos(), ims.cursorPos(), true);
assertFalse(ic.isCursorTouchingWord(sap, true));
}
use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class DictionaryInfoUtilsTests method testLooksValidForDictionaryInsertion.
public void testLooksValidForDictionaryInsertion() {
final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
@Override
protected SpacingAndPunctuations job(final Resources res) {
return new SpacingAndPunctuations(res);
}
};
final Resources res = getContext().getResources();
final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("aochaueo", sp));
assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("", sp));
assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("ao-ch'aueo", sp));
assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("2908743256", sp));
assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("31aochaueo", sp));
assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("akeo raeoch oerch .", sp));
assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("!!!", sp));
}
use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class CapsModeUtilsTests method testGetCapsMode.
public void testGetCapsMode() {
final int c = TextUtils.CAP_MODE_CHARACTERS;
final int w = TextUtils.CAP_MODE_WORDS;
final int s = TextUtils.CAP_MODE_SENTENCES;
final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
@Override
protected SpacingAndPunctuations job(final Resources res) {
return new SpacingAndPunctuations(res);
}
};
final Resources res = getContext().getResources();
SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
allPathsForCaps("", c | w | s, sp, false);
allPathsForCaps("Word", c, sp, false);
allPathsForCaps("Word.", c, sp, false);
allPathsForCaps("Word ", c | w, sp, false);
allPathsForCaps("Word. ", c | w | s, sp, false);
allPathsForCaps("Word..", c, sp, false);
allPathsForCaps("Word.. ", c | w | s, sp, false);
allPathsForCaps("Word... ", c | w | s, sp, false);
allPathsForCaps("Word ... ", c | w | s, sp, false);
allPathsForCaps("Word . ", c | w, sp, false);
allPathsForCaps("In the U.S ", c | w, sp, false);
allPathsForCaps("In the U.S. ", c | w, sp, false);
allPathsForCaps("Some stuff (e.g. ", c | w, sp, false);
allPathsForCaps("In the U.S.. ", c | w | s, sp, false);
allPathsForCaps("\"Word.\" ", c | w | s, sp, false);
allPathsForCaps("\"Word\". ", c | w | s, sp, false);
allPathsForCaps("\"Word\" ", c | w, sp, false);
// Test for phantom space
allPathsForCaps("Word", c | w, sp, true);
allPathsForCaps("Word.", c | w | s, sp, true);
// Tests after some whitespace
allPathsForCaps("Word\n", c | w | s, sp, false);
allPathsForCaps("Word\n", c | w | s, sp, true);
allPathsForCaps("Word\n ", c | w | s, sp, true);
allPathsForCaps("Word.\n", c | w | s, sp, false);
allPathsForCaps("Word.\n", c | w | s, sp, true);
allPathsForCaps("Word.\n ", c | w | s, sp, true);
sp = job.runInLocale(res, Locale.FRENCH);
allPathsForCaps("\"Word.\" ", c | w, sp, false);
allPathsForCaps("\"Word\". ", c | w | s, sp, false);
allPathsForCaps("\"Word\" ", c | w, sp, false);
// Test special case for German. German does not capitalize at the start of a
// line when the previous line starts with a comma. It does in other cases.
sp = job.runInLocale(res, Locale.GERMAN);
allPathsForCaps("Liebe Sara,\n", c | w, sp, false);
allPathsForCaps("Liebe Sara,\n", c | w, sp, true);
allPathsForCaps("Liebe Sara, \n ", c | w, sp, false);
allPathsForCaps("Liebe Sara \n ", c | w | s, sp, false);
allPathsForCaps("Liebe Sara.\n ", c | w | s, sp, false);
sp = job.runInLocale(res, Locale.ENGLISH);
allPathsForCaps("Liebe Sara,\n", c | w | s, sp, false);
allPathsForCaps("Liebe Sara,\n", c | w | s, sp, true);
allPathsForCaps("Liebe Sara, \n ", c | w | s, sp, false);
allPathsForCaps("Liebe Sara \n ", c | w | s, sp, false);
allPathsForCaps("Liebe Sara.\n ", c | w | s, sp, false);
// Test armenian period
sp = job.runInLocale(res, LocaleUtils.constructLocaleFromString("hy_AM"));
assertTrue("Period is not sentence separator in Armenian", !sp.isSentenceSeparator('.'));
assertTrue("Sentence separator is Armenian period in Armenian", sp.isSentenceSeparator(0x589));
// No space : capitalize only if MODE_CHARACTERS
allPathsForCaps("Word", c, sp, false);
allPathsForCaps("Word.", c, sp, false);
// Space, but no armenian period : capitalize if MODE_WORDS but not SENTENCES
allPathsForCaps("Word. ", c | w, sp, false);
// Armenian period : capitalize if MODE_SENTENCES
allPathsForCaps("Word։ ", c | w | s, sp, false);
// Test for sentence terminators
sp = job.runInLocale(res, Locale.ENGLISH);
allPathsForCaps("Word? ", c | w | s, sp, false);
allPathsForCaps("Word?", c | w | s, sp, true);
allPathsForCaps("Word?", c, sp, false);
allPathsForCaps("Word! ", c | w | s, sp, false);
allPathsForCaps("Word!", c | w | s, sp, true);
allPathsForCaps("Word!", c, sp, false);
allPathsForCaps("Word; ", c | w, sp, false);
allPathsForCaps("Word;", c | w, sp, true);
allPathsForCaps("Word;", c, sp, false);
// Test for sentence terminators in Greek
sp = job.runInLocale(res, LocaleUtils.constructLocaleFromString("el"));
allPathsForCaps("Word? ", c | w | s, sp, false);
allPathsForCaps("Word?", c | w | s, sp, true);
allPathsForCaps("Word?", c, sp, false);
allPathsForCaps("Word! ", c | w | s, sp, false);
allPathsForCaps("Word!", c | w | s, sp, true);
allPathsForCaps("Word!", c, sp, false);
// In Greek ";" is the question mark and it terminates the sentence
allPathsForCaps("Word; ", c | w | s, sp, false);
allPathsForCaps("Word;", c | w | s, sp, true);
allPathsForCaps("Word;", c, sp, false);
}
use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class NgramContextTests method testGetNgramContextFromNthPreviousWord.
public void testGetNgramContextFromNthPreviousWord() {
SpacingAndPunctuations spacingAndPunctuations = new SpacingAndPunctuations(mContext.getResources());
assertEquals("<S>", NgramContextUtils.getNgramContextFromNthPreviousWord("", spacingAndPunctuations, 1).extractPrevWordsContext());
assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a. b ", spacingAndPunctuations, 1).extractPrevWordsContext());
assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a? b ", spacingAndPunctuations, 1).extractPrevWordsContext());
assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a! b ", spacingAndPunctuations, 1).extractPrevWordsContext());
assertEquals("<S> b", NgramContextUtils.getNgramContextFromNthPreviousWord("a\nb ", spacingAndPunctuations, 1).extractPrevWordsContext());
assertEquals("<S> a b", NgramContextUtils.getNgramContextFromNthPreviousWord("a b ", spacingAndPunctuations, 1).extractPrevWordsContext());
assertFalse(NgramContextUtils.getNgramContextFromNthPreviousWord("a b c d e", spacingAndPunctuations, 1).extractPrevWordsContext().startsWith("<S>"));
}
Aggregations