Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 28507b8

Browse filesBrowse files
committed
[Intl] Update intl tests to match the ICU 63.1 behaviour
1 parent e62b061 commit 28507b8
Copy full SHA for 28507b8

File tree

3 files changed

+67
-40
lines changed
Filter options

3 files changed

+67
-40
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function transform($value)
121121
}
122122

123123
// Convert fixed spaces to normal ones
124-
$value = str_replace("\xc2\xa0", ' ', $value);
124+
$value = str_replace(array("\xc2\xa0", "\xe2\x80\xaf"), ' ', $value);
125125

126126
return $value;
127127
}

‎src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php
+14-15Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ class NumberFormatter
236236
);
237237

238238
private static $enTextAttributes = array(
239-
self::DECIMAL => array('', '', '-', '', ' ', '', ''),
240-
self::CURRENCY => array('¤', '', '', '', ' ', ''),
239+
self::DECIMAL => array('', '', '-', '', ' ', 'XXX', ''),
240+
self::CURRENCY => array('¤', '', '', '', ' ', 'XXX'),
241241
);
242242

243243
/**
@@ -331,7 +331,7 @@ public function formatCurrency($value, $currency)
331331

332332
$value = $this->formatNumber($value, $fractionDigits);
333333

334-
$ret = $symbol.$value;
334+
$ret = $symbol.(mb_strlen($symbol) > 2 ? "\xc2\xa0" : '').$value;
335335

336336
return $negative ? '-'.$ret : $ret;
337337
}
@@ -513,17 +513,15 @@ public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
513513
return false;
514514
}
515515

516-
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
517-
518-
// Any string before the numeric value causes error in the parsing
519-
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d*+)?)/", $value, $matches)) {
516+
$groupingMatch = $this->getAttribute(self::GROUPING_USED) ? '|(?P<grouping>\d++(,{1}\d+)++(\.\d*+)?)' : '';
517+
if (preg_match("/^-?(?:\.\d++{$groupingMatch}|\d++(\.\d*+)?)/", $value, $matches)) {
520518
$value = $matches[0];
521519
$position = \strlen($value);
522-
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
523-
$position -= \strlen(preg_replace('/^\d{1,3}+(?:(?:,\d++)++|\d*+)/', '', $matches[1]));
520+
if ($error = isset($matches['grouping']) && !preg_match('/^-?(?:\d{1,3}+)?(?:(?:,\d{3})++|\d*+)(?:\.\d*+)?$/', $value)) {
521+
$position = 0 === strpos($value, '-') ? 1 : 0;
524522
}
525523
} else {
526-
$error = 1;
524+
$error = true;
527525
$position = 0;
528526
}
529527

@@ -585,6 +583,10 @@ public function setAttribute($attr, $value)
585583

586584
if (self::$supportedAttributes['FRACTION_DIGITS'] == $attr) {
587585
$value = $this->normalizeFractionDigitsValue($value);
586+
if ($value < 0) {
587+
// ignore negative values but do not raise an error
588+
return true;
589+
}
588590
}
589591

590592
$this->attributes[$attr] = $value;
@@ -868,17 +870,14 @@ private function normalizeGroupingUsedValue($value)
868870
}
869871

870872
/**
871-
* Returns the normalized value for the FRACTION_DIGITS attribute. The value is converted to int and if negative,
872-
* the returned value will be 0.
873+
* Returns the normalized value for the FRACTION_DIGITS attribute.
873874
*
874875
* @param mixed $value The value to be normalized
875876
*
876877
* @return int The normalized value for the attribute
877878
*/
878879
private function normalizeFractionDigitsValue($value)
879880
{
880-
$value = (int) $value;
881-
882-
return (0 > $value) ? 0 : $value;
881+
return (int) $value;
883882
}
884883
}

‎src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php
+52-24Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public function testFormatCurrencyWithCurrencyStyle($value, $currency, $expected
6464
public function formatCurrencyWithCurrencyStyleProvider()
6565
{
6666
return array(
67-
array(100, 'ALL', 'ALL100'),
68-
array(-100, 'ALL', '-ALL100'),
69-
array(1000.12, 'ALL', 'ALL1,000'),
67+
array(100, 'ALL', "ALL\xc2\xa0100"),
68+
array(-100, 'ALL', "-ALL\xc2\xa0100"),
69+
array(1000.12, 'ALL', "ALL\xc2\xa01,000"),
7070

7171
array(100, 'JPY', '¥100'),
7272
array(-100, 'JPY', '-¥100'),
@@ -92,9 +92,9 @@ public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRounding($val
9292
public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider()
9393
{
9494
return array(
95-
array(100, 'CRC', 'CRC', '%s100.00'),
96-
array(-100, 'CRC', 'CRC', '-%s100.00'),
97-
array(1000.12, 'CRC', 'CRC', '%s1,000.12'),
95+
array(100, 'CRC', 'CRC', "%s\xc2\xa0100.00"),
96+
array(-100, 'CRC', 'CRC', "-%s\xc2\xa0100.00"),
97+
array(1000.12, 'CRC', 'CRC', "%s\xc2\xa01,000.12"),
9898
);
9999
}
100100

@@ -137,22 +137,22 @@ public function testFormatCurrencyWithCurrencyStyleSwissRounding($value, $curren
137137
public function formatCurrencyWithCurrencyStyleSwissRoundingProvider()
138138
{
139139
return array(
140-
array(100, 'CHF', 'CHF', '%s100.00'),
141-
array(-100, 'CHF', 'CHF', '-%s100.00'),
142-
array(1000.12, 'CHF', 'CHF', '%s1,000.12'),
143-
array('1000.12', 'CHF', 'CHF', '%s1,000.12'),
140+
array(100, 'CHF', 'CHF', "%s\xc2\xa0100.00"),
141+
array(-100, 'CHF', 'CHF', "-%s\xc2\xa0100.00"),
142+
array(1000.12, 'CHF', 'CHF', "%s\xc2\xa01,000.12"),
143+
array('1000.12', 'CHF', 'CHF', "%s\xc2\xa01,000.12"),
144144

145145
// Rounding checks
146-
array(1000.121, 'CHF', 'CHF', '%s1,000.12'),
147-
array(1000.123, 'CHF', 'CHF', '%s1,000.12'),
148-
array(1000.125, 'CHF', 'CHF', '%s1,000.12'),
149-
array(1000.127, 'CHF', 'CHF', '%s1,000.13'),
150-
array(1000.129, 'CHF', 'CHF', '%s1,000.13'),
151-
152-
array(1200000.00, 'CHF', 'CHF', '%s1,200,000.00'),
153-
array(1200000.1, 'CHF', 'CHF', '%s1,200,000.10'),
154-
array(1200000.10, 'CHF', 'CHF', '%s1,200,000.10'),
155-
array(1200000.101, 'CHF', 'CHF', '%s1,200,000.10'),
146+
array(1000.121, 'CHF', 'CHF', "%s\xc2\xa01,000.12"),
147+
array(1000.123, 'CHF', 'CHF', "%s\xc2\xa01,000.12"),
148+
array(1000.125, 'CHF', 'CHF', "%s\xc2\xa01,000.12"),
149+
array(1000.127, 'CHF', 'CHF', "%s\xc2\xa01,000.13"),
150+
array(1000.129, 'CHF', 'CHF', "%s\xc2\xa01,000.13"),
151+
152+
array(1200000.00, 'CHF', 'CHF', "%s\xc2\xa01,200,000.00"),
153+
array(1200000.1, 'CHF', 'CHF', "%s\xc2\xa01,200,000.10"),
154+
array(1200000.10, 'CHF', 'CHF', "%s\xc2\xa01,200,000.10"),
155+
array(1200000.101, 'CHF', 'CHF', "%s\xc2\xa01,200,000.10"),
156156
);
157157
}
158158

@@ -369,7 +369,7 @@ public function formatFractionDigitsProvider()
369369
array(1.123, '1', 0, 0),
370370
array(1.123, '1.1', 1, 1),
371371
array(1.123, '1.12', 2, 2),
372-
array(1.123, '1', -1, 0),
372+
array(1.123, '1.123', -1, 0),
373373
array(1.123, '1', 'abc', 0),
374374
);
375375
}
@@ -648,12 +648,40 @@ public function parseProvider()
648648
{
649649
return array(
650650
array('prefix1', false, '->parse() does not parse a number with a string prefix.', 0),
651+
array('prefix1', false, '->parse() does not parse a number with a string prefix.', 0, false),
651652
array('1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3),
653+
array('1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3, false),
654+
array('1,234.4suffix', 1234.4, '->parse() parses a number with a string suffix.', 7),
655+
array('1,234.4suffix', 1.0, '->parse() parses a number with a string suffix.', 1, false),
652656
array('-.4suffix', (float) -0.4, '->parse() parses a negative dot float with suffix.', 3),
653-
array('-123,4', false, '->parse() does not parse when invalid grouping used.', 6),
654-
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
655-
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
657+
array('-.4suffix', (float) -0.4, '->parse() parses a negative dot float with suffix.', 3, false),
658+
array(',4', false, '->parse() does not parse when invalid grouping used.', 0),
659+
array(',4', false, '->parse() does not parse when invalid grouping used.', 0, false),
660+
array('123,4', false, '->parse() does not parse when invalid grouping used.', 0),
661+
array('123,4', 123.0, '->parse() truncates invalid grouping when grouping is disabled.', 3, false),
662+
array('123,a4', 123.0, '->parse() truncates a string suffix.', 3),
663+
array('123,a4', 123.0, '->parse() truncates a string suffix.', 3, false),
664+
array('-123,4', false, '->parse() does not parse when invalid grouping used.', 1),
665+
array('-123,4', -123.0, '->parse() truncates invalid grouping when grouping is disabled.', 4, false),
666+
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 1),
667+
array('-123,4567', -123.0, '->parse() truncates invalid grouping when grouping is disabled.', 4, false),
668+
array('-123,456,789', -123456789.0, '->parse() parses a number with grouping.', 12),
669+
array('-123,456,789', -123.0, '->parse() truncates a group if grouping is disabled.', 4, false),
670+
array('-123,456,789.66', -123456789.66, '->parse() parses a number with grouping.', 15),
671+
array('-123,456,789.66', -123.00, '->parse() truncates a group if grouping is disabled.', 4, false),
672+
array('-123,456789.66', false, '->parse() does not parse when invalid grouping used.', 1),
673+
array('-123,456789.66', -123.00, '->parse() truncates a group if grouping is disabled.', 4, false),
674+
array('-123456,789.66', false, '->parse() does not parse when invalid grouping used.', 1),
675+
array('-123456,789.66', -123456.00, '->parse() truncates a group if grouping is disabled.', 7, false),
676+
array('-123,456,78', false, '->parse() does not parse when invalid grouping used.', 1),
677+
array('-123,456,78', -123.0, '->parse() truncates a group if grouping is disabled.', 4, false),
678+
array('-123,45,789', false, '->parse() does not parse when invalid grouping used.', 1),
679+
array('-123,45,789', -123.0, '->parse() truncates a group if grouping is disabled.', 4, false),
680+
array('-123,,456', -123.0, '->parse() parses when grouping is duplicated.', 4),
656681
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
682+
array('-123,,4', -123.0, '->parse() parses when grouping is duplicated.', 4),
683+
array('-123,,4', -123.0, '->parse() parses when grouping is duplicated.', 4, false),
684+
array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4),
657685
array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false),
658686
);
659687
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.