Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 226c4bba authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add a test for constructLocaleFromString(String).

This is a follow up CL for ed65bc0c [1],
which fixed special handling of a fake language code "tl".

  [1] Ica9cd2baac002c406f92331aadd7725d7424046a

Bug: 20696126
Change-Id: Ifc8bf2ff6bd617a215e4b68f6b2bf9b94e80db07
parent dd4e4121
Loading
Loading
Loading
Loading
+21 −0
Original line number Original line Diff line number Diff line
@@ -1191,4 +1191,25 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
                    InputMethodUtils.buildInputMethodsAndSubtypesString(map)));
                    InputMethodUtils.buildInputMethodsAndSubtypesString(map)));
        }
        }
    }
    }

    @SmallTest
    public void testConstructLocaleFromString() throws Exception {
        assertEquals(new Locale("en"), InputMethodUtils.constructLocaleFromString("en"));
        assertEquals(new Locale("en", "US"), InputMethodUtils.constructLocaleFromString("en_US"));
        assertEquals(new Locale("en", "US", "POSIX"),
                InputMethodUtils.constructLocaleFromString("en_US_POSIX"));

        // Special rewrite rule for "tl" for versions of Android earlier than Lollipop that did not
        // support three letter language codes, and used "tl" (Tagalog) as the language string for
        // "fil" (Filipino).
        assertEquals(new Locale("fil"), InputMethodUtils.constructLocaleFromString("tl"));
        assertEquals(new Locale("fil", "PH"), InputMethodUtils.constructLocaleFromString("tl_PH"));
        assertEquals(new Locale("fil", "PH", "POSIX"),
                InputMethodUtils.constructLocaleFromString("tl_PH_POSIX"));

        // So far rejecting an invalid/unexpected locale string is out of the scope of this method.
        assertEquals(new Locale("a"), InputMethodUtils.constructLocaleFromString("a"));
        assertEquals(new Locale("a b c"), InputMethodUtils.constructLocaleFromString("a b c"));
        assertEquals(new Locale("en-US"), InputMethodUtils.constructLocaleFromString("en-US"));
    }
}
}