Passed
Push — master ( 8ff373...315bd9 )
by adam
01:44
created

FloatParserTest::invalidInputProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

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