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