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