Passed
Push — nullBounds ( b3e7e4...f3529c )
by no
03:35
created

BasicNumberUnlocalizerTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 158
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
B provideUnlocalizeNumber() 0 29 1
A testUnlocalizeNumber() 0 6 1
A provideGetNumberRegexMatch() 0 23 1
A testGetNumberRegexMatch() 0 6 1
B provideGetNumberRegexMismatch() 0 26 1
A testGetNumberRegexMismatch() 0 6 1
A provideGetUnitRegexMatch() 0 5 1
A testGetUnitRegexMatch() 0 6 1
A provideGetUnitRegexMismatch() 0 17 1
A testGetUnitRegexMismatch() 0 6 1
1
<?php
2
3
namespace ValueParsers\Test;
4
5
use ValueParsers\BasicNumberUnlocalizer;
6
7
/**
8
 * @covers ValueParsers\BasicNumberUnlocalizer
9
 *
10
 * @group DataValue
11
 * @group DataValueExtensions
12
 *
13
 * @license GPL-2.0+
14
 * @author Daniel Kinzler
15
 */
16
class BasicNumberUnlocalizerTest extends \PHPUnit_Framework_TestCase {
17
18
	public function provideUnlocalizeNumber() {
19
		return array(
20
			array( '5', '5' ),
21
			array( '+3', '+3' ),
22
			array( '-15', '-15' ),
23
24
			array( '5.3', '5.3' ),
25
			array( '+3.2', '+3.2' ),
26
			array( '-15.77', '-15.77' ),
27
28
			array( '.3', '.3' ),
29
			array( '+.2', '+.2' ),
30
			array( '-.77', '-.77' ),
31
32
			array( '5.3e4', '5.3e4' ),
33
			array( '+3.2E-4', '+3.2E-4' ),
34
			array( '-15.77e+4.2', '-15.77e+4.2' ),
35
36
			array( '0x20', '0x20' ),
37
			array( '0X20', '0X20' ),
38
39
			array( '1,335.3', '1335.3' ),
40
			array( '+1,333.2', '+1333.2' ),
41
			array( '-1,315.77', '-1315.77' ),
42
43
			array( ' 1,333.3', '1333.3' ),
44
			array( '1,333.3 ', '1333.3' ),
45
		);
46
	}
47
48
	/**
49
	 * @dataProvider provideUnlocalizeNumber
50
	 */
51
	public function testUnlocalizeNumber( $localized, $expected ) {
52
		$unlocalizer = new BasicNumberUnlocalizer();
53
		$unlocalized = $unlocalizer->unlocalizeNumber( $localized );
54
55
		$this->assertEquals( $expected, $unlocalized );
56
	}
57
58
	public function provideGetNumberRegexMatch() {
59
		return array(
60
			array( '5' ),
61
			array( '+3' ),
62
			array( '-15' ),
63
64
			array( '5.3' ),
65
			array( '+3.2' ),
66
			array( '-15.77' ),
67
68
			array( '.3' ),
69
			array( '+.2' ),
70
			array( '-.77' ),
71
72
			array( '5.3e4' ),
73
			array( '+3.2E-4' ),
74
			array( '-15.77e+2' ),
75
76
			array( '1,335.3' ),
77
			array( '+1,333.2' ),
78
			array( '-1,315.77' ),
79
		);
80
	}
81
82
	/**
83
	 * @dataProvider provideGetNumberRegexMatch
84
	 */
85
	public function testGetNumberRegexMatch( $value ) {
86
		$unlocalizer = new BasicNumberUnlocalizer();
87
		$regex = $unlocalizer->getNumberRegex();
88
89
		$this->assertTrue( (bool)preg_match( "/^($regex)$/u", $value ) );
90
	}
91
92
	public function provideGetNumberRegexMismatch() {
93
		return array(
94
			array( '' ),
95
			array( ' ' ),
96
			array( '+' ),
97
			array( 'e' ),
98
99
			array( '+.' ),
100
			array( '.-' ),
101
			array( '...' ),
102
103
			array( '0x20' ),
104
			array( '2x2' ),
105
			array( 'x2' ),
106
			array( '2x' ),
107
108
			array( 'e.' ),
109
			array( '.e' ),
110
			array( '12e' ),
111
			array( 'E17' ),
112
113
			array( '+-3' ),
114
			array( '++7' ),
115
			array( '--5' ),
116
		);
117
	}
118
119
	/**
120
	 * @dataProvider provideGetNumberRegexMismatch
121
	 */
122
	public function testGetNumberRegexMismatch( $value ) {
123
		$unlocalizer = new BasicNumberUnlocalizer();
124
		$regex = $unlocalizer->getNumberRegex();
125
126
		$this->assertFalse( (bool)preg_match( "/^($regex)$/u", $value ) );
127
	}
128
129
	public function provideGetUnitRegexMatch() {
130
		return array(
131
			array( '' ),
132
		);
133
	}
134
135
	/**
136
	 * @dataProvider provideGetUnitRegexMatch
137
	 */
138
	public function testGetUnitRegexMatch( $value ) {
139
		$unlocalizer = new BasicNumberUnlocalizer();
140
		$regex = $unlocalizer->getUnitRegex();
141
142
		$this->assertTrue( (bool)preg_match( "/^($regex)$/u", $value ) );
143
	}
144
145
	public function provideGetUnitRegexMismatch() {
146
		return array(
147
			array( ' ' ),
148
149
			array( '^' ),
150
			array( '/' ),
151
152
			array( 'x^' ),
153
			array( 'x/' ),
154
155
			array( '2' ),
156
			array( '2b' ),
157
158
			array( '~' ),
159
			array( '#' ),
160
		);
161
	}
162
163
	/**
164
	 * @dataProvider provideGetUnitRegexMismatch
165
	 */
166
	public function testGetUnitRegexMismatch( $value ) {
167
		$unlocalizer = new BasicNumberUnlocalizer();
168
		$regex = $unlocalizer->getUnitRegex();
169
170
		$this->assertFalse( (bool)preg_match( "/^($regex)$/u", $value ) );
171
	}
172
173
}
174