Skip to content

Commit

Permalink
ICU4J: Handle decimal params and unignore test
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Jun 27, 2024
1 parent 2e9d99b commit ecfa426
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ static void rewriteDates(Map<String, Object> params) {
}
}

static void rewriteDecimals(Map<String, Object> params) {
// For each value in `params` that's a map with the single key
// `decimal` and a string value s
// return a map with that value changed to Decimal(s)
// In JSON this looks like:
// "params": {"val": {"decimal": "1234567890123456789.987654321"}},
for (Map.Entry<String, Object> pair : params.entrySet()) {
if (pair.getValue() instanceof Map) {
Map innerMap = (Map) pair.getValue();
if (innerMap.size() == 1 && innerMap.containsKey("decimal")
&& innerMap.get("decimal") instanceof String) {
String decimalValue = (String) innerMap.get("decimal");
params.put(pair.getKey(), new com.ibm.icu.math.BigDecimal(decimalValue));
}
}
}
}


static boolean expectsErrors(Unit unit) {
return unit.errors != null && !unit.errors.isEmpty();
Expand Down Expand Up @@ -127,6 +145,7 @@ static void runTestCase(Unit unit, Map<String, Object> params) {
if (unit.params != null) {
params = unit.params;
rewriteDates(params);
rewriteDecimals(params);
}
String result = mf.formatToString(params);
if (expectsErrors(unit)) {
Expand Down
3 changes: 1 addition & 2 deletions testdata/message2/more-functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@
"src": "Default number: {$val}!",
"exp": "Default number: 1.234.567.890.123.456.789,987654!",
"locale": "ro",
"params": {"val": {"decimal": "1234567890123456789.987654321"}},
"ignoreJava": "ICU4J: Not sure if there's a way to specify a decimal string as a param"
"params": {"val": {"decimal": "1234567890123456789.987654321"}}
}
]
}

0 comments on commit ecfa426

Please sign in to comment.