ICU-13634 Updating Java test expectations with new behavior for fallback currency display. Other minor ICU4J test updates. All ICU4J tests are passing.

X-SVN-Rev: 41228
This commit is contained in:
Shane Carr 2018-04-14 06:17:39 +00:00
parent 79f4944ecd
commit cd3b2c7d41
9 changed files with 54 additions and 19 deletions

View file

@ -245,7 +245,8 @@ double DecimalQuantity::getPluralOperand(PluralOperand operand) const {
switch (operand) {
case PLURAL_OPERAND_I:
return static_cast<double>(toLong());
// Invert the negative sign if necessary
return static_cast<double>(isNegative() ? -toLong() : toLong());
case PLURAL_OPERAND_F:
return static_cast<double>(toFractionLong(true));
case PLURAL_OPERAND_T:

View file

@ -49,10 +49,6 @@ public class CustomSymbolCurrency extends Currency {
@Override
public String getName(ULocale locale, int nameStyle, String pluralCount, boolean[] isChoiceFormat) {
if (nameStyle == PLURAL_LONG_NAME && subType.equals("XXX")) {
// Plural in absence of a currency should return the symbol
return symbol1;
}
return super.getName(locale, nameStyle, pluralCount, isChoiceFormat);
}

View file

@ -241,7 +241,8 @@ public abstract class DecimalQuantity_AbstractBCD implements DecimalQuantity {
switch (operand) {
case i:
return toLong();
// Invert the negative sign if necessary
return isNegative() ? -toLong() : toLong();
case f:
return toFractionLong(true);
case t:
@ -571,7 +572,7 @@ public abstract class DecimalQuantity_AbstractBCD implements DecimalQuantity {
* Returns a long approximating the internal BCD. A long can only represent the integral part of the
* number.
*
* @return A double representation of the internal BCD.
* @return A 64-bit integer representation of the internal BCD.
*/
public long toLong() {
long result = 0L;

View file

@ -5,15 +5,31 @@ package com.ibm.icu.number;
/**
* Exception used for illegal number skeleton strings.
*
* @author sffc
* @draft ICU 62
* @provisional This API might change or be removed in a future release.
* @see NumberFormatter
*/
public class SkeletonSyntaxException extends IllegalArgumentException {
private static final long serialVersionUID = 7733971331648360554L;
/**
* Construct a new SkeletonSyntaxException with information about the token at the point of failure.
*
* @draft ICU 62
* @provisional This API might change or be removed in a future release.
* @see NumberFormatter
*/
public SkeletonSyntaxException(String message, CharSequence token) {
super("Syntax error in skeleton string: " + message + ": " + token);
}
/**
* Construct a new SkeletonSyntaxException with information about the token at the point of failure.
*
* @draft ICU 62
* @provisional This API might change or be removed in a future release.
* @see NumberFormatter
*/
public SkeletonSyntaxException(String message, CharSequence token, Throwable cause) {
super("Syntax error in skeleton string: " + message + ": " + token, cause);
}

View file

@ -393,8 +393,8 @@ public class NumberFormatRegressionTest extends TestFmwk {
ULocale locale = new ULocale("en");
DecimalFormat nf = (DecimalFormat) NumberFormat.getInstance(locale, NumberFormat.PLURALCURRENCYSTYLE);
assertEquals(
"Positive suffix should contain the single currency sign when no currency is set",
" \u00A4",
"Positive suffix should contain the localized display name for currency XXX",
" (unknown currency)",
nf.getPositiveSuffix());
}
}

View file

@ -38,6 +38,7 @@ import java.text.ParsePosition;
import java.util.Date;
import java.util.Locale;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -49,6 +50,7 @@ import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.DecimalFormat;
import com.ibm.icu.text.DecimalFormatSymbols;
import com.ibm.icu.text.NumberFormat;
import com.ibm.icu.util.Currency;
import com.ibm.icu.util.GregorianCalendar;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.VersionInfo;
@ -410,9 +412,7 @@ public class NumberRegressionTests extends TestFmwk {
logln("Long.MIN_VALUE : " + df.parse(str, new ParsePosition(0)).toString());
df.setMultiplier(100);
Number num = df.parse(str, new ParsePosition(0));
if (num.doubleValue() != -9.223372036854776E16) {
errln("Bug 4092561 test failed when multiplier is set to not 1.");
}
assertEquals("Bug 4092561 test failed when multiplier is set to not 1.", -9.223372036854776E16, num.doubleValue());
Locale.setDefault(savedLocale);
}
@ -998,8 +998,12 @@ public class NumberRegressionTests extends TestFmwk {
* 1) Make sure that all currency formats use the generic currency symbol.
* 2) Make sure we get the same results using the generic symbol or a
* hard-coded one.
*
* ICU 62: DecimalFormatSymbols currency symbol has long been deprecated.
* In the absence of a user-specified currency, XXX is used instead.
*/
@Test
@Ignore
public void Test4122840()
{
Locale[] locales = NumberFormat.getAvailableLocales();
@ -1555,10 +1559,13 @@ public class NumberRegressionTests extends TestFmwk {
String pat = df.toPattern();
DecimalFormatSymbols symb = new DecimalFormatSymbols(avail[i]);
DecimalFormat f2 = new DecimalFormat(pat, symb);
f2.setCurrency(df.getCurrency()); // Currency does not travel with the pattern string
if (df.getCurrency() != Currency.getInstance("XXX") && j == 1) {
// Currency does not travel with the pattern string
f2.setCurrency(df.getCurrency());
}
if (!df.equals(f2)) {
errln("FAIL: " + avail[i] + " #" + j + " -> \"" + pat +
"\" -> \"" + f2.toPattern() + '"');
"\" -> \"" + f2.toPattern() + "\" for case " + j);
}
// Test toLocalizedPattern/applyLocalizedPattern round trip

View file

@ -443,16 +443,17 @@ public class TestMessageFormat extends TestFmwk {
String formatStr = "At <time> on {1,date}, you made a {2} of {0,number,currency}.";
// {sfb} to get $, would need Locale::US, not Locale::ENGLISH
// Just use unlocalized currency symbol.
// ICU 62: use the unknown currency symbol XXX.
//String compareStrEng = "At <time> on Aug 8, 1997, you made a deposit of $456.83.";
String compareStrEng = "At <time> on Aug 8, 1997, you made a deposit of ";
compareStrEng += '\u00a4';
compareStrEng += "XXX\u00a0";
compareStrEng += "456.83.";
// {sfb} to get DM, would need Locale::GERMANY, not Locale::GERMAN
// Just use unlocalized currency symbol.
//String compareStrGer = "At <time> on 08.08.1997, you made a deposit of 456,83 DM.";
String compareStrGer = "At <time> on 08.08.1997, you made a deposit of ";
compareStrGer += "456,83\u00a0";
compareStrGer += '\u00a4';
compareStrGer += "XXX";
compareStrGer += ".";
MessageFormat msg = new MessageFormat(formatStr, Locale.ENGLISH);
@ -912,12 +913,12 @@ public class TestMessageFormat extends TestFmwk {
String compareStr = "At <time> on Aug 8, 1997, you made a deposit of $456.83.";
// the date being German-style, but the currency being English-style
String compareStr2 = "At <time> on 08.08.1997, you made a deposit of ";
compareStr2 += '\u00a4';
compareStr2 += "XXX\u00A0";
compareStr2 += "456.83.";
// both date and currency formats are German-style
String compareStr3 = "At <time> on 08.08.1997, you made a deposit of ";
compareStr3 += "456,83\u00a0";
compareStr3 += '\u00a4';
compareStr3 += "XXX";
compareStr3 += ".";
MessageFormat msg = new MessageFormat(formatStr, ULocale.US);

View file

@ -15,6 +15,7 @@ import java.util.Locale;
import com.ibm.icu.impl.IllegalIcuArgumentException;
import com.ibm.icu.impl.InvalidFormatException;
import com.ibm.icu.impl.locale.LocaleSyntaxException;
import com.ibm.icu.number.SkeletonSyntaxException;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.util.IllformedLocaleException;
@ -147,4 +148,15 @@ public abstract class ExceptionHandler implements SerializableTestUtility.Handle
return exceptions;
}
}
static class SkeletonSyntaxExceptionHandler extends ExceptionHandler
{
public Object[] getTestObjects()
{
SkeletonSyntaxException[] exceptions = {
new SkeletonSyntaxException("Bad number skeleton", "[foo]")
};
return exceptions;
}
}
}

View file

@ -832,6 +832,7 @@ public class SerializableTestUtility {
map.put("com.ibm.icu.impl.number.Properties", new PropertiesTest.ICU59PropertiesHandler());
map.put("com.ibm.icu.impl.number.DecimalFormatProperties", new PropertiesTest.PropertiesHandler());
map.put("com.ibm.icu.impl.number.CustomSymbolCurrency", new CurrencyHandler());
map.put("com.ibm.icu.number.SkeletonSyntaxException", new ExceptionHandler.SkeletonSyntaxExceptionHandler());
map.put("com.ibm.icu.util.ICUException", new ICUExceptionHandler());
map.put("com.ibm.icu.util.ICUUncheckedIOException", new ICUUncheckedIOExceptionHandler());