Java Code Examples for android.icu.lang.UCharacter#getIntPropertyMinValue()

The following examples show how to use android.icu.lang.UCharacter#getIntPropertyMinValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Test the property values API.  See JB#2410.
 */
@Test
public void TestPropertyValues() {
    int i, p, min, max;

    /* Min should be 0 for everything. */
    /* Until JB#2478 is fixed, the one exception is UProperty.BLOCK. */
    for (p=UProperty.INT_START; p<UProperty.INT_LIMIT; ++p) {
        min = UCharacter.getIntPropertyMinValue(p);
        if (min != 0) {
            if (p == UProperty.BLOCK) {
                /* This is okay...for now.  See JB#2487.
                   TODO Update this for JB#2487. */
            } else {
                String name;
                name = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);
                errln("FAIL: UCharacter.getIntPropertyMinValue(" + name + ") = " +
                      min + ", exp. 0");
            }
        }
    }

    if (UCharacter.getIntPropertyMinValue(UProperty.GENERAL_CATEGORY_MASK)
        != 0
        || UCharacter.getIntPropertyMaxValue(
                                           UProperty.GENERAL_CATEGORY_MASK)
           != -1) {
        errln("error: UCharacter.getIntPropertyMin/MaxValue("
              + "UProperty.GENERAL_CATEGORY_MASK) is wrong");
    }

    /* Max should be -1 for invalid properties. */
    max = UCharacter.getIntPropertyMaxValue(-1);
    if (max != -1) {
        errln("FAIL: UCharacter.getIntPropertyMaxValue(-1) = " +
              max + ", exp. -1");
    }

    /* Script should return 0 for an invalid code point. If the API
       throws an exception then that's fine too. */
    for (i=0; i<2; ++i) {
        try {
            int script = 0;
            String desc = null;
            switch (i) {
            case 0:
                script = UScript.getScript(-1);
                desc = "UScript.getScript(-1)";
                break;
            case 1:
                script = UCharacter.getIntPropertyValue(-1, UProperty.SCRIPT);
                desc = "UCharacter.getIntPropertyValue(-1, UProperty.SCRIPT)";
                break;
            }
            if (script != 0) {
                errln("FAIL: " + desc + " = " + script + ", exp. 0");
            }
        } catch (IllegalArgumentException e) {}
    }
}
 
Example 2
Source File: RegexUtilitiesTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Check all integer Unicode properties to make sure they work.
 */
@Test
public void TestUnicodeProperties() {
    final boolean skip = TestFmwk.getExhaustiveness() < 10;
    UnicodeSet temp = new UnicodeSet();
    for (int propNum = UProperty.INT_START; propNum < UProperty.INT_LIMIT; ++propNum) {
        if (skip && (propNum % 5 != 0)) {
            continue;
        }
        String propName = UCharacter.getPropertyName(propNum, NameChoice.LONG);
        final int intPropertyMinValue = UCharacter.getIntPropertyMinValue(propNum);
        int intPropertyMaxValue = UCharacter.getIntPropertyMaxValue(propNum);
        if (skip) { // only test first if not exhaustive
            intPropertyMaxValue = intPropertyMinValue;
        }
        for (int valueNum = intPropertyMinValue; valueNum <= intPropertyMaxValue; ++valueNum) {
            // hack for getting property value name
            String valueName = UCharacter.getPropertyValueName(propNum, valueNum, NameChoice.LONG);
            if (valueName == null) {
                valueName = UCharacter.getPropertyValueName(propNum, valueNum, NameChoice.SHORT);
                if (valueName == null) {
                    valueName = Integer.toString(valueNum);
                }
            }
            temp.applyIntPropertyValue(propNum, valueNum);
            if (temp.size() == 0) {
                continue;
            }
            final String prefix = "a";
            final String suffix = "b";
            String shouldMatch = prefix + UTF16.valueOf(temp.charAt(0)) + suffix;
            temp.complement();
            String shouldNotMatch = prefix + UTF16.valueOf(temp.charAt(0)) + suffix;

            // posix style pattern
            String rawPattern = prefix + "[:" + propName + "=" + valueName + ":]" + suffix;
            String rawNegativePattern = prefix + "[:^" + propName + "=" + valueName + ":]" + suffix;
            checkCharPattern(UnicodeRegex.compile(rawPattern), rawPattern, shouldMatch, shouldNotMatch);
            checkCharPattern(UnicodeRegex.compile(rawNegativePattern), rawNegativePattern, shouldNotMatch, shouldMatch);

            // perl style pattern
            rawPattern = prefix + "\\p{" + propName + "=" + valueName + "}" + suffix;
            rawNegativePattern = prefix + "\\P{" + propName + "=" + valueName + "}" + suffix;
            checkCharPattern(UnicodeRegex.compile(rawPattern), rawPattern, shouldMatch, shouldNotMatch);
            checkCharPattern(UnicodeRegex.compile(rawNegativePattern), rawNegativePattern, shouldNotMatch, shouldMatch);
        }
    }
}