LEFT | RIGHT |
(no file at all) | |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.dev.test.format; | 3 package com.ibm.icu.dev.test.format; |
4 | 4 |
5 import java.math.BigDecimal; | 5 import java.math.BigDecimal; |
6 import java.math.RoundingMode; | 6 import java.math.RoundingMode; |
7 import java.text.ParseException; | 7 import java.text.ParseException; |
8 import java.text.ParsePosition; | 8 import java.text.ParsePosition; |
9 | 9 |
| 10 import org.junit.Ignore; |
10 import org.junit.Test; | 11 import org.junit.Test; |
11 | 12 |
12 import com.ibm.icu.dev.test.TestUtil; | 13 import com.ibm.icu.dev.test.TestUtil; |
13 import com.ibm.icu.impl.number.DecimalFormatProperties; | 14 import com.ibm.icu.impl.number.DecimalFormatProperties; |
14 import com.ibm.icu.impl.number.Padder.PadPosition; | 15 import com.ibm.icu.impl.number.Padder.PadPosition; |
15 import com.ibm.icu.impl.number.Parse; | 16 import com.ibm.icu.impl.number.Parse; |
16 import com.ibm.icu.impl.number.Parse.ParseMode; | 17 import com.ibm.icu.impl.number.Parse.ParseMode; |
17 import com.ibm.icu.impl.number.PatternStringParser; | 18 import com.ibm.icu.impl.number.PatternStringParser; |
18 import com.ibm.icu.impl.number.PatternStringUtils; | 19 import com.ibm.icu.impl.number.PatternStringUtils; |
| 20 import com.ibm.icu.impl.number.parse.NumberParserImpl; |
19 import com.ibm.icu.number.LocalizedNumberFormatter; | 21 import com.ibm.icu.number.LocalizedNumberFormatter; |
20 import com.ibm.icu.number.NumberFormatter; | 22 import com.ibm.icu.number.NumberFormatter; |
21 import com.ibm.icu.text.DecimalFormat; | 23 import com.ibm.icu.text.DecimalFormat; |
22 import com.ibm.icu.text.DecimalFormat.PropertySetter; | 24 import com.ibm.icu.text.DecimalFormat.PropertySetter; |
23 import com.ibm.icu.text.DecimalFormatSymbols; | 25 import com.ibm.icu.text.DecimalFormatSymbols; |
24 import com.ibm.icu.text.DecimalFormat_ICU58; | 26 import com.ibm.icu.text.DecimalFormat_ICU58; |
25 import com.ibm.icu.util.CurrencyAmount; | 27 import com.ibm.icu.util.CurrencyAmount; |
26 import com.ibm.icu.util.ULocale; | 28 import com.ibm.icu.util.ULocale; |
27 | 29 |
28 public class NumberFormatDataDrivenTest { | 30 public class NumberFormatDataDrivenTest { |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 Number number = toNumber(tuple.format); | 568 Number number = toNumber(tuple.format); |
567 String expected = tuple.output; | 569 String expected = tuple.output; |
568 String actual = fmt.format(number).toString(); | 570 String actual = fmt.format(number).toString(); |
569 if (!expected.equals(actual)) { | 571 if (!expected.equals(actual)) { |
570 return "Expected \"" + expected + "\", got \"" + actual + "\""; | 572 return "Expected \"" + expected + "\", got \"" + actual + "\""; |
571 } | 573 } |
572 return null; | 574 return null; |
573 } | 575 } |
574 }; | 576 }; |
575 | 577 |
| 578 /** |
| 579 * Parsing, but no other features. |
| 580 */ |
| 581 private DataDrivenNumberFormatTestUtility.CodeUnderTest ICU61_Parsing = |
| 582 new DataDrivenNumberFormatTestUtility.CodeUnderTest() { |
| 583 |
| 584 @Override |
| 585 public Character Id() { |
| 586 return 'P'; |
| 587 } |
| 588 |
| 589 @Override |
| 590 public String parse(DataDrivenNumberFormatTestData tuple) { |
| 591 String pattern = (tuple.pattern == null) ? "0" : tuple.pattern; |
| 592 DecimalFormatProperties properties; |
| 593 ParsePosition ppos = new ParsePosition(0); |
| 594 Number actual; |
| 595 try { |
| 596 properties = PatternStringParser.parseToProperties(pattern, |
| 597 tuple.currency != null ? PatternStringParser.IGNORE_
ROUNDING_ALWAYS |
| 598 : PatternStringParser.IGNORE_ROUNDING_NEVER)
; |
| 599 propertiesFromTuple(tuple, properties); |
| 600 actual = NumberParserImpl.parseStatic(tuple.parse, |
| 601 ppos, |
| 602 properties, |
| 603 DecimalFormatSymbols.getInstance(tuple.locale)); |
| 604 } catch (IllegalArgumentException e) { |
| 605 return "parse exception: " + e.getMessage(); |
| 606 } |
| 607 if (actual == null && ppos.getIndex() != 0) { |
| 608 throw new AssertionError("Error: value is null but parse pos
ition is not zero"); |
| 609 } |
| 610 if (ppos.getIndex() == 0) { |
| 611 return "Parse failed; got " + actual + ", but expected " + t
uple.output; |
| 612 } |
| 613 if (tuple.output.equals("NaN")) { |
| 614 if (!Double.isNaN(actual.doubleValue())) { |
| 615 return "Expected NaN, but got: " + actual; |
| 616 } |
| 617 return null; |
| 618 } else if (tuple.output.equals("Inf")) { |
| 619 if (!Double.isInfinite(actual.doubleValue()) || Double.compa
re(actual.doubleValue(), 0.0) < 0) { |
| 620 return "Expected Inf, but got: " + actual; |
| 621 } |
| 622 return null; |
| 623 } else if (tuple.output.equals("-Inf")) { |
| 624 if (!Double.isInfinite(actual.doubleValue()) || Double.compa
re(actual.doubleValue(), 0.0) > 0) { |
| 625 return "Expected -Inf, but got: " + actual; |
| 626 } |
| 627 return null; |
| 628 } else if (tuple.output.equals("fail")) { |
| 629 return null; |
| 630 } else if (new BigDecimal(tuple.output).compareTo(new BigDecimal
(actual.toString())) != 0) { |
| 631 return "Expected: " + tuple.output + ", got: " + actual; |
| 632 } else { |
| 633 return null; |
| 634 } |
| 635 } |
| 636 |
| 637 @Override |
| 638 public String parseCurrency(DataDrivenNumberFormatTestData tuple) { |
| 639 String pattern = (tuple.pattern == null) ? "0" : tuple.pattern; |
| 640 DecimalFormatProperties properties; |
| 641 ParsePosition ppos = new ParsePosition(0); |
| 642 CurrencyAmount actual; |
| 643 try { |
| 644 properties = PatternStringParser.parseToProperties( |
| 645 pattern, |
| 646 tuple.currency != null ? PatternStringParser.IGNORE_
ROUNDING_ALWAYS |
| 647 : PatternStringParser.IGNORE_ROUNDING_NEVER)
; |
| 648 propertiesFromTuple(tuple, properties); |
| 649 actual = NumberParserImpl.parseStaticCurrency(tuple.parse, |
| 650 ppos, |
| 651 properties, |
| 652 DecimalFormatSymbols.getInstance(tuple.locale)); |
| 653 } catch (IllegalArgumentException e) { |
| 654 e.printStackTrace(); |
| 655 return "parse exception: " + e.getMessage(); |
| 656 } |
| 657 if (ppos.getIndex() == 0 || actual.getCurrency().getCurrencyCode
().equals("XXX")) { |
| 658 return "Parse failed; got " + actual + ", but expected " + t
uple.output; |
| 659 } |
| 660 BigDecimal expectedNumber = new BigDecimal(tuple.output); |
| 661 if (expectedNumber.compareTo(new BigDecimal(actual.getNumber().t
oString())) != 0) { |
| 662 return "Wrong number: Expected: " + expectedNumber + ", got:
" + actual; |
| 663 } |
| 664 String expectedCurrency = tuple.outputCurrency; |
| 665 if (!expectedCurrency.equals(actual.getCurrency().toString())) { |
| 666 return "Wrong currency: Expected: " + expectedCurrency + ",
got: " + actual; |
| 667 } |
| 668 return null; |
| 669 } |
| 670 }; |
| 671 |
576 /** | 672 /** |
577 * All features except formatting. | 673 * All features except formatting. |
578 */ | 674 */ |
579 private DataDrivenNumberFormatTestUtility.CodeUnderTest ICU60_Other = | 675 private DataDrivenNumberFormatTestUtility.CodeUnderTest ICU59_Other = |
580 new DataDrivenNumberFormatTestUtility.CodeUnderTest() { | 676 new DataDrivenNumberFormatTestUtility.CodeUnderTest() { |
581 | 677 |
582 @Override | 678 @Override |
583 public Character Id() { | 679 public Character Id() { |
584 return 'S'; | 680 return 'S'; |
585 } | 681 } |
586 | 682 |
587 /** | 683 /** |
588 * Runs a single toPattern test. On success, returns null. On failure, r
eturns the error. This implementation | 684 * Runs a single toPattern test. On success, returns null. On failure, r
eturns the error. This implementation |
589 * just returns null. Subclasses should override. | 685 * just returns null. Subclasses should override. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 * @param tuple | 827 * @param tuple |
732 * contains the parameters of the format test. | 828 * contains the parameters of the format test. |
733 */ | 829 */ |
734 @Override | 830 @Override |
735 public String select(DataDrivenNumberFormatTestData tuple) { | 831 public String select(DataDrivenNumberFormatTestData tuple) { |
736 return null; | 832 return null; |
737 } | 833 } |
738 }; | 834 }; |
739 | 835 |
740 @Test | 836 @Test |
| 837 @Ignore |
741 public void TestDataDrivenICU58() { | 838 public void TestDataDrivenICU58() { |
742 // Android can't access DecimalFormat_ICU58 for testing (ticket #13283). | 839 // Android can't access DecimalFormat_ICU58 for testing (ticket #13283). |
743 if (TestUtil.getJavaVendor() == TestUtil.JavaVendor.Android) return; | 840 if (TestUtil.getJavaVendor() == TestUtil.JavaVendor.Android) return; |
744 | 841 |
745 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( | 842 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( |
746 "numberformattestspecification.txt", ICU58); | 843 "numberformattestspecification.txt", ICU58); |
747 } | 844 } |
748 | 845 |
749 // Note: This test case is really questionable. Depending on Java version, | 846 // Note: This test case is really questionable. Depending on Java version, |
750 // something may or may not work. However the test data assumes a specific | 847 // something may or may not work. However the test data assumes a specific |
751 // Java runtime version. We should probably disable this test case - #13372 | 848 // Java runtime version. We should probably disable this test case - #13372 |
752 @Test | 849 @Test |
| 850 @Ignore |
753 public void TestDataDrivenJDK() { | 851 public void TestDataDrivenJDK() { |
754 // Android implements java.text.DecimalFormat with ICU4J (ticket #13322). | 852 // Android implements java.text.DecimalFormat with ICU4J (ticket #13322). |
755 // Oracle/OpenJDK 9's behavior is not exactly same with Oracle/OpenJDK 8. | 853 // Oracle/OpenJDK 9's behavior is not exactly same with Oracle/OpenJDK 8. |
756 // Some test cases failed on 8 work well, while some other test cases | 854 // Some test cases failed on 8 work well, while some other test cases |
757 // fail on 9, but worked on 8. Skip this test case if Java version is not 8. | 855 // fail on 9, but worked on 8. Skip this test case if Java version is not 8. |
758 org.junit.Assume.assumeTrue( | 856 org.junit.Assume.assumeTrue( |
759 TestUtil.getJavaVendor() != TestUtil.JavaVendor.Android | 857 TestUtil.getJavaVendor() != TestUtil.JavaVendor.Android |
760 && TestUtil.getJavaVersion() < 9); | 858 && TestUtil.getJavaVersion() < 9); |
761 | 859 |
762 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( | 860 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( |
763 "numberformattestspecification.txt", JDK); | 861 "numberformattestspecification.txt", JDK); |
764 } | 862 } |
765 | 863 |
766 @Test | 864 @Test |
| 865 @Ignore |
767 public void TestDataDrivenICULatest_Format() { | 866 public void TestDataDrivenICULatest_Format() { |
768 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( | 867 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( |
769 "numberformattestspecification.txt", ICU60); | 868 "numberformattestspecification.txt", ICU60); |
770 } | 869 } |
771 | 870 |
772 @Test | 871 @Test |
| 872 public void TestDataDrivenICULatest_Parsing() { |
| 873 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( |
| 874 "numberformattestspecification.txt", ICU61_Parsing); |
| 875 } |
| 876 |
| 877 @Test |
| 878 @Ignore |
773 public void TestDataDrivenICULatest_Other() { | 879 public void TestDataDrivenICULatest_Other() { |
774 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( | 880 DataDrivenNumberFormatTestUtility.runFormatSuiteIncludingKnownFailures( |
775 "numberformattestspecification.txt", ICU60_Other); | 881 "numberformattestspecification.txt", ICU59_Other); |
776 } | 882 } |
777 } | 883 } |
LEFT | RIGHT |