summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/libcore/icu
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-02-04 15:37:52 -0800
committerElliott Hughes <enh@google.com>2013-02-04 17:28:21 -0800
commit3aac4ddc4d17c07fa8b4908069d23d5401a77993 (patch)
tree4b8e70836ce522d4fc0d7ca03f53a7327e3fb153 /luni/src/test/java/libcore/icu
parent3ad678058ea02fe44d720442c2ee0501dc483974 (diff)
downloadlibcore-3aac4ddc4d17c07fa8b4908069d23d5401a77993.zip
libcore-3aac4ddc4d17c07fa8b4908069d23d5401a77993.tar.gz
libcore-3aac4ddc4d17c07fa8b4908069d23d5401a77993.tar.bz2
Add icu4c-backed transliteration.
Change-Id: I4194810646a2a0661331aaf941fb5f99ce7758b1
Diffstat (limited to 'luni/src/test/java/libcore/icu')
-rw-r--r--luni/src/test/java/libcore/icu/TransliteratorTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/icu/TransliteratorTest.java b/luni/src/test/java/libcore/icu/TransliteratorTest.java
new file mode 100644
index 0000000..7187cbc
--- /dev/null
+++ b/luni/src/test/java/libcore/icu/TransliteratorTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2013 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 libcore.icu;
+
+public class TransliteratorTest extends junit.framework.TestCase {
+ public void testAll() throws Exception {
+ for (String id : Transliterator.getAvailableIDs()) {
+ System.err.println(id);
+ Transliterator.transliterate(id, "hello");
+ }
+ }
+
+ public void test_Unknown() throws Exception {
+ try {
+ Transliterator.transliterate("Unknown", "hello");
+ fail();
+ } catch (RuntimeException expected) {
+ }
+ }
+
+ public void test_null_id() throws Exception {
+ try {
+ Transliterator.transliterate(null, "hello");
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ public void test_null_string() throws Exception {
+ try {
+ Transliterator.transliterate("Any-Upper", null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ public void test_Any_Upper() throws Exception {
+ assertEquals("HELLO WORLD!", Transliterator.transliterate("Any-Upper", "HeLlO WoRlD!"));
+ assertEquals("STRASSE", Transliterator.transliterate("Any-Upper", "Straße"));
+ }
+
+ public void test_Any_Lower() throws Exception {
+ assertEquals("hello world!", Transliterator.transliterate("Any-Lower", "HeLlO WoRlD!"));
+ }
+
+ public void test_Greek_Latin() throws Exception {
+ String greek = "Καλημέρα κόσμε!";
+
+ // Transliterate Greek to Latin, then to plain ASCII.
+ String latin = Transliterator.transliterate("Greek-Latin", greek);
+ String ascii = Transliterator.transliterate("Latin-Ascii", latin);
+ assertEquals("Kalēméra kósme!", latin);
+ assertEquals("Kalemera kosme!", ascii);
+
+ // Use alternative transliteration variants.
+ assertEquals("Kaliméra kósme!", Transliterator.transliterate("Greek-Latin/BGN", greek));
+ assertEquals("Kali̱méra kósme!", Transliterator.transliterate("Greek-Latin/UNGEGN", greek));
+ }
+
+ public void test_Han_Latin() throws Exception {
+ assertEquals("hàn zì/hàn zì", Transliterator.transliterate("Han-Latin", "汉字/漢字"));
+ }
+}