Search in sources :

Example 1 with RestrictionLevel

use of android.icu.text.SpoofChecker.RestrictionLevel in project j2objc by google.

the class SpoofCheckerTest method TestRestrictionLevel.

@Test
public void TestRestrictionLevel() {
    Object[][] tests = { { "aγ♥", RestrictionLevel.UNRESTRICTIVE }, { "a", RestrictionLevel.ASCII }, { "γ", RestrictionLevel.SINGLE_SCRIPT_RESTRICTIVE }, { "aアー", RestrictionLevel.HIGHLY_RESTRICTIVE }, { "aऄ", RestrictionLevel.MODERATELY_RESTRICTIVE }, { "aγ", RestrictionLevel.MINIMALLY_RESTRICTIVE }, { "a♥", RestrictionLevel.UNRESTRICTIVE }, { "a\u303c", RestrictionLevel.HIGHLY_RESTRICTIVE }, { "aー\u303c", RestrictionLevel.HIGHLY_RESTRICTIVE }, { "aー\u303cア", RestrictionLevel.HIGHLY_RESTRICTIVE }, { "アaー\u303c", RestrictionLevel.HIGHLY_RESTRICTIVE }, { "a1١", RestrictionLevel.MODERATELY_RESTRICTIVE }, { "a1١۱", RestrictionLevel.MODERATELY_RESTRICTIVE }, { "١ー\u303caア1१۱", RestrictionLevel.MINIMALLY_RESTRICTIVE }, { "aアー\u303c1१١۱", RestrictionLevel.MINIMALLY_RESTRICTIVE } };
    UnicodeSet allowedChars = new UnicodeSet();
    // Allowed Identifier Characters. In addition to the Recommended Set,
    // allow u303c, which has an interesting script extension of Hani Hira Kana.
    allowedChars.addAll(SpoofChecker.RECOMMENDED).add(0x303c);
    CheckResult checkResult = new CheckResult();
    for (Object[] test : tests) {
        String testString = (String) test[0];
        RestrictionLevel expectedLevel = (RestrictionLevel) test[1];
        for (RestrictionLevel levelSetInSpoofChecker : RestrictionLevel.values()) {
            SpoofChecker sc = new SpoofChecker.Builder().setAllowedChars(allowedChars).setRestrictionLevel(levelSetInSpoofChecker).setChecks(// only check this
            SpoofChecker.RESTRICTION_LEVEL).build();
            boolean actualValue = sc.failsChecks(testString, checkResult);
            assertEquals("Testing restriction level for '" + testString + "'", expectedLevel, checkResult.restrictionLevel);
            // we want to fail if the text is (say) MODERATE and the testLevel is ASCII
            boolean expectedFailure = expectedLevel.compareTo(levelSetInSpoofChecker) > 0;
            assertEquals("Testing spoof restriction level for '" + testString + "', " + levelSetInSpoofChecker, expectedFailure, actualValue);
            // Coverage for getRestrictionLevel
            assertEquals("Restriction level on built SpoofChecker should be same as on builder", levelSetInSpoofChecker, sc.getRestrictionLevel());
        }
    }
}
Also used : SpoofChecker(android.icu.text.SpoofChecker) CheckResult(android.icu.text.SpoofChecker.CheckResult) RestrictionLevel(android.icu.text.SpoofChecker.RestrictionLevel) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

SpoofChecker (android.icu.text.SpoofChecker)1 CheckResult (android.icu.text.SpoofChecker.CheckResult)1 RestrictionLevel (android.icu.text.SpoofChecker.RestrictionLevel)1 UnicodeSet (android.icu.text.UnicodeSet)1 Test (org.junit.Test)1