diff options
Diffstat (limited to 'tests/src')
5 files changed, 441 insertions, 20 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java index 737d1695b..8b2bb4289 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyOutput.java @@ -63,7 +63,8 @@ abstract class ExpectedKeyOutput { final String codeString = StringUtils.newSingleCodePointString(mCode); // A letter may have an upper case counterpart that consists of multiple code // points, for instance the upper case of "ß" is "SS". - return newInstance(codeString.toUpperCase(locale)); + return newInstance(StringUtils.toUpperCaseOfStringForLocale( + codeString, true /* needsToUpperCase */, locale)); } // A special negative value has no upper case. return this; diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java index facdf7043..34024a5e0 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyVisual.java @@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.layout.expected; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.MoreKeySpec; +import com.android.inputmethod.latin.utils.StringUtils; import java.util.Locale; @@ -105,7 +106,8 @@ abstract class ExpectedKeyVisual { @Override ExpectedKeyVisual toUpperCase(final Locale locale) { - return new Label(mLabel.toUpperCase(locale)); + return new Label(StringUtils.toUpperCaseOfStringForLocale( + mLabel, true /* needsToUpperCase */, locale)); } @Override diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java index 199922491..f9d72269e 100644 --- a/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java +++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionAndTextRangeTests.java @@ -215,18 +215,23 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { "abc 'def", mSpacingAndPunctuations, 2), PrevWordsInfo.EMPTY_PREV_WORDS_INFO); } - /** - * Test logic in getting the word range at the cursor. - */ - private static final int[] SPACE = { Constants.CODE_SPACE }; - static final int[] TAB = { Constants.CODE_TAB }; - private static final int[] SPACE_TAB = StringUtils.toSortedCodePointArray(" \t"); - // A character that needs surrogate pair to represent its code point (U+2008A). - private static final String SUPPLEMENTARY_CHAR = "\uD840\uDC8A"; - private static final String HIRAGANA_WORD = "\u3042\u3044\u3046\u3048\u304A"; // あいうえお - private static final String GREEK_WORD = "\u03BA\u03B1\u03B9"; // και - 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 }); + final int[] SPACE_TAB = StringUtils.toSortedCodePointArray(" \t"); + // A character that needs surrogate pair to represent its code point (U+2008A). + final String SUPPLEMENTARY_CHAR_STRING = "\uD840\uDC8A"; + final SpacingAndPunctuations SUPPLEMENTARY_CHAR = new SpacingAndPunctuations( + mSpacingAndPunctuations, StringUtils.toSortedCodePointArray( + SUPPLEMENTARY_CHAR_STRING)); + final String HIRAGANA_WORD = "\u3042\u3044\u3046\u3048\u304A"; // あいうえお + final String GREEK_WORD = "\u03BA\u03B1\u03B9"; // και + ExtractedText et = new ExtractedText(); final MockInputMethodService mockInputMethodService = new MockInputMethodService(); final RichInputConnection ic = new RichInputConnection(mockInputMethodService); @@ -249,10 +254,9 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { // splitting on supplementary character mockInputMethodService.setInputConnection( - new MockConnection("one word" + SUPPLEMENTARY_CHAR + "wo", "rd", et)); + new MockConnection("one word" + SUPPLEMENTARY_CHAR_STRING + "wo", "rd", et)); ic.beginBatchEdit(); - r = ic.getWordRangeAtCursor(StringUtils.toSortedCodePointArray(SUPPLEMENTARY_CHAR), - ScriptUtils.SCRIPT_LATIN); + r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_LATIN); ic.endBatchEdit(); assertTrue(TextUtils.equals("word", r.mWord)); @@ -260,8 +264,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { mockInputMethodService.setInputConnection( new MockConnection(HIRAGANA_WORD + "wo", "rd" + GREEK_WORD, et)); ic.beginBatchEdit(); - r = ic.getWordRangeAtCursor(StringUtils.toSortedCodePointArray(SUPPLEMENTARY_CHAR), - ScriptUtils.SCRIPT_LATIN); + r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_LATIN); ic.endBatchEdit(); assertTrue(TextUtils.equals("word", r.mWord)); @@ -269,8 +272,7 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { mockInputMethodService.setInputConnection( new MockConnection("text" + GREEK_WORD, "text", et)); ic.beginBatchEdit(); - r = ic.getWordRangeAtCursor(StringUtils.toSortedCodePointArray(SUPPLEMENTARY_CHAR), - ScriptUtils.SCRIPT_GREEK); + r = ic.getWordRangeAtCursor(SUPPLEMENTARY_CHAR, ScriptUtils.SCRIPT_GREEK); ic.endBatchEdit(); assertTrue(TextUtils.equals(GREEK_WORD, r.mWord)); } @@ -286,6 +288,8 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase { } private void helpTestGetSuggestionSpansAtWord(final int cursorPos) { + final SpacingAndPunctuations SPACE = new SpacingAndPunctuations( + mSpacingAndPunctuations, new int[] { Constants.CODE_SPACE }); final MockInputMethodService mockInputMethodService = new MockInputMethodService(); final RichInputConnection ic = new RichInputConnection(mockInputMethodService); diff --git a/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java new file mode 100644 index 000000000..819d76328 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/utils/ImportantNoticeUtilsTests.java @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin.utils; + +import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE; +import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION; + +import android.content.Context; +import android.content.SharedPreferences; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.text.TextUtils; + +import java.util.concurrent.TimeUnit; + +@SmallTest +public class ImportantNoticeUtilsTests extends AndroidTestCase { + // This should be aligned with R.integer.config_important_notice_version. + private static final int CURRENT_IMPORTANT_NOTICE_VERSION = 1; + + private ImportantNoticePreferences mImportantNoticePreferences; + + private static class ImportantNoticePreferences { + private final SharedPreferences mPref; + + private Integer mVersion; + private Long mLastTime; + + public ImportantNoticePreferences(final Context context) { + mPref = ImportantNoticeUtils.getImportantNoticePreferences(context); + } + + private Integer getInt(final String key) { + if (mPref.contains(key)) { + return mPref.getInt(key, 0); + } + return null; + } + + public Long getLong(final String key) { + if (mPref.contains(key)) { + return mPref.getLong(key, 0); + } + return null; + } + + private void putInt(final String key, final Integer value) { + if (value == null) { + removePreference(key); + } else { + mPref.edit().putInt(key, value).apply(); + } + } + + private void putLong(final String key, final Long value) { + if (value == null) { + removePreference(key); + } else { + mPref.edit().putLong(key, value).apply(); + } + } + + private void removePreference(final String key) { + mPref.edit().remove(key).apply(); + } + + public void save() { + mVersion = getInt(KEY_IMPORTANT_NOTICE_VERSION); + mLastTime = getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE); + } + + public void restore() { + putInt(KEY_IMPORTANT_NOTICE_VERSION, mVersion); + putLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE, mLastTime); + } + + public void clear() { + removePreference(KEY_IMPORTANT_NOTICE_VERSION); + removePreference(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE); + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mImportantNoticePreferences = new ImportantNoticePreferences(getContext()); + mImportantNoticePreferences.save(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + mImportantNoticePreferences.restore(); + } + + public void testCurrentVersion() { + assertEquals("Current version", CURRENT_IMPORTANT_NOTICE_VERSION, + ImportantNoticeUtils.getCurrentImportantNoticeVersion(getContext())); + } + + public void testUpdateVersion() { + mImportantNoticePreferences.clear(); + + assertEquals("Current boolean before update", true, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + assertEquals("Last version before update", 0, + ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); + assertEquals("Next version before update ", 1, + ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); + assertEquals("Current title before update", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Current contents before update", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); + + ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext()); + + assertEquals("Current boolean after update", false, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + assertEquals("Last version after update", 1, + ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); + assertEquals("Next version after update", 2, + ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); + assertEquals("Current title after update", true, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Current contents after update", true, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); + } + + private static void sleep(final long millseconds) { + try { Thread.sleep(millseconds); } catch (final Exception e) { /* ignore */ } + } + + public void testTimeout() { + final long lastTime = System.currentTimeMillis() + - ImportantNoticeUtils.TIMEOUT_OF_IMPORTANT_NOTICE + + TimeUnit.MILLISECONDS.toMillis(1000); + mImportantNoticePreferences.clear(); + assertEquals("Before set last time", null, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + assertEquals("Set last time", false, + ImportantNoticeUtils.hasTimeoutPassed(getContext(), lastTime)); + assertEquals("After set last time", (Long)lastTime, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + + // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout. + assertEquals("Current boolean before timeout 1", true, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + assertEquals("Last version before timeout 1", 0, + ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); + assertEquals("Next version before timeout 1", 1, + ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); + assertEquals("Last time before timeout 1", (Long)lastTime, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + assertEquals("Current title before timeout 1", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Current contents before timeout 1", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); + + sleep(TimeUnit.MILLISECONDS.toMillis(600)); + + // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout + // again. + assertEquals("Current boolean before timeout 2", true, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + assertEquals("Last version before timeout 2", 0, + ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); + assertEquals("Next version before timeout 2", 1, + ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); + assertEquals("Last time before timeout 2", (Long)lastTime, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + assertEquals("Current title before timeout 2", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Current contents before timeout 2", false, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); + + sleep(TimeUnit.MILLISECONDS.toMillis(600)); + + // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout. + assertEquals("Current boolean after timeout 1", false, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + assertEquals("Last version after timeout 1", 1, + ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); + assertEquals("Next version after timeout 1", 2, + ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); + assertEquals("Last time aflter timeout 1", null, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + assertEquals("Current title after timeout 1", true, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Current contents after timeout 1", true, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); + + sleep(TimeUnit.MILLISECONDS.toMillis(600)); + + // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout again. + assertEquals("Current boolean after timeout 2", false, + ImportantNoticeUtils.shouldShowImportantNotice(getContext())); + assertEquals("Last version after timeout 2", 1, + ImportantNoticeUtils.getLastImportantNoticeVersion(getContext())); + assertEquals("Next version after timeout 2", 2, + ImportantNoticeUtils.getNextImportantNoticeVersion(getContext())); + assertEquals("Last time aflter timeout 2", null, + mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)); + assertEquals("Current title after timeout 2", true, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeTitle(getContext()))); + assertEquals("Current contents after timeout 2", true, TextUtils.isEmpty( + ImportantNoticeUtils.getNextImportantNoticeContents(getContext()))); + } +} diff --git a/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java new file mode 100644 index 000000000..ba2e99802 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/utils/StringUtilsTests.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin.utils; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.utils.StringUtils; + +import java.util.Locale; + +@SmallTest +public class StringUtilsTests extends AndroidTestCase { + private static final Locale US = Locale.US; + private static final Locale GERMAN = Locale.GERMAN; + private static final Locale TURKEY = new Locale("tr", "TR"); + private static final Locale GREECE = new Locale("el", "GR"); + + private static void assert_toUpperCaseOfStringForLocale(final Locale locale, + final String lowerCase, final String expected) { + assertEquals(lowerCase + " in " + locale, expected, + StringUtils.toUpperCaseOfStringForLocale( + lowerCase, true /* needsToUpperCase */, locale)); + } + + public void test_toUpperCaseOfStringForLocale() { + assert_toUpperCaseOfStringForLocale(US, null, null); + assert_toUpperCaseOfStringForLocale(US, "", ""); + assert_toUpperCaseOfStringForLocale(US, "aeiou", "AEIOU"); + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+00C0: "À" LATIN CAPITAL LETTER A WITH GRAVE + // U+00C8: "È" LATIN CAPITAL LETTER E WITH GRAVE + // U+00CE: "Î" LATIN CAPITAL LETTER I WITH CIRCUMFLEX + // U+00D6: "Ö" LATIN CAPITAL LETTER O WITH DIAERESIS + // U+016A: "Ū" LATIN CAPITAL LETTER U WITH MACRON + // U+00D1: "Ñ" LATIN CAPITAL LETTER N WITH TILDE + // U+00C7: "Ç" LATIN CAPITAL LETTER C WITH CEDILLA + assert_toUpperCaseOfStringForLocale(US, + "\u00E0\u00E8\u00EE\u00F6\u016B\u00F1\u00E7", + "\u00C0\u00C8\u00CE\u00D6\u016A\u00D1\u00C7"); + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015A: "Ś" LATIN CAPITAL LETTER S WITH ACUTE + // U+0160: "Š" LATIN CAPITAL LETTER S WITH CARONZ + assert_toUpperCaseOfStringForLocale(GERMAN, + "\u00DF\u015B\u0161", + "SS\u015A\u0160"); + // U+0259: "ə" LATIN SMALL LETTER SCHWA + // U+0069: "i" LATIN SMALL LETTER I + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+018F: "Ə" LATIN SMALL LETTER SCHWA + // U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE + // U+0049: "I" LATIN SMALL LETTER I + assert_toUpperCaseOfStringForLocale(TURKEY, + "\u0259\u0069\u0131", + "\u018F\u0130\u0049"); + // U+03C3: "σ" GREEK SMALL LETTER SIGMA + // U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA + // U+03A3: "Σ" GREEK CAPITAL LETTER SIGMA + assert_toUpperCaseOfStringForLocale(GREECE, + "\u03C3\u03C2", + "\u03A3\u03A3"); + // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS + // U+03AD: "έ" GREEK SMALL LETTER EPSILON WITH TONOS + // U+03AE: "ή" GREEK SMALL LETTER ETA WITH TONOS + // U+03AF: "ί" GREEK SMALL LETTER IOTA WITH TONOS + // U+03CC: "ό" GREEK SMALL LETTER OMICRON WITH TONOS + // U+03CD: "ύ" GREEK SMALL LETTER UPSILON WITH TONOS + // U+03CE: "ώ" GREEK SMALL LETTER OMEGA WITH TONOS + // U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS + // U+0388: "Έ" GREEK CAPITAL LETTER EPSILON WITH TONOS + // U+0389: "Ή" GREEK CAPITAL LETTER ETA WITH TONOS + // U+038A: "Ί" GREEK CAPITAL LETTER IOTA WITH TONOS + // U+038C: "Ό" GREEK CAPITAL LETTER OMICRON WITH TONOS + // U+038E: "Ύ" GREEK CAPITAL LETTER UPSILON WITH TONOS + // U+038F: "Ώ" GREEK CAPITAL LETTER OMEGA WITH TONOS + assert_toUpperCaseOfStringForLocale(GREECE, + "\u03AC\u03AD\u03AE\u03AF\u03CC\u03CD\u03CE", + "\u0386\u0388\u0389\u038A\u038C\u038E\u038F"); + // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA + // U+03CB: "ϋ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA + // U+0390: "ΐ" GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS + // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS + // U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA + // U+03AB: "Ϋ" GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA + // U+0399: "Ι" GREEK CAPITAL LETTER IOTA + // U+03A5: "Υ" GREEK CAPITAL LETTER UPSILON + // U+0308: COMBINING DIAERESIS + // U+0301: COMBINING GRAVE ACCENT + assert_toUpperCaseOfStringForLocale(GREECE, + "\u03CA\u03CB\u0390\u03B0", + "\u03AA\u03AB\u0399\u0308\u0301\u03A5\u0308\u0301"); + } + + private static void assert_toUpperCaseOfCodeForLocale(final Locale locale, final int lowerCase, + final int expected) { + assertEquals(lowerCase + " in " + locale, expected, + StringUtils.toUpperCaseOfCodeForLocale( + lowerCase, true /* needsToUpperCase */, locale)); + } + + public void test_toUpperCaseOfCodeForLocale() { + assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_ENTER, Constants.CODE_ENTER); + assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_SPACE, Constants.CODE_SPACE); + assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_COMMA, Constants.CODE_COMMA); + // U+0069: "i" LATIN SMALL LETTER I + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE + // U+0049: "I" LATIN SMALL LETTER I + assert_toUpperCaseOfCodeForLocale(US, 0x0069, 0x0049); // i -> I + assert_toUpperCaseOfCodeForLocale(US, 0x0131, 0x0049); // ı -> I + assert_toUpperCaseOfCodeForLocale(TURKEY, 0x0069, 0x0130); // i -> İ + assert_toUpperCaseOfCodeForLocale(TURKEY, 0x0131, 0x0049); // ı -> I + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // The title case of "ß" is "SS". + assert_toUpperCaseOfCodeForLocale(US, 0x00DF, Constants.CODE_UNSPECIFIED); + // U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS + // U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS + assert_toUpperCaseOfCodeForLocale(GREECE, 0x03AC, 0x0386); + // U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA + // U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA + assert_toUpperCaseOfCodeForLocale(GREECE, 0x03CA, 0x03AA); + // U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS + // The title case of "ΰ" is "\u03A5\u0308\u0301". + assert_toUpperCaseOfCodeForLocale(GREECE, 0x03B0, Constants.CODE_UNSPECIFIED); + } + + private static void assert_capitalizeFirstCodePoint(final Locale locale, final String text, + final String expected) { + assertEquals(text + " in " + locale, expected, + StringUtils.capitalizeFirstCodePoint(text, locale)); + } + + public void test_capitalizeFirstCodePoint() { + assert_capitalizeFirstCodePoint(US, "", ""); + assert_capitalizeFirstCodePoint(US, "a", "A"); + assert_capitalizeFirstCodePoint(US, "à", "À"); + assert_capitalizeFirstCodePoint(US, "ß", "SS"); + assert_capitalizeFirstCodePoint(US, "text", "Text"); + assert_capitalizeFirstCodePoint(US, "iGoogle", "IGoogle"); + assert_capitalizeFirstCodePoint(TURKEY, "iyi", "İyi"); + assert_capitalizeFirstCodePoint(TURKEY, "ısırdı", "Isırdı"); + assert_capitalizeFirstCodePoint(GREECE, "ά", "Ά"); + assert_capitalizeFirstCodePoint(GREECE, "άνεση", "Άνεση"); + } + + private static void assert_capitalizeFirstAndDowncaseRest(final Locale locale, + final String text, final String expected) { + assertEquals(text + " in " + locale, expected, + StringUtils.capitalizeFirstAndDowncaseRest(text, locale)); + } + + public void test_capitalizeFirstAndDowncaseRest() { + assert_capitalizeFirstAndDowncaseRest(US, "", ""); + assert_capitalizeFirstAndDowncaseRest(US, "a", "A"); + assert_capitalizeFirstAndDowncaseRest(US, "à", "À"); + assert_capitalizeFirstAndDowncaseRest(US, "ß", "SS"); + assert_capitalizeFirstAndDowncaseRest(US, "text", "Text"); + assert_capitalizeFirstAndDowncaseRest(US, "iGoogle", "Igoogle"); + assert_capitalizeFirstAndDowncaseRest(US, "invite", "Invite"); + assert_capitalizeFirstAndDowncaseRest(US, "INVITE", "Invite"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "iyi", "İyi"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "İYİ", "İyi"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "ısırdı", "Isırdı"); + assert_capitalizeFirstAndDowncaseRest(TURKEY, "ISIRDI", "Isırdı"); + assert_capitalizeFirstAndDowncaseRest(GREECE, "ά", "Ά"); + assert_capitalizeFirstAndDowncaseRest(GREECE, "άνεση", "Άνεση"); + assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση"); + } +} |