1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/csv-token |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/csv-token/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/csv-token |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\CsvToken\Test\Unit\ValueParser; |
15
|
|
|
|
16
|
|
|
use Graze\CsvToken\Test\TestCase; |
17
|
|
|
use Graze\CsvToken\ValueParser\NumberValueParser; |
18
|
|
|
|
19
|
|
|
class NumberValueParserTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** @var NumberValueParser */ |
22
|
|
|
private $parser; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->parser = new NumberValueParser(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @dataProvider canParseData |
31
|
|
|
* |
32
|
|
|
* @param string $string |
33
|
|
|
* @param bool $expected |
34
|
|
|
*/ |
35
|
|
|
public function testCanParseValue($string, $expected) |
36
|
|
|
{ |
37
|
|
|
static::assertEquals($expected, $this->parser->canParseValue($string)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function canParseData() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
['1', true], |
47
|
|
|
['1.2', true], |
48
|
|
|
['-1', true], |
49
|
|
|
['string', false], |
50
|
|
|
['null', false], |
51
|
|
|
['1.2e-12', true], |
52
|
|
|
['4763894692379379723479327842', true], |
53
|
|
|
['0.000000000001231312', true], |
54
|
|
|
['some string', false], |
55
|
|
|
['string12345', false], |
56
|
|
|
['12345string', false], |
57
|
|
|
['123,123,123.01', false], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @dataProvider parseData |
63
|
|
|
* |
64
|
|
|
* @param string $string |
65
|
|
|
* @param mixed $expected |
66
|
|
|
*/ |
67
|
|
|
public function testParseValue($string, $expected) |
68
|
|
|
{ |
69
|
|
|
static::assertEquals($expected, $this->parser->parseValue($string)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function parseData() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
['1', true], |
79
|
|
|
['1.2', 1.2], |
80
|
|
|
['-1', -1], |
81
|
|
|
['1.2e-12', 1.2e-12], |
82
|
|
|
['4763894692379379723479327842', 4763894692379379723479327842], |
83
|
|
|
['0.000000000001231312', 0.000000000001231312], |
84
|
|
|
['123,123,123.01', 123123123.01], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|