// For more information on the format of this file, including all the available
// field names, please see
// https://docs.google.com/document/d/1T2P0p953_Lh1pRwo-5CuPVrHlIBa_wcXElG-Hhg_WHM/edit?usp=sharing
+
test basic patterns
set locale fr_FR
set format 1234.567
// JDK parses as -1945
(1,945d1) fail K
+test parse integer only
+set locale en
+set pattern 0.00
+set parseIntegerOnly 1
+begin
+parse output breaks
+35 35
++35 fail
+-35 -35
+2.63 2
+-39.99 -39
+
+test parse no exponent flag
+set pattern 0
+set locale en
+begin
+parseNoExponent parse output breaks
+// JDK doesn't allow lowercase exponent but ICU4J and ICU4C do.
+0 5e2 500 K
+0 5.3E2 530
+// See ticket 11725
+1 5e2 5 J
+1 5.3E2 5.3 JK
+
+
test parse strange prefix
set locale en
set positivePrefix dd
parse output breaks
// C consumes the '9' as a digit and assumes number is negative
// J and JDK bail
-6549K 654 CJK
+// 6549K 654 CJK
// C consumes the '9' as a digit and assumes number is negative
// J and JDK bail
-6549N -654 CJK
+// 6549N -654 CJK
test really strange prefix
set locale en
5.1 0.0 one
5.09 0.0 one
+
@Override
public String parse(NumberFormatTestTuple tuple) {
DecimalFormat fmt = newDecimalFormat(tuple);
- int lenient = tuple.lenient == null ? 1 : tuple.lenient.intValue();
- fmt.setParseStrict(lenient == 0 ? true : false);
ParsePosition ppos = new ParsePosition(0);
Number actual = fmt.parse(tuple.parse, ppos);
if (ppos.getIndex() == 0) {
return null;
}
if (tuple.output.equals("fail")) {
- return "Parse succeeded, but was expected to fail.";
+ return "Parse succeeded: "+actual+", but was expected to fail.";
}
Number expected = toNumber(tuple.output);
// number types cannot be compared, this is the best we can do.
if (tuple.localizedPattern != null) {
fmt.applyLocalizedPattern(tuple.localizedPattern);
}
+ int lenient = tuple.lenient == null ? 1 : tuple.lenient.intValue();
+ fmt.setParseStrict(lenient == 0);
+ if (tuple.parseIntegerOnly != null) {
+ fmt.setParseIntegerOnly(tuple.parseIntegerOnly != 0);
+ }
+ if (tuple.decimalPatternMatchRequired != null) {
+ fmt.setDecimalPatternMatchRequired(tuple.decimalPatternMatchRequired != 0);
+ }
+ if (tuple.parseNoExponent != null) {
+ // Oops, not supported for now
+ }
}
};
if (tuple.localizedPattern != null) {
fmt.applyLocalizedPattern(tuple.localizedPattern);
}
+
+ // lenient parsing not supported by JDK
+ if (tuple.parseIntegerOnly != null) {
+ fmt.setParseIntegerOnly(tuple.parseIntegerOnly != 0);
+ }
+ if (tuple.decimalPatternMatchRequired != null) {
+ // Oops, not supported
+ }
+ if (tuple.parseNoExponent != null) {
+ // Oops, not supported for now
+ }
}
};
errln("decfmt.toPattern results wrong, expected \u200B$100.00, got " + currFmtResult);
}
}
+
+ public void TestNumberFormatTestTupleToString() {
+ new NumberFormatTestTuple().toString();
+ }
}
public String parse = null;
public Integer lenient = null;
public String plural = null;
+ public Integer parseIntegerOnly = null;
+ public Integer decimalPatternMatchRequired = null;
+ public Integer parseNoExponent = null;
"parse",
"lenient",
"plural",
+ "parseIntegerOnly",
+ "decimalPatternMatchRequired",
+ "parseNoExponent",
};
static {
plural = value;
}
+ public void setParseIntegerOnly(String value) {
+ parseIntegerOnly = Integer.valueOf(value);
+ }
+
+ public void setDecimalPatternMatchRequired(String value) {
+ decimalPatternMatchRequired = Integer.valueOf(value);
+ }
+
+ public void setParseNoExponent(String value) {
+ parseNoExponent = Integer.valueOf(value);
+ }
+
// end field setters.
// start of field clearers