-
Notifications
You must be signed in to change notification settings - Fork 177
Drop the symbol separator in the currency and percent re-parse #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ class CurrencyValidatorTest { | |
|
|
||
| private static final char CURRENCY_SYMBOL = '\u00A4'; | ||
|
|
||
| /** The character locales such as de-DE use between the number and a trailing currency symbol. */ | ||
| private static final char NON_BREAKING_SPACE = '\u00A0'; | ||
|
|
||
| private String usDollar; | ||
| private String ukPound; | ||
|
|
||
|
|
@@ -176,6 +179,21 @@ void testPattern() { | |
| assertFalse(validator.isValid(ukPound + "1,234.567", pattern, Locale.US), "invalid symbol"); | ||
| } | ||
|
|
||
| /** | ||
| * Test currency values with a pattern that suffixes the symbol, which locales such as de-DE separate from the number with a non-breaking space. The symbol | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment make a claim about DE and the code about US. Add a test for each, or parameterize the current test for both, better yet, for all known currency symbols. |
||
| * is optional, so its separator has to be optional too. | ||
| */ | ||
| @Test | ||
| void testSuffixSymbolPattern() { | ||
| final BigDecimalValidator validator = CurrencyValidator.getInstance(); | ||
|
Comment on lines
+187
to
+188
|
||
| final String pattern = "#,##0.00" + NON_BREAKING_SPACE + CURRENCY_SYMBOL; | ||
| final BigDecimal expected = new BigDecimal("1234.56"); | ||
|
|
||
| assertEquals(expected, validator.validate("1,234.56" + NON_BREAKING_SPACE + usDollar, pattern, Locale.US), "symbol"); | ||
| assertEquals(expected, validator.validate("1,234.56", pattern, Locale.US), "no symbol"); | ||
| assertNull(validator.validate("1,234.56" + NON_BREAKING_SPACE, pattern, Locale.US), "separator without symbol"); | ||
| } | ||
|
|
||
| /** | ||
| * Test Valid currency values | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ | |
| */ | ||
| class PercentValidatorTest { | ||
|
|
||
| private static final char PERCENT_SYMBOL = '%'; | ||
|
|
||
| /** The character locales such as fr-FR use between the number and a trailing percent symbol. */ | ||
| private static final char NON_BREAKING_SPACE = '\u00A0'; | ||
|
|
||
| protected PercentValidator validator; | ||
| private Locale originalLocale; | ||
|
|
||
|
|
@@ -100,6 +105,21 @@ void testNumberRangeExactBound() { | |
| assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5"))); | ||
| } | ||
|
|
||
| /** | ||
| * Test percentage values with a pattern that suffixes the symbol, which locales such as fr-FR separate from the number with a non-breaking space. The | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment make a claim about FR and the code about US. Add a test for each, or parameterize the current test for both, better yet, for all known currency symbols. |
||
| * symbol is optional, so its separator has to be optional too. | ||
| */ | ||
| @Test | ||
| void testSuffixSymbolPattern() { | ||
| final BigDecimalValidator validator = PercentValidator.getInstance(); | ||
|
Comment on lines
+113
to
+114
|
||
| final String pattern = "#,##0" + NON_BREAKING_SPACE + PERCENT_SYMBOL; | ||
| final BigDecimal expected = new BigDecimal("0.12"); | ||
|
|
||
| assertEquals(expected, validator.validate("12" + NON_BREAKING_SPACE + PERCENT_SYMBOL, pattern, Locale.US), "symbol"); | ||
| assertEquals(expected, validator.validate("12", pattern, Locale.US), "no symbol"); | ||
| assertNull(validator.validate("12" + NON_BREAKING_SPACE, pattern, Locale.US), "separator without symbol"); | ||
| } | ||
|
|
||
| /** | ||
| * Test Valid percentage values | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.