1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.inputmethod.latin.settings; 18 19 import android.content.res.Resources; 20 import android.test.AndroidTestCase; 21 import android.test.suitebuilder.annotation.SmallTest; 22 23 import com.android.inputmethod.latin.SuggestedWords; 24 import com.android.inputmethod.latin.common.Constants; 25 import com.android.inputmethod.latin.utils.RunInLocale; 26 27 import junit.framework.AssertionFailedError; 28 29 import java.util.Locale; 30 31 @SmallTest 32 public class SpacingAndPunctuationsTests extends AndroidTestCase { 33 private static final int ARMENIAN_FULL_STOP = '\u0589'; 34 private static final int ARMENIAN_COMMA = '\u055D'; 35 36 private int mScreenMetrics; 37 isPhone()38 private boolean isPhone() { 39 return Constants.isPhone(mScreenMetrics); 40 } 41 isTablet()42 private boolean isTablet() { 43 return Constants.isTablet(mScreenMetrics); 44 } 45 46 private SpacingAndPunctuations ENGLISH; 47 private SpacingAndPunctuations FRENCH; 48 private SpacingAndPunctuations GERMAN; 49 private SpacingAndPunctuations ARMENIAN; 50 private SpacingAndPunctuations THAI; 51 private SpacingAndPunctuations KHMER; 52 private SpacingAndPunctuations LAO; 53 private SpacingAndPunctuations ARABIC; 54 private SpacingAndPunctuations PERSIAN; 55 private SpacingAndPunctuations HEBREW; 56 57 private SpacingAndPunctuations UNITED_STATES; 58 private SpacingAndPunctuations UNITED_KINGDOM; 59 private SpacingAndPunctuations CANADA_FRENCH; 60 private SpacingAndPunctuations SWISS_GERMAN; 61 private SpacingAndPunctuations INDIA_ENGLISH; 62 private SpacingAndPunctuations ARMENIA_ARMENIAN; 63 private SpacingAndPunctuations CAMBODIA_KHMER; 64 private SpacingAndPunctuations LAOS_LAO; 65 66 @Override setUp()67 protected void setUp() throws Exception { 68 super.setUp(); 69 70 mScreenMetrics = Settings.readScreenMetrics(getContext().getResources()); 71 72 // Language only 73 ENGLISH = getSpacingAndPunctuations(Locale.ENGLISH); 74 FRENCH = getSpacingAndPunctuations(Locale.FRENCH); 75 GERMAN = getSpacingAndPunctuations(Locale.GERMAN); 76 THAI = getSpacingAndPunctuations(new Locale("th")); 77 ARMENIAN = getSpacingAndPunctuations(new Locale("hy")); 78 KHMER = getSpacingAndPunctuations(new Locale("km")); 79 LAO = getSpacingAndPunctuations(new Locale("lo")); 80 ARABIC = getSpacingAndPunctuations(new Locale("ar")); 81 PERSIAN = getSpacingAndPunctuations(new Locale("fa")); 82 HEBREW = getSpacingAndPunctuations(new Locale("iw")); 83 84 // Language and Country 85 UNITED_STATES = getSpacingAndPunctuations(Locale.US); 86 UNITED_KINGDOM = getSpacingAndPunctuations(Locale.UK); 87 CANADA_FRENCH = getSpacingAndPunctuations(Locale.CANADA_FRENCH); 88 SWISS_GERMAN = getSpacingAndPunctuations(new Locale("de", "CH")); 89 INDIA_ENGLISH = getSpacingAndPunctuations(new Locale("en", "IN")); 90 ARMENIA_ARMENIAN = getSpacingAndPunctuations(new Locale("hy", "AM")); 91 CAMBODIA_KHMER = getSpacingAndPunctuations(new Locale("km", "KH")); 92 LAOS_LAO = getSpacingAndPunctuations(new Locale("lo", "LA")); 93 } 94 getSpacingAndPunctuations(final Locale locale)95 private SpacingAndPunctuations getSpacingAndPunctuations(final Locale locale) { 96 final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() { 97 @Override 98 protected SpacingAndPunctuations job(Resources res) { 99 return new SpacingAndPunctuations(res); 100 } 101 }; 102 return job.runInLocale(getContext().getResources(), locale); 103 } 104 testingStandardWordSeparator(final SpacingAndPunctuations sp)105 private static void testingStandardWordSeparator(final SpacingAndPunctuations sp) { 106 assertTrue("Tab", sp.isWordSeparator('\t')); 107 assertTrue("Newline", sp.isWordSeparator('\n')); 108 assertTrue("Space", sp.isWordSeparator(' ')); 109 assertTrue("Exclamation", sp.isWordSeparator('!')); 110 assertTrue("Quotation", sp.isWordSeparator('"')); 111 assertFalse("Number", sp.isWordSeparator('#')); 112 assertFalse("Dollar", sp.isWordSeparator('$')); 113 assertFalse("Percent", sp.isWordSeparator('%')); 114 assertTrue("Ampersand", sp.isWordSeparator('&')); 115 assertFalse("Apostrophe", sp.isWordSeparator('\'')); 116 assertTrue("L Paren", sp.isWordSeparator('(')); 117 assertTrue("R Paren", sp.isWordSeparator(')')); 118 assertTrue("Asterisk", sp.isWordSeparator('*')); 119 assertTrue("Plus", sp.isWordSeparator('+')); 120 assertTrue("Comma", sp.isWordSeparator(',')); 121 assertFalse("Minus", sp.isWordSeparator('-')); 122 assertTrue("Period", sp.isWordSeparator('.')); 123 assertTrue("Slash", sp.isWordSeparator('/')); 124 assertTrue("Colon", sp.isWordSeparator(':')); 125 assertTrue("Semicolon", sp.isWordSeparator(';')); 126 assertTrue("L Angle", sp.isWordSeparator('<')); 127 assertTrue("Equal", sp.isWordSeparator('=')); 128 assertTrue("R Angle", sp.isWordSeparator('>')); 129 assertTrue("Question", sp.isWordSeparator('?')); 130 assertFalse("Atmark", sp.isWordSeparator('@')); 131 assertTrue("L S Bracket", sp.isWordSeparator('[')); 132 assertFalse("B Slash", sp.isWordSeparator('\\')); 133 assertTrue("R S Bracket", sp.isWordSeparator(']')); 134 assertFalse("Circumflex", sp.isWordSeparator('^')); 135 assertTrue("Underscore", sp.isWordSeparator('_')); 136 assertFalse("Grave", sp.isWordSeparator('`')); 137 assertTrue("L C Brace", sp.isWordSeparator('{')); 138 assertTrue("V Line", sp.isWordSeparator('|')); 139 assertTrue("R C Brace", sp.isWordSeparator('}')); 140 assertFalse("Tilde", sp.isWordSeparator('~')); 141 } 142 testWordSeparator()143 public void testWordSeparator() { 144 testingStandardWordSeparator(ENGLISH); 145 testingStandardWordSeparator(FRENCH); 146 testingStandardWordSeparator(CANADA_FRENCH); 147 testingStandardWordSeparator(ARMENIA_ARMENIAN); 148 assertTrue(ARMENIA_ARMENIAN.isWordSeparator(ARMENIAN_FULL_STOP)); 149 assertTrue(ARMENIA_ARMENIAN.isWordSeparator(ARMENIAN_COMMA)); 150 // TODO: We should fix these. 151 testingStandardWordSeparator(ARMENIAN); 152 assertFalse(ARMENIAN.isWordSeparator(ARMENIAN_FULL_STOP)); 153 assertFalse(ARMENIAN.isWordSeparator(ARMENIAN_COMMA)); 154 } 155 testingStandardWordConnector(final SpacingAndPunctuations sp)156 private static void testingStandardWordConnector(final SpacingAndPunctuations sp) { 157 assertFalse("Tab", sp.isWordConnector('\t')); 158 assertFalse("Newline", sp.isWordConnector('\n')); 159 assertFalse("Space", sp.isWordConnector(' ')); 160 assertFalse("Exclamation", sp.isWordConnector('!')); 161 assertFalse("Quotation", sp.isWordConnector('"')); 162 assertFalse("Number", sp.isWordConnector('#')); 163 assertFalse("Dollar", sp.isWordConnector('$')); 164 assertFalse("Percent", sp.isWordConnector('%')); 165 assertFalse("Ampersand", sp.isWordConnector('&')); 166 assertTrue("Apostrophe", sp.isWordConnector('\'')); 167 assertFalse("L Paren", sp.isWordConnector('(')); 168 assertFalse("R Paren", sp.isWordConnector(')')); 169 assertFalse("Asterisk", sp.isWordConnector('*')); 170 assertFalse("Plus", sp.isWordConnector('+')); 171 assertFalse("Comma", sp.isWordConnector(',')); 172 assertTrue("Minus", sp.isWordConnector('-')); 173 assertFalse("Period", sp.isWordConnector('.')); 174 assertFalse("Slash", sp.isWordConnector('/')); 175 assertFalse("Colon", sp.isWordConnector(':')); 176 assertFalse("Semicolon", sp.isWordConnector(';')); 177 assertFalse("L Angle", sp.isWordConnector('<')); 178 assertFalse("Equal", sp.isWordConnector('=')); 179 assertFalse("R Angle", sp.isWordConnector('>')); 180 assertFalse("Question", sp.isWordConnector('?')); 181 assertFalse("Atmark", sp.isWordConnector('@')); 182 assertFalse("L S Bracket", sp.isWordConnector('[')); 183 assertFalse("B Slash", sp.isWordConnector('\\')); 184 assertFalse("R S Bracket", sp.isWordConnector(']')); 185 assertFalse("Circumflex", sp.isWordConnector('^')); 186 assertFalse("Underscore", sp.isWordConnector('_')); 187 assertFalse("Grave", sp.isWordConnector('`')); 188 assertFalse("L C Brace", sp.isWordConnector('{')); 189 assertFalse("V Line", sp.isWordConnector('|')); 190 assertFalse("R C Brace", sp.isWordConnector('}')); 191 assertFalse("Tilde", sp.isWordConnector('~')); 192 193 } 194 testWordConnector()195 public void testWordConnector() { 196 testingStandardWordConnector(ENGLISH); 197 testingStandardWordConnector(FRENCH); 198 testingStandardWordConnector(CANADA_FRENCH); 199 testingStandardWordConnector(ARMENIA_ARMENIAN); 200 } 201 testingCommonPrecededBySpace(final SpacingAndPunctuations sp)202 private static void testingCommonPrecededBySpace(final SpacingAndPunctuations sp) { 203 assertFalse("Tab", sp.isUsuallyPrecededBySpace('\t')); 204 assertFalse("Newline", sp.isUsuallyPrecededBySpace('\n')); 205 assertFalse("Space", sp.isUsuallyPrecededBySpace(' ')); 206 //assertFalse("Exclamation", sp.isUsuallyPrecededBySpace('!')); 207 assertFalse("Quotation", sp.isUsuallyPrecededBySpace('"')); 208 assertFalse("Number", sp.isUsuallyPrecededBySpace('#')); 209 assertFalse("Dollar", sp.isUsuallyPrecededBySpace('$')); 210 assertFalse("Percent", sp.isUsuallyPrecededBySpace('%')); 211 assertTrue("Ampersand", sp.isUsuallyPrecededBySpace('&')); 212 assertFalse("Apostrophe", sp.isUsuallyPrecededBySpace('\'')); 213 assertTrue("L Paren", sp.isUsuallyPrecededBySpace('(')); 214 assertFalse("R Paren", sp.isUsuallyPrecededBySpace(')')); 215 assertFalse("Asterisk", sp.isUsuallyPrecededBySpace('*')); 216 assertFalse("Plus", sp.isUsuallyPrecededBySpace('+')); 217 assertFalse("Comma", sp.isUsuallyPrecededBySpace(',')); 218 assertFalse("Minus", sp.isUsuallyPrecededBySpace('-')); 219 assertFalse("Period", sp.isUsuallyPrecededBySpace('.')); 220 assertFalse("Slash", sp.isUsuallyPrecededBySpace('/')); 221 //assertFalse("Colon", sp.isUsuallyPrecededBySpace(':')); 222 //assertFalse("Semicolon", sp.isUsuallyPrecededBySpace(';')); 223 assertFalse("L Angle", sp.isUsuallyPrecededBySpace('<')); 224 assertFalse("Equal", sp.isUsuallyPrecededBySpace('=')); 225 assertFalse("R Angle", sp.isUsuallyPrecededBySpace('>')); 226 //assertFalse("Question", sp.isUsuallyPrecededBySpace('?')); 227 assertFalse("Atmark", sp.isUsuallyPrecededBySpace('@')); 228 assertTrue("L S Bracket", sp.isUsuallyPrecededBySpace('[')); 229 assertFalse("B Slash", sp.isUsuallyPrecededBySpace('\\')); 230 assertFalse("R S Bracket", sp.isUsuallyPrecededBySpace(']')); 231 assertFalse("Circumflex", sp.isUsuallyPrecededBySpace('^')); 232 assertFalse("Underscore", sp.isUsuallyPrecededBySpace('_')); 233 assertFalse("Grave", sp.isUsuallyPrecededBySpace('`')); 234 assertTrue("L C Brace", sp.isUsuallyPrecededBySpace('{')); 235 assertFalse("V Line", sp.isUsuallyPrecededBySpace('|')); 236 assertFalse("R C Brace", sp.isUsuallyPrecededBySpace('}')); 237 assertFalse("Tilde", sp.isUsuallyPrecededBySpace('~')); 238 } 239 testingStandardPrecededBySpace(final SpacingAndPunctuations sp)240 private static void testingStandardPrecededBySpace(final SpacingAndPunctuations sp) { 241 testingCommonPrecededBySpace(sp); 242 assertFalse("Exclamation", sp.isUsuallyPrecededBySpace('!')); 243 assertFalse("Colon", sp.isUsuallyPrecededBySpace(':')); 244 assertFalse("Semicolon", sp.isUsuallyPrecededBySpace(';')); 245 assertFalse("Question", sp.isUsuallyPrecededBySpace('?')); 246 } 247 testIsUsuallyPrecededBySpace()248 public void testIsUsuallyPrecededBySpace() { 249 testingStandardPrecededBySpace(ENGLISH); 250 testingCommonPrecededBySpace(FRENCH); 251 assertTrue("Exclamation", FRENCH.isUsuallyPrecededBySpace('!')); 252 assertTrue("Colon", FRENCH.isUsuallyPrecededBySpace(':')); 253 assertTrue("Semicolon", FRENCH.isUsuallyPrecededBySpace(';')); 254 assertTrue("Question", FRENCH.isUsuallyPrecededBySpace('?')); 255 testingCommonPrecededBySpace(CANADA_FRENCH); 256 assertFalse("Exclamation", CANADA_FRENCH.isUsuallyPrecededBySpace('!')); 257 assertTrue("Colon", CANADA_FRENCH.isUsuallyPrecededBySpace(':')); 258 assertFalse("Semicolon", CANADA_FRENCH.isUsuallyPrecededBySpace(';')); 259 assertFalse("Question", CANADA_FRENCH.isUsuallyPrecededBySpace('?')); 260 testingStandardPrecededBySpace(ARMENIA_ARMENIAN); 261 } 262 testingStandardFollowedBySpace(final SpacingAndPunctuations sp)263 private static void testingStandardFollowedBySpace(final SpacingAndPunctuations sp) { 264 assertFalse("Tab", sp.isUsuallyFollowedBySpace('\t')); 265 assertFalse("Newline", sp.isUsuallyFollowedBySpace('\n')); 266 assertFalse("Space", sp.isUsuallyFollowedBySpace(' ')); 267 assertTrue("Exclamation", sp.isUsuallyFollowedBySpace('!')); 268 assertFalse("Quotation", sp.isUsuallyFollowedBySpace('"')); 269 assertFalse("Number", sp.isUsuallyFollowedBySpace('#')); 270 assertFalse("Dollar", sp.isUsuallyFollowedBySpace('$')); 271 assertFalse("Percent", sp.isUsuallyFollowedBySpace('%')); 272 assertTrue("Ampersand", sp.isUsuallyFollowedBySpace('&')); 273 assertFalse("Apostrophe", sp.isUsuallyFollowedBySpace('\'')); 274 assertFalse("L Paren", sp.isUsuallyFollowedBySpace('(')); 275 assertTrue("R Paren", sp.isUsuallyFollowedBySpace(')')); 276 assertFalse("Asterisk", sp.isUsuallyFollowedBySpace('*')); 277 assertFalse("Plus", sp.isUsuallyFollowedBySpace('+')); 278 assertTrue("Comma", sp.isUsuallyFollowedBySpace(',')); 279 assertFalse("Minus", sp.isUsuallyFollowedBySpace('-')); 280 assertTrue("Period", sp.isUsuallyFollowedBySpace('.')); 281 assertFalse("Slash", sp.isUsuallyFollowedBySpace('/')); 282 assertTrue("Colon", sp.isUsuallyFollowedBySpace(':')); 283 assertTrue("Semicolon", sp.isUsuallyFollowedBySpace(';')); 284 assertFalse("L Angle", sp.isUsuallyFollowedBySpace('<')); 285 assertFalse("Equal", sp.isUsuallyFollowedBySpace('=')); 286 assertFalse("R Angle", sp.isUsuallyFollowedBySpace('>')); 287 assertTrue("Question", sp.isUsuallyFollowedBySpace('?')); 288 assertFalse("Atmark", sp.isUsuallyFollowedBySpace('@')); 289 assertFalse("L S Bracket", sp.isUsuallyFollowedBySpace('[')); 290 assertFalse("B Slash", sp.isUsuallyFollowedBySpace('\\')); 291 assertTrue("R S Bracket", sp.isUsuallyFollowedBySpace(']')); 292 assertFalse("Circumflex", sp.isUsuallyFollowedBySpace('^')); 293 assertFalse("Underscore", sp.isUsuallyFollowedBySpace('_')); 294 assertFalse("Grave", sp.isUsuallyFollowedBySpace('`')); 295 assertFalse("L C Brace", sp.isUsuallyFollowedBySpace('{')); 296 assertFalse("V Line", sp.isUsuallyFollowedBySpace('|')); 297 assertTrue("R C Brace", sp.isUsuallyFollowedBySpace('}')); 298 assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); 299 } 300 testIsUsuallyFollowedBySpace()301 public void testIsUsuallyFollowedBySpace() { 302 testingStandardFollowedBySpace(ENGLISH); 303 testingStandardFollowedBySpace(FRENCH); 304 testingStandardFollowedBySpace(CANADA_FRENCH); 305 testingStandardFollowedBySpace(ARMENIA_ARMENIAN); 306 assertTrue(ARMENIA_ARMENIAN.isUsuallyFollowedBySpace(ARMENIAN_FULL_STOP)); 307 assertTrue(ARMENIA_ARMENIAN.isUsuallyFollowedBySpace(ARMENIAN_COMMA)); 308 } 309 testingStandardSentenceSeparator(final SpacingAndPunctuations sp)310 private static void testingStandardSentenceSeparator(final SpacingAndPunctuations sp) { 311 assertFalse("Tab", sp.isUsuallyFollowedBySpace('\t')); 312 assertFalse("Newline", sp.isUsuallyFollowedBySpace('\n')); 313 assertFalse("Space", sp.isUsuallyFollowedBySpace(' ')); 314 assertFalse("Exclamation", sp.isUsuallyFollowedBySpace('!')); 315 assertFalse("Quotation", sp.isUsuallyFollowedBySpace('"')); 316 assertFalse("Number", sp.isUsuallyFollowedBySpace('#')); 317 assertFalse("Dollar", sp.isUsuallyFollowedBySpace('$')); 318 assertFalse("Percent", sp.isUsuallyFollowedBySpace('%')); 319 assertFalse("Ampersand", sp.isUsuallyFollowedBySpace('&')); 320 assertFalse("Apostrophe", sp.isUsuallyFollowedBySpace('\'')); 321 assertFalse("L Paren", sp.isUsuallyFollowedBySpace('(')); 322 assertFalse("R Paren", sp.isUsuallyFollowedBySpace(')')); 323 assertFalse("Asterisk", sp.isUsuallyFollowedBySpace('*')); 324 assertFalse("Plus", sp.isUsuallyFollowedBySpace('+')); 325 assertFalse("Comma", sp.isUsuallyFollowedBySpace(',')); 326 assertFalse("Minus", sp.isUsuallyFollowedBySpace('-')); 327 assertTrue("Period", sp.isUsuallyFollowedBySpace('.')); 328 assertFalse("Slash", sp.isUsuallyFollowedBySpace('/')); 329 assertFalse("Colon", sp.isUsuallyFollowedBySpace(':')); 330 assertFalse("Semicolon", sp.isUsuallyFollowedBySpace(';')); 331 assertFalse("L Angle", sp.isUsuallyFollowedBySpace('<')); 332 assertFalse("Equal", sp.isUsuallyFollowedBySpace('=')); 333 assertFalse("R Angle", sp.isUsuallyFollowedBySpace('>')); 334 assertFalse("Question", sp.isUsuallyFollowedBySpace('?')); 335 assertFalse("Atmark", sp.isUsuallyFollowedBySpace('@')); 336 assertFalse("L S Bracket", sp.isUsuallyFollowedBySpace('[')); 337 assertFalse("B Slash", sp.isUsuallyFollowedBySpace('\\')); 338 assertFalse("R S Bracket", sp.isUsuallyFollowedBySpace(']')); 339 assertFalse("Circumflex", sp.isUsuallyFollowedBySpace('^')); 340 assertFalse("Underscore", sp.isUsuallyFollowedBySpace('_')); 341 assertFalse("Grave", sp.isUsuallyFollowedBySpace('`')); 342 assertFalse("L C Brace", sp.isUsuallyFollowedBySpace('{')); 343 assertFalse("V Line", sp.isUsuallyFollowedBySpace('|')); 344 assertFalse("R C Brace", sp.isUsuallyFollowedBySpace('}')); 345 assertFalse("Tilde", sp.isUsuallyFollowedBySpace('~')); 346 } 347 isSentenceSeparator()348 public void isSentenceSeparator() { 349 testingStandardSentenceSeparator(ENGLISH); 350 try { 351 testingStandardSentenceSeparator(ARMENIA_ARMENIAN); 352 fail("Armenian Sentence Separator"); 353 } catch (final AssertionFailedError e) { 354 assertEquals("Period", e.getMessage()); 355 } 356 assertTrue(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_FULL_STOP)); 357 assertFalse(ARMENIA_ARMENIAN.isSentenceSeparator(ARMENIAN_COMMA)); 358 } 359 testLanguageHasSpace()360 public void testLanguageHasSpace() { 361 assertTrue(ENGLISH.mCurrentLanguageHasSpaces); 362 assertTrue(FRENCH.mCurrentLanguageHasSpaces); 363 assertTrue(GERMAN.mCurrentLanguageHasSpaces); 364 assertFalse(THAI.mCurrentLanguageHasSpaces); 365 assertFalse(CAMBODIA_KHMER.mCurrentLanguageHasSpaces); 366 assertFalse(LAOS_LAO.mCurrentLanguageHasSpaces); 367 // TODO: We should fix these. 368 assertTrue(KHMER.mCurrentLanguageHasSpaces); 369 assertTrue(LAO.mCurrentLanguageHasSpaces); 370 } 371 testUsesAmericanTypography()372 public void testUsesAmericanTypography() { 373 assertTrue(ENGLISH.mUsesAmericanTypography); 374 assertTrue(UNITED_STATES.mUsesAmericanTypography); 375 assertTrue(UNITED_KINGDOM.mUsesAmericanTypography); 376 assertTrue(INDIA_ENGLISH.mUsesAmericanTypography); 377 assertFalse(FRENCH.mUsesAmericanTypography); 378 assertFalse(GERMAN.mUsesAmericanTypography); 379 assertFalse(SWISS_GERMAN.mUsesAmericanTypography); 380 } 381 testUsesGermanRules()382 public void testUsesGermanRules() { 383 assertFalse(ENGLISH.mUsesGermanRules); 384 assertFalse(FRENCH.mUsesGermanRules); 385 assertTrue(GERMAN.mUsesGermanRules); 386 assertTrue(SWISS_GERMAN.mUsesGermanRules); 387 } 388 389 // Punctuations for phone. 390 private static final String[] PUNCTUATION_LABELS_PHONE = { 391 "!", "?", ",", ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_" 392 }; 393 private static final String[] PUNCTUATION_WORDS_PHONE_LTR = PUNCTUATION_LABELS_PHONE; 394 private static final String[] PUNCTUATION_WORDS_PHONE_HEBREW = { 395 "!", "?", ",", ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_" 396 }; 397 // U+061F: "؟" ARABIC QUESTION MARK 398 // U+060C: "،" ARABIC COMMA 399 // U+061B: "؛" ARABIC SEMICOLON 400 private static final String[] PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN = { 401 "!", "\u061F", "\u060C", ":", "\u061B", "\"", "(", ")", "'", "-", "/", "@", "_" 402 }; 403 private static final String[] PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN = { 404 "!", "\u061F", "\u060C", ":", "\u061B", "\"", ")", "(", "'", "-", "/", "@", "_" 405 }; 406 407 // Punctuations for tablet. 408 private static final String[] PUNCTUATION_LABELS_TABLET = { 409 ":", ";", "\"", "(", ")", "'", "-", "/", "@", "_" 410 }; 411 private static final String[] PUNCTUATION_WORDS_TABLET_LTR = PUNCTUATION_LABELS_TABLET; 412 private static final String[] PUNCTUATION_WORDS_TABLET_HEBREW = { 413 ":", ";", "\"", ")", "(", "'", "-", "/", "@", "_" 414 }; 415 private static final String[] PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN = { 416 "!", "\u061F", ":", "\u061B", "\"", "'", "(", ")", "-", "/", "@", "_" 417 }; 418 private static final String[] PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN = { 419 "!", "\u061F", ":", "\u061B", "\"", "'", ")", "(", "-", "/", "@", "_" 420 }; 421 testingStandardPunctuationSuggestions(final SpacingAndPunctuations sp, final String[] punctuationLabels, final String[] punctuationWords)422 private static void testingStandardPunctuationSuggestions(final SpacingAndPunctuations sp, 423 final String[] punctuationLabels, final String[] punctuationWords) { 424 final SuggestedWords suggestedWords = sp.mSuggestPuncList; 425 assertFalse("typedWordValid", suggestedWords.mTypedWordValid); 426 assertFalse("willAutoCorrect", suggestedWords.mWillAutoCorrect); 427 assertTrue("isPunctuationSuggestions", suggestedWords.isPunctuationSuggestions()); 428 assertFalse("isObsoleteSuggestions", suggestedWords.mIsObsoleteSuggestions); 429 assertFalse("isPrediction", suggestedWords.isPrediction()); 430 assertEquals("size", punctuationLabels.length, suggestedWords.size()); 431 for (int index = 0; index < suggestedWords.size(); index++) { 432 assertEquals("punctuation label at " + index, 433 punctuationLabels[index], suggestedWords.getLabel(index)); 434 assertEquals("punctuation word at " + index, 435 punctuationWords[index], suggestedWords.getWord(index)); 436 } 437 } 438 testPhonePunctuationSuggestions()439 public void testPhonePunctuationSuggestions() { 440 if (!isPhone()) { 441 return; 442 } 443 testingStandardPunctuationSuggestions(ENGLISH, 444 PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); 445 testingStandardPunctuationSuggestions(FRENCH, 446 PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); 447 testingStandardPunctuationSuggestions(GERMAN, 448 PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_LTR); 449 testingStandardPunctuationSuggestions(ARABIC, 450 PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN); 451 testingStandardPunctuationSuggestions(PERSIAN, 452 PUNCTUATION_LABELS_PHONE_ARABIC_PERSIAN, PUNCTUATION_WORDS_PHONE_ARABIC_PERSIAN); 453 testingStandardPunctuationSuggestions(HEBREW, 454 PUNCTUATION_LABELS_PHONE, PUNCTUATION_WORDS_PHONE_HEBREW); 455 } 456 testTabletPunctuationSuggestions()457 public void testTabletPunctuationSuggestions() { 458 if (!isTablet()) { 459 return; 460 } 461 testingStandardPunctuationSuggestions(ENGLISH, 462 PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); 463 testingStandardPunctuationSuggestions(FRENCH, 464 PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); 465 testingStandardPunctuationSuggestions(GERMAN, 466 PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_LTR); 467 testingStandardPunctuationSuggestions(ARABIC, 468 PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN); 469 testingStandardPunctuationSuggestions(PERSIAN, 470 PUNCTUATION_LABELS_TABLET_ARABIC_PERSIAN, PUNCTUATION_WORDS_TABLET_ARABIC_PERSIAN); 471 testingStandardPunctuationSuggestions(HEBREW, 472 PUNCTUATION_LABELS_TABLET, PUNCTUATION_WORDS_TABLET_HEBREW); 473 } 474 } 475