Search in sources :

Example 6 with IllegalFormatPrecisionException

use of java.util.IllegalFormatPrecisionException in project j2objc by google.

the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerExceptionOrder.

/**
     * java.util.Formatter#format(String, Object...) for BigInteger
     * exception throwing order
     */
public void test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerExceptionOrder() {
    Formatter f = null;
    BigInteger big = new BigInteger("100");
    /*
         * Order summary: UnknownFormatConversionException >
         * MissingFormatWidthException > IllegalFormatFlagsException >
         * IllegalFormatPrecisionException > IllegalFormatConversionException >
         * FormatFlagsConversionMismatchException
         *
         */
    f = new Formatter(Locale.US);
    try {
        f.format("%(o", false);
        fail();
    } catch (FormatFlagsConversionMismatchException expected) {
    } catch (IllegalFormatConversionException expected) {
    }
    try {
        f.format("%.4o", false);
        fail();
    } catch (IllegalFormatPrecisionException expected) {
    } catch (IllegalFormatConversionException expected) {
    }
    try {
        f.format("%+ .4o", big);
        fail();
    } catch (IllegalFormatPrecisionException expected) {
    } catch (IllegalFormatFlagsException expected) {
    }
    try {
        f.format("%+ -o", big);
        fail();
    } catch (MissingFormatWidthException expected) {
    } catch (IllegalFormatFlagsException expected) {
    }
    try {
        f.format("%-O", big);
        fail();
    } catch (MissingFormatWidthException expected) {
    } catch (UnknownFormatConversionException expected) {
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) FormatFlagsConversionMismatchException(java.util.FormatFlagsConversionMismatchException) IllegalFormatPrecisionException(java.util.IllegalFormatPrecisionException) Formatter(java.util.Formatter) BigInteger(java.math.BigInteger) IllegalFormatFlagsException(java.util.IllegalFormatFlagsException) MissingFormatWidthException(java.util.MissingFormatWidthException) IllegalFormatConversionException(java.util.IllegalFormatConversionException)

Example 7 with IllegalFormatPrecisionException

use of java.util.IllegalFormatPrecisionException in project j2objc by google.

the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_Flag.

/**
     * java.util.Formatter#format(String, Object...) for flag
     */
public void test_formatLjava_lang_String$Ljava_lang_Object_Flag() {
    Formatter f = new Formatter(Locale.US);
    try {
        f.format("%1$-#-8s", "something");
        fail("should throw DuplicateFormatFlagsException");
    } catch (DuplicateFormatFlagsException e) {
    // expected
    }
    final char[] chars = { '-', '#', '+', ' ', '0', ',', '(', '%', '<' };
    Arrays.sort(chars);
    f = new Formatter(Locale.US);
    for (char i = 0; i <= 256; i++) {
        // test 8 bit character
        if (Arrays.binarySearch(chars, i) >= 0 || Character.isDigit(i) || Character.isLetter(i)) {
            // They are characters used as flags, width or conversions
            continue;
        }
        try {
            f.format("%" + i + "s", 1);
            fail("should throw UnknownFormatConversionException");
        } catch (UnknownFormatConversionException e) {
        // expected
        } catch (IllegalFormatPrecisionException e) {
            // If i is '.', s can also be interpreted as an illegal precision.
            if (i != '.') {
                throw e;
            }
        }
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) DuplicateFormatFlagsException(java.util.DuplicateFormatFlagsException) IllegalFormatPrecisionException(java.util.IllegalFormatPrecisionException) Formatter(java.util.Formatter)

Aggregations

Formatter (java.util.Formatter)7 IllegalFormatPrecisionException (java.util.IllegalFormatPrecisionException)7 UnknownFormatConversionException (java.util.UnknownFormatConversionException)4 FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)3 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)3 BigInteger (java.math.BigInteger)2 IllegalFormatConversionException (java.util.IllegalFormatConversionException)2 MissingFormatWidthException (java.util.MissingFormatWidthException)2 Date (java.util.Date)1 DuplicateFormatFlagsException (java.util.DuplicateFormatFlagsException)1 IllegalFormatCodePointException (java.util.IllegalFormatCodePointException)1 IllegalFormatWidthException (java.util.IllegalFormatWidthException)1