|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ValueParsers\Test; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\NumberValue; |
|
6
|
|
|
use ValueParsers\FloatParser; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers ValueParsers\FloatParser |
|
10
|
|
|
* @covers ValueParsers\StringValueParser |
|
11
|
|
|
* |
|
12
|
|
|
* @group ValueParsers |
|
13
|
|
|
* @group DataValueExtensions |
|
14
|
|
|
* |
|
15
|
|
|
* @license GPL-2.0+ |
|
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
17
|
|
|
*/ |
|
18
|
|
|
class FloatParserTest extends StringValueParserTest { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @see ValueParserTestBase::getInstance |
|
22
|
|
|
* |
|
23
|
|
|
* @return FloatParser |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function getInstance() { |
|
26
|
|
|
return new FloatParser(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @see ValueParserTestBase::validInputProvider |
|
31
|
|
|
*/ |
|
32
|
|
|
public function validInputProvider() { |
|
33
|
|
|
return [ |
|
34
|
|
|
// Ignoring a single trailing newline is an intended PCRE feature |
|
35
|
|
|
[ "0\n", new NumberValue( 0.0 ) ], |
|
36
|
|
|
|
|
37
|
|
|
[ '0', new NumberValue( 0.0 ) ], |
|
38
|
|
|
[ '1', new NumberValue( 1.0 ) ], |
|
39
|
|
|
[ '42', new NumberValue( 42.0 ) ], |
|
40
|
|
|
[ '01', new NumberValue( 1.0 ) ], |
|
41
|
|
|
[ '9001', new NumberValue( 9001.0 ) ], |
|
42
|
|
|
[ '-1', new NumberValue( -1.0 ) ], |
|
43
|
|
|
[ '-42', new NumberValue( -42.0 ) ], |
|
44
|
|
|
|
|
45
|
|
|
[ '0.0', new NumberValue( 0.0 ) ], |
|
46
|
|
|
[ '1.0', new NumberValue( 1.0 ) ], |
|
47
|
|
|
[ '4.2', new NumberValue( 4.2 ) ], |
|
48
|
|
|
[ '0.1', new NumberValue( 0.1 ) ], |
|
49
|
|
|
[ '90.01', new NumberValue( 90.01 ) ], |
|
50
|
|
|
[ '-1.0', new NumberValue( -1.0 ) ], |
|
51
|
|
|
[ '-4.2', new NumberValue( -4.2 ) ], |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @see StringValueParserTest::invalidInputProvider |
|
57
|
|
|
*/ |
|
58
|
|
|
public function invalidInputProvider() { |
|
59
|
|
|
$argLists = parent::invalidInputProvider(); |
|
60
|
|
|
|
|
61
|
|
|
$invalid = [ |
|
62
|
|
|
// Trimming is currently not supported |
|
63
|
|
|
' 0 ', |
|
64
|
|
|
|
|
65
|
|
|
'foo', |
|
66
|
|
|
'', |
|
67
|
|
|
'--1', |
|
68
|
|
|
'1-', |
|
69
|
|
|
'1 1', |
|
70
|
|
|
'1,', |
|
71
|
|
|
',1', |
|
72
|
|
|
',1,', |
|
73
|
|
|
'one', |
|
74
|
|
|
'0x20', |
|
75
|
|
|
'+1', |
|
76
|
|
|
'1+1', |
|
77
|
|
|
'1-1', |
|
78
|
|
|
'1.2.3', |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
foreach ( $invalid as $value ) { |
|
82
|
|
|
$argLists[] = [ $value ]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $argLists; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|