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
|
|
|
* @licence GNU GPL v2+ |
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
|
|
|
array( '0', new NumberValue( 0.0 ) ), |
36
|
|
|
array( '1', new NumberValue( 1.0 ) ), |
37
|
|
|
array( '42', new NumberValue( 42.0 ) ), |
38
|
|
|
array( '01', new NumberValue( 1.0 ) ), |
39
|
|
|
array( '9001', new NumberValue( 9001.0 ) ), |
40
|
|
|
array( '-1', new NumberValue( -1.0 ) ), |
41
|
|
|
array( '-42', new NumberValue( -42.0 ) ), |
42
|
|
|
|
43
|
|
|
array( '0.0', new NumberValue( 0.0 ) ), |
44
|
|
|
array( '1.0', new NumberValue( 1.0 ) ), |
45
|
|
|
array( '4.2', new NumberValue( 4.2 ) ), |
46
|
|
|
array( '0.1', new NumberValue( 0.1 ) ), |
47
|
|
|
array( '90.01', new NumberValue( 90.01 ) ), |
48
|
|
|
array( '-1.0', new NumberValue( -1.0 ) ), |
49
|
|
|
array( '-4.2', new NumberValue( -4.2 ) ), |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @see StringValueParserTest::invalidInputProvider |
55
|
|
|
*/ |
56
|
|
|
public function invalidInputProvider() { |
57
|
|
|
$argLists = parent::invalidInputProvider(); |
58
|
|
|
|
59
|
|
|
$invalid = array( |
60
|
|
|
'foo', |
61
|
|
|
'', |
62
|
|
|
'--1', |
63
|
|
|
'1-', |
64
|
|
|
'1 1', |
65
|
|
|
'1,', |
66
|
|
|
',1', |
67
|
|
|
',1,', |
68
|
|
|
'one', |
69
|
|
|
'0x20', |
70
|
|
|
'+1', |
71
|
|
|
'1+1', |
72
|
|
|
'1-1', |
73
|
|
|
'1.2.3', |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
foreach ( $invalid as $value ) { |
77
|
|
|
$argLists[] = array( $value ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $argLists; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|