[Yaml] deprecate comma separators in floats
This commit is contained in:
parent
ea9d6e7235
commit
3f3623df27
@ -591,6 +591,7 @@ class Inline
|
||||
case 0 === strpos($scalar, '!!binary '):
|
||||
return self::evaluateBinaryScalar(substr($scalar, 9));
|
||||
case preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar):
|
||||
@trigger_error('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
case preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
|
||||
return (float) str_replace(array(',', '_'), '', $scalar);
|
||||
case preg_match(self::getTimestampRegex(), $scalar):
|
||||
|
@ -509,24 +509,31 @@ test: Integers
|
||||
spec: 2.19
|
||||
yaml: |
|
||||
canonical: 12345
|
||||
decimal: +12,345
|
||||
octal: 014
|
||||
hexadecimal: 0xC
|
||||
php: |
|
||||
array(
|
||||
'canonical' => 12345,
|
||||
'decimal' => 12345.0,
|
||||
'octal' => 014,
|
||||
'hexadecimal' => 0xC
|
||||
)
|
||||
---
|
||||
test: Decimal Integer
|
||||
deprecated: true
|
||||
spec: 2.19
|
||||
yaml: |
|
||||
decimal: +12,345
|
||||
php: |
|
||||
array(
|
||||
'decimal' => 12345.0,
|
||||
)
|
||||
---
|
||||
# FIX: spec shows parens around -inf and NaN
|
||||
test: Floating point
|
||||
spec: 2.20
|
||||
yaml: |
|
||||
canonical: 1.23015e+3
|
||||
exponential: 12.3015e+02
|
||||
fixed: 1,230.15
|
||||
negative infinity: -.inf
|
||||
not a number: .NaN
|
||||
float as whole number: !!float 1
|
||||
@ -534,12 +541,21 @@ php: |
|
||||
array(
|
||||
'canonical' => 1230.15,
|
||||
'exponential' => 1230.15,
|
||||
'fixed' => 1230.15,
|
||||
'negative infinity' => log(0),
|
||||
'not a number' => -log(0),
|
||||
'float as whole number' => (float) 1
|
||||
)
|
||||
---
|
||||
test: Fixed Floating point
|
||||
deprecated: true
|
||||
spec: 2.20
|
||||
yaml: |
|
||||
fixed: 1,230.15
|
||||
php: |
|
||||
array(
|
||||
'fixed' => 1230.15,
|
||||
)
|
||||
---
|
||||
test: Miscellaneous
|
||||
spec: 2.21
|
||||
yaml: |
|
||||
@ -1532,29 +1548,42 @@ php: |
|
||||
test: Integer
|
||||
yaml: |
|
||||
canonical: 12345
|
||||
decimal: +12,345
|
||||
octal: 014
|
||||
hexadecimal: 0xC
|
||||
php: |
|
||||
array(
|
||||
'canonical' => 12345,
|
||||
'decimal' => 12345.0,
|
||||
'octal' => 12,
|
||||
'hexadecimal' => 12
|
||||
)
|
||||
---
|
||||
test: Decimal
|
||||
deprecated: true
|
||||
yaml: |
|
||||
decimal: +12,345
|
||||
php: |
|
||||
array(
|
||||
'decimal' => 12345.0,
|
||||
)
|
||||
---
|
||||
test: Fixed Float
|
||||
deprecated: true
|
||||
yaml: |
|
||||
fixed: 1,230.15
|
||||
php: |
|
||||
array(
|
||||
'fixed' => 1230.15,
|
||||
)
|
||||
test: Float
|
||||
yaml: |
|
||||
canonical: 1.23015e+3
|
||||
exponential: 12.3015e+02
|
||||
fixed: 1,230.15
|
||||
negative infinity: -.inf
|
||||
not a number: .NaN
|
||||
php: |
|
||||
array(
|
||||
'canonical' => 1230.15,
|
||||
'exponential' => 1230.15,
|
||||
'fixed' => 1230.15,
|
||||
'negative infinity' => log(0),
|
||||
'not a number' => -log(0)
|
||||
)
|
||||
|
@ -176,13 +176,37 @@ brief: >
|
||||
yaml: |
|
||||
zero: 0
|
||||
simple: 12
|
||||
one-thousand: 1,000
|
||||
negative one-thousand: -1,000
|
||||
php: |
|
||||
array(
|
||||
'zero' => 0,
|
||||
'simple' => 12,
|
||||
)
|
||||
---
|
||||
test: Positive Big Integer
|
||||
deprecated: true
|
||||
dump_skip: true
|
||||
brief: >
|
||||
An integer is a series of numbers, optionally
|
||||
starting with a positive or negative sign. Integers
|
||||
may also contain commas for readability.
|
||||
yaml: |
|
||||
one-thousand: 1,000
|
||||
php: |
|
||||
array(
|
||||
'one-thousand' => 1000.0,
|
||||
)
|
||||
---
|
||||
test: Negative Big Integer
|
||||
deprecated: true
|
||||
dump_skip: true
|
||||
brief: >
|
||||
An integer is a series of numbers, optionally
|
||||
starting with a positive or negative sign. Integers
|
||||
may also contain commas for readability.
|
||||
yaml: |
|
||||
negative one-thousand: -1,000
|
||||
php: |
|
||||
array(
|
||||
'negative one-thousand' => -1000.0
|
||||
)
|
||||
---
|
||||
@ -208,15 +232,27 @@ brief: >
|
||||
positive and negative infinity and "not a number."
|
||||
yaml: |
|
||||
a simple float: 2.00
|
||||
larger float: 1,000.09
|
||||
scientific notation: 1.00009e+3
|
||||
php: |
|
||||
array(
|
||||
'a simple float' => 2.0,
|
||||
'larger float' => 1000.09,
|
||||
'scientific notation' => 1000.09
|
||||
)
|
||||
---
|
||||
test: Larger Float
|
||||
dump_skip: true
|
||||
deprecated: true
|
||||
brief: >
|
||||
Floats are represented by numbers with decimals,
|
||||
allowing for scientific notation, as well as
|
||||
positive and negative infinity and "not a number."
|
||||
yaml: |
|
||||
larger float: 1,000.09
|
||||
php: |
|
||||
array(
|
||||
'larger float' => 1000.09,
|
||||
)
|
||||
---
|
||||
test: Time
|
||||
todo: true
|
||||
brief: >
|
||||
|
@ -31,9 +31,30 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @dataProvider getDataFormSpecifications
|
||||
*/
|
||||
public function testSpecifications($file, $expected, $yaml, $comment)
|
||||
public function testSpecifications($file, $expected, $yaml, $comment, $deprecated)
|
||||
{
|
||||
$deprecations = array();
|
||||
|
||||
if ($deprecated) {
|
||||
set_error_handler(function ($type, $msg) use (&$deprecations) {
|
||||
if (E_USER_DEPRECATED !== $type) {
|
||||
restore_error_handler();
|
||||
|
||||
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
|
||||
}
|
||||
|
||||
$deprecations[] = $msg;
|
||||
});
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment);
|
||||
|
||||
if ($deprecated) {
|
||||
restore_error_handler();
|
||||
|
||||
$this->assertCount(1, $deprecations);
|
||||
$this->assertContains('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', $deprecations[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDataFormSpecifications()
|
||||
@ -58,7 +79,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
} else {
|
||||
eval('$expected = '.trim($test['php']).';');
|
||||
|
||||
$tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test']);
|
||||
$tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test'], isset($test['deprecated']) ? $test['deprecated'] : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user