]> granicus.if.org Git - icu/commitdiff
ICU-10458 More data driven tests for parsing.
authorTravis Keep <keep94@gmail.com>
Wed, 3 Jun 2015 16:41:42 +0000 (16:41 +0000)
committerTravis Keep <keep94@gmail.com>
Wed, 3 Jun 2015 16:41:42 +0000 (16:41 +0000)
X-SVN-Rev: 37494

icu4j/main/tests/core/src/com/ibm/icu/dev/data/numberformattestspecification.txt
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTestTuple.java

index e2c6518de10c61d44bd44a984e0be8bb7618d8dc..5f32f04646ca93ef9772b59dbf4922aeb202d0d3 100644 (file)
@@ -9,6 +9,7 @@
 // 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
@@ -696,6 +697,31 @@ parse      output  breaks
 // 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
@@ -724,10 +750,10 @@ begin
 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
@@ -756,3 +782,4 @@ NaN 0.0     other
 5.1    0.0     one
 5.09   0.0     one
 
+
index 3ad1419ef25487335b33d1d0740907f669409a57..4c34fb24f5c5493ed2c8fa3a6e452f4369924557 100644 (file)
@@ -96,8 +96,6 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
                 @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) {
@@ -107,7 +105,7 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
                         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.
@@ -221,6 +219,17 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
                     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
+                    }
                 }
     };
 
@@ -387,6 +396,17 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
                     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
+                    }
                 }
     };
 
@@ -4096,5 +4116,9 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
             errln("decfmt.toPattern results wrong, expected \u200B$100.00, got " + currFmtResult);
         }
     }
+    
+    public void TestNumberFormatTestTupleToString() {
+        new NumberFormatTestTuple().toString();
+    }
 
 }
index 54f97268e4dc0395d8aa48ccd08bbc746fa6ee53..bfc8b6c8888148aafe3f55a4d8e633582e4de457 100644 (file)
@@ -113,6 +113,9 @@ public class NumberFormatTestTuple {
     public String parse = null;
     public Integer lenient = null;
     public String plural = null;
+    public Integer parseIntegerOnly = null;
+    public Integer decimalPatternMatchRequired = null;
+    public Integer parseNoExponent = null;
     
     
     
@@ -213,6 +216,9 @@ public class NumberFormatTestTuple {
         "parse",
         "lenient",
         "plural",
+        "parseIntegerOnly",
+        "decimalPatternMatchRequired",
+        "parseNoExponent",
     };
     
     static {
@@ -395,6 +401,18 @@ public class NumberFormatTestTuple {
         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