1 32 package net.sf.retrotranslator.runtime.format; 33 34 import java.math.BigInteger ; 35 import java.util.*; 36 import net.sf.retrotranslator.tests.BaseTestCase; 37 38 41 public class NondecimalIntegralConversionTestCase extends BaseTestCase { 42 43 public void testFormat_Hex() throws Exception { 44 assertFormat("64", "%x", 100); 45 assertFormat("ffffff9c", "%x", -100); 46 assertFormat("64", "%x", (byte) 100); 47 assertFormat("9c", "%x", (byte) -100); 48 assertFormat("64", "%x", (short) 100); 49 assertFormat("ff9c", "%x", (short) -100); 50 assertFormat("64", "%x", 100L); 51 assertFormat("ffffffffffffff9c", "%x", -100L); 52 assertFormat("f4240", "%x", BigInteger.valueOf(1000000)); 53 assertFormat("-f4240", "%x", BigInteger.valueOf(-1000000)); 54 55 assertFormat("00064", "%05x", 100); 56 assertFormat("0x064", "%#05x", 100); 57 assertFormat("0xffffff9c", "%#x", -100); 58 assertFormat("0xffffffffffffff9c", "%#x", -100L); 59 assertFormat("0x00ffffffffffffff9c", "%0#20x", -100L); 60 assertFormat("ffffffffffffff9c ", "%-20x", -100L); 61 assertFormat("-0xf4240", "%#x", BigInteger.valueOf(-1000000)); 62 assertFormat("-0x00f4240", "%#010x", BigInteger.valueOf(-1000000)); 63 assertFormat("+0x00f4240", "%#+010x", BigInteger.valueOf(1000000)); 64 assertFormat(" 0x00f4240", "%# 010x", BigInteger.valueOf(1000000)); 65 assertFormat(" -0xf4240", "%#10x", BigInteger.valueOf(-1000000)); 66 assertFormat("-0xf4240 ", "%-#10x", BigInteger.valueOf(-1000000)); 67 assertFormat("(0xf4240) ", "%-(#15x", BigInteger.valueOf(-1000000)); 68 assertFormat(" +0xf4240", "%+#15x", BigInteger.valueOf(1000000)); 69 assertFormat(" f4240", "% x", BigInteger.valueOf(1000000)); 70 assertFormat("-0XF4240", "%#X", BigInteger.valueOf(-1000000)); 71 72 assertFormatException(IllegalFormatPrecisionException.class, "%,01.2x"); 73 assertFormatException(MissingFormatWidthException.class, "%,-x"); 74 assertFormatException(MissingFormatWidthException.class, "%,0x"); 75 assertFormatException(FormatFlagsConversionMismatchException.class, "%,x"); 76 assertFormatException(MissingFormatArgumentException.class, "%(x"); 77 assertFormatException(IllegalFormatConversionException.class, "%(x", "z"); 78 assertFormatException(FormatFlagsConversionMismatchException.class, "%(x", 5); 79 assertFormatException(FormatFlagsConversionMismatchException.class, "%+x", 5); 80 assertFormatException(FormatFlagsConversionMismatchException.class, "% x", 5); 81 assertFormatException(FormatFlagsConversionMismatchException.class, "%,x", 5); 82 assertFormatException(FormatFlagsConversionMismatchException.class, "%,x", BigInteger.valueOf(5)); 83 } 84 85 public void testFormat_Octal() throws Exception { 86 assertFormat("144", "%o", 100); 87 assertFormat("37777777634", "%o", -100); 88 assertFormat("144", "%o", (byte) 100); 89 assertFormat("234", "%o", (byte) -100); 90 assertFormat("144", "%o", (short) 100); 91 assertFormat("177634", "%o", (short) -100); 92 assertFormat("144", "%o", 100L); 93 assertFormat("1777777777777777777634", "%o", -100L); 94 assertFormat("3641100", "%o", BigInteger.valueOf(1000000)); 95 assertFormat("-3641100", "%o", BigInteger.valueOf(-1000000)); 96 97 assertFormat("00144", "%05o", 100); 98 assertFormat("0144", "%#o", 100); 99 assertFormat("037777777634", "%#o", -100); 100 assertFormat("01777777777777777777634", "%#o", -100L); 101 assertFormat("0001777777777777777777634", "%0#25o", -100L); 102 assertFormat("1777777777777777777634 ", "%-25o", -100L); 103 assertFormat("-03641100", "%#o", BigInteger.valueOf(-1000000)); 104 assertFormat("-003641100", "%#010o", BigInteger.valueOf(-1000000)); 105 assertFormat("+003641100", "%#+010o", BigInteger.valueOf(1000000)); 106 assertFormat(" 003641100", "%# 010o", BigInteger.valueOf(1000000)); 107 assertFormat(" -03641100", "%#10o", BigInteger.valueOf(-1000000)); 108 assertFormat("-03641100 ", "%-#10o", BigInteger.valueOf(-1000000)); 109 assertFormat("(03641100) ", "%-(#15o", BigInteger.valueOf(-1000000)); 110 assertFormat(" +03641100", "%+#15o", BigInteger.valueOf(1000000)); 111 assertFormat(" 3641100", "% o", BigInteger.valueOf(1000000)); 112 113 assertFormatException(UnknownFormatConversionException.class, "%#O"); 114 assertFormatException(IllegalFormatPrecisionException.class, "%,01.2o"); 115 assertFormatException(MissingFormatWidthException.class, "%,-o"); 116 assertFormatException(MissingFormatWidthException.class, "%,0o"); 117 assertFormatException(FormatFlagsConversionMismatchException.class, "%,o"); 118 assertFormatException(MissingFormatArgumentException.class, "%(o"); 119 assertFormatException(IllegalFormatConversionException.class, "%(o", "z"); 120 assertFormatException(FormatFlagsConversionMismatchException.class, "%(o", 5); 121 assertFormatException(FormatFlagsConversionMismatchException.class, "%+o", 5); 122 assertFormatException(FormatFlagsConversionMismatchException.class, "% o", 5); 123 assertFormatException(FormatFlagsConversionMismatchException.class, "%,o", 5); 124 assertFormatException(FormatFlagsConversionMismatchException.class, "%,o", BigInteger.valueOf(5)); 125 } 126 127 } | Popular Tags |