diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/StringUtilsTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/StringUtilsTests.java | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java index 5db06ef51..00cca9d3b 100644 --- a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java @@ -17,6 +17,9 @@ package com.android.inputmethod.latin; import android.test.AndroidTestCase; +import android.text.TextUtils; + +import java.util.Locale; public class StringUtilsTests extends AndroidTestCase { public void testContainsInArray() { @@ -89,14 +92,50 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.removeFromCsvIfExists("key", "key1,key,key3,key,key5")); } - public void testHasUpperCase() { - assertTrue("single upper-case string", StringUtils.hasUpperCase("String")); - assertTrue("multi upper-case string", StringUtils.hasUpperCase("stRInG")); - assertTrue("all upper-case string", StringUtils.hasUpperCase("STRING")); - assertTrue("upper-case string with non-letters", StringUtils.hasUpperCase("He's")); + private void onePathForCaps(final CharSequence cs, final int expectedResult, final int mask, + final Locale l) { + int oneTimeResult = expectedResult & mask; + assertEquals("After >" + cs + "<", oneTimeResult, StringUtils.getCapsMode(cs, mask, l)); + } + + private void allPathsForCaps(final CharSequence cs, final int expectedResult, final Locale l) { + final int c = TextUtils.CAP_MODE_CHARACTERS; + final int w = TextUtils.CAP_MODE_WORDS; + final int s = TextUtils.CAP_MODE_SENTENCES; + onePathForCaps(cs, expectedResult, c | w | s, l); + onePathForCaps(cs, expectedResult, w | s, l); + onePathForCaps(cs, expectedResult, c | s, l); + onePathForCaps(cs, expectedResult, c | w, l); + onePathForCaps(cs, expectedResult, c, l); + onePathForCaps(cs, expectedResult, w, l); + onePathForCaps(cs, expectedResult, s, l); + } - assertFalse("empty string", StringUtils.hasUpperCase("")); - assertFalse("lower-case string", StringUtils.hasUpperCase("string")); - assertFalse("lower-case string with non-letters", StringUtils.hasUpperCase("he's")); + public void testGetCapsMode() { + final int c = TextUtils.CAP_MODE_CHARACTERS; + final int w = TextUtils.CAP_MODE_WORDS; + final int s = TextUtils.CAP_MODE_SENTENCES; + Locale l = Locale.ENGLISH; + allPathsForCaps("", c | w | s, l); + allPathsForCaps("Word", c, l); + allPathsForCaps("Word.", c, l); + allPathsForCaps("Word ", c | w, l); + allPathsForCaps("Word. ", c | w | s, l); + allPathsForCaps("Word..", c, l); + allPathsForCaps("Word.. ", c | w | s, l); + allPathsForCaps("Word... ", c | w | s, l); + allPathsForCaps("Word ... ", c | w | s, l); + allPathsForCaps("Word . ", c | w, l); + allPathsForCaps("In the U.S ", c | w, l); + allPathsForCaps("In the U.S. ", c | w, l); + allPathsForCaps("Some stuff (e.g. ", c | w, l); + allPathsForCaps("In the U.S.. ", c | w | s, l); + allPathsForCaps("\"Word.\" ", c | w | s, l); + allPathsForCaps("\"Word\". ", c | w | s, l); + allPathsForCaps("\"Word\" ", c | w, l); + l = Locale.FRENCH; + allPathsForCaps("\"Word.\" ", c | w, l); + allPathsForCaps("\"Word\". ", c | w | s, l); + allPathsForCaps("\"Word\" ", c | w, l); } } |