Search in sources :

Example 1 with CheckResult

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

the class SpoofCheckerTest method TestCheckResultToString11447.

@Test
public void TestCheckResultToString11447() {
    CheckResult checkResult = new CheckResult();
    SpoofChecker sc = new SpoofChecker.Builder().setChecks(SpoofChecker.MIXED_NUMBERS).build();
    sc.failsChecks("1१", checkResult);
    assertTrue("CheckResult: ", checkResult.toString().contains("MIXED_NUMBERS"));
}
Also used : SpoofChecker(android.icu.text.SpoofChecker) CheckResult(android.icu.text.SpoofChecker.CheckResult) Test(org.junit.Test)

Example 2 with CheckResult

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

the class SpoofCheckerTest method TestSpoofAPI.

/**
 * IntlTestSpoof is the top level test class for the Unicode Spoof detection tests
 */
// Test the USpoofDetector API functions that require C++
// The pure C part of the API, which is most of it, is tested in cintltst
/**
 * IntlTestSpoof tests for USpoofDetector
 */
@Test
public void TestSpoofAPI() {
    SpoofChecker sc = new SpoofChecker.Builder().setChecks(SpoofChecker.ALL_CHECKS).build();
    String s = "xyz";
    SpoofChecker.CheckResult result = new SpoofChecker.CheckResult();
    result.position = 666;
    boolean checkResults = sc.failsChecks(s, result);
    assertFalse("", checkResults);
    assertEquals("", 0, result.position);
    sc = new SpoofChecker.Builder().build();
    String s1 = "cxs";
    // Cyrillic "cxs"
    String s2 = Utility.unescape("\\u0441\\u0445\\u0455");
    int checkResult = sc.areConfusable(s1, s2);
    assertEquals("", SpoofChecker.MIXED_SCRIPT_CONFUSABLE | SpoofChecker.WHOLE_SCRIPT_CONFUSABLE, checkResult);
    sc = new SpoofChecker.Builder().build();
    s = "I1l0O";
    String dest = sc.getSkeleton(SpoofChecker.ANY_CASE, s);
    assertEquals("", dest, "lllOO");
}
Also used : CheckResult(android.icu.text.SpoofChecker.CheckResult) SpoofChecker(android.icu.text.SpoofChecker) CheckResult(android.icu.text.SpoofChecker.CheckResult) Test(org.junit.Test)

Example 3 with CheckResult

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

the class SpoofCheckerTest method TestMixedNumbers.

@Test
public void TestMixedNumbers() {
    Object[][] tests = { { "1", "[0]" }, { "१", "[०]" }, { "1१", "[0०]" }, { "١۱", "[٠۰]" }, { "a♥", "[]" }, { "a\u303c", "[]" }, { "aー\u303c", "[]" }, { "aー\u303cア", "[]" }, { "アaー\u303c", "[]" }, { "a1١", "[0٠]" }, { "a1١۱", "[0٠۰]" }, { "١ー\u303caア1१۱", "[0٠۰०]" }, { "aアー\u303c1१١۱", "[0٠۰०]" } };
    CheckResult checkResult = new CheckResult();
    for (Object[] test : tests) {
        String testString = (String) test[0];
        UnicodeSet expected = new UnicodeSet((String) test[1]);
        SpoofChecker sc = new SpoofChecker.Builder().setChecks(// only check this
        SpoofChecker.MIXED_NUMBERS).build();
        boolean actualValue = sc.failsChecks(testString, checkResult);
        assertEquals("", expected, checkResult.numerics);
        assertEquals("Testing spoof mixed numbers for '" + testString + "', ", expected.size() > 1, actualValue);
    }
}
Also used : SpoofChecker(android.icu.text.SpoofChecker) CheckResult(android.icu.text.SpoofChecker.CheckResult) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 4 with CheckResult

use of android.icu.text.SpoofChecker.CheckResult 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)

Example 5 with CheckResult

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

the class SpoofCheckerTest method TestBug11635.

@Test
public void TestBug11635() {
    // The bug was an error in iterating through supplementary characters in IdentifierInfo.
    // The three supplemental chars in the string are "123" from the mathematical bold digit range.
    // Common script, Nd general category, and no other restrictions on allowed characters
    // leaves "ABC123" as SINGLE_SCRIPT_RESTRICTIVE.
    String identifier = Utility.unescape("ABC\\U0001D7CF\\U0001D7D0\\U0001D7D1");
    CheckResult checkResult = new CheckResult();
    SpoofChecker sc = new SpoofChecker.Builder().setChecks(SpoofChecker.RESTRICTION_LEVEL).build();
    sc.failsChecks(identifier, checkResult);
    assertEquals("", RestrictionLevel.SINGLE_SCRIPT_RESTRICTIVE, checkResult.restrictionLevel);
}
Also used : SpoofChecker(android.icu.text.SpoofChecker) CheckResult(android.icu.text.SpoofChecker.CheckResult) Test(org.junit.Test)

Aggregations

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