@@ -148,4 +148,132 @@ public function providerFractions(): array
148
148
'improper fraction ' => ['1.75 ' , '7/4 ' ],
149
149
];
150
150
}
151
+
152
+ /**
153
+ * @dataProvider providerPercentages
154
+ */
155
+ public function testPercentage (string $ expected , string $ value ): void
156
+ {
157
+ $ originalValue = $ value ;
158
+ $ result = StringHelper::convertToNumberIfPercent ($ value );
159
+ if ($ result === false ) {
160
+ self ::assertSame ($ expected , $ originalValue );
161
+ self ::assertSame ($ expected , $ value );
162
+ } else {
163
+ self ::assertSame ($ expected , (string ) $ value );
164
+ self ::assertNotEquals ($ value , $ originalValue );
165
+ }
166
+ }
167
+
168
+ public function providerPercentages (): array
169
+ {
170
+ return [
171
+ 'non-percentage ' => ['10 ' , '10 ' ],
172
+ 'single digit percentage ' => ['0.02 ' , '2% ' ],
173
+ 'two digit percentage ' => ['0.13 ' , '13% ' ],
174
+ 'negative single digit percentage ' => ['-0.07 ' , '-7% ' ],
175
+ 'negative two digit percentage ' => ['-0.75 ' , '-75% ' ],
176
+ 'large percentage ' => ['98.45 ' , '9845% ' ],
177
+ 'small percentage ' => ['0.0005 ' , '0.05% ' ],
178
+ 'percentage with decimals ' => ['0.025 ' , '2.5% ' ],
179
+ 'trailing percent with space ' => ['0.02 ' , '2 % ' ],
180
+ 'trailing percent with leading and trailing space ' => ['0.02 ' , ' 2 % ' ],
181
+ 'leading percent with decimals ' => ['0.025 ' , ' % 2.5 ' ],
182
+
183
+ //These should all fail
184
+ 'percent only ' => ['% ' , '% ' ],
185
+ 'nonsense percent ' => ['2%2 ' , '2%2 ' ],
186
+ 'negative leading percent ' => ['-0.02 ' , '-%2 ' ],
187
+
188
+ //Percent position permutations
189
+ 'permutation_1 ' => ['0.02 ' , '2% ' ],
190
+ 'permutation_2 ' => ['0.02 ' , ' 2% ' ],
191
+ 'permutation_3 ' => ['0.02 ' , '2% ' ],
192
+ 'permutation_4 ' => ['0.02 ' , ' 2 % ' ],
193
+ 'permutation_5 ' => ['0.0275 ' , '2.75% ' ],
194
+ 'permutation_6 ' => ['0.0275 ' , ' 2.75% ' ],
195
+ 'permutation_7 ' => ['0.0275 ' , ' 2.75 % ' ],
196
+ 'permutation_8 ' => [' 2 . 75 % ' , ' 2 . 75 % ' ],
197
+ 'permutation_9 ' => [' 2.7 5 % ' , ' 2.7 5 % ' ],
198
+ 'permutation_10 ' => ['-0.02 ' , '-2% ' ],
199
+ 'permutation_11 ' => ['-0.02 ' , ' -2% ' ],
200
+ 'permutation_12 ' => ['-0.02 ' , '- 2% ' ],
201
+ 'permutation_13 ' => ['-0.02 ' , '-2 % ' ],
202
+ 'permutation_14 ' => ['-0.0275 ' , '-2.75% ' ],
203
+ 'permutation_15 ' => ['-0.0275 ' , ' -2.75% ' ],
204
+ 'permutation_16 ' => ['-0.0275 ' , '-2.75 % ' ],
205
+ 'permutation_17 ' => ['-0.0275 ' , ' - 2.75 % ' ],
206
+ 'permutation_18 ' => ['0.02 ' , '2% ' ],
207
+ 'permutation_19 ' => ['0.02 ' , '% 2 ' ],
208
+ 'permutation_20 ' => ['0.02 ' , ' %2 ' ],
209
+ 'permutation_21 ' => ['0.02 ' , ' % 2 ' ],
210
+ 'permutation_22 ' => ['0.0275 ' , '%2.75 ' ],
211
+ 'permutation_23 ' => ['0.0275 ' , ' %2.75 ' ],
212
+ 'permutation_24 ' => ['0.0275 ' , ' % 2.75 ' ],
213
+ 'permutation_25 ' => [' %2 . 75 ' , ' %2 . 75 ' ],
214
+ 'permutation_26 ' => [' %2.7 5 ' , ' %2.7 5 ' ],
215
+ 'permutation_27 ' => [' % 2 . 75 ' , ' % 2 . 75 ' ],
216
+ 'permutation_28 ' => [' % 2.7 5 ' , ' % 2.7 5 ' ],
217
+ 'permutation_29 ' => ['-0.0275 ' , '-%2.75 ' ],
218
+ 'permutation_30 ' => ['-0.0275 ' , ' - %2.75 ' ],
219
+ 'permutation_31 ' => ['-0.0275 ' , '- % 2.75 ' ],
220
+ 'permutation_32 ' => ['-0.0275 ' , ' - % 2.75 ' ],
221
+ 'permutation_33 ' => ['0.02 ' , '2% ' ],
222
+ 'permutation_34 ' => ['0.02 ' , '2 % ' ],
223
+ 'permutation_35 ' => ['0.02 ' , ' 2% ' ],
224
+ 'permutation_36 ' => ['0.02 ' , ' 2 % ' ],
225
+ 'permutation_37 ' => ['0.0275 ' , '2.75% ' ],
226
+ 'permutation_38 ' => ['0.0275 ' , ' 2.75 % ' ],
227
+ 'permutation_39 ' => ['2 . 75 % ' , '2 . 75 % ' ],
228
+ 'permutation_40 ' => ['-0.0275 ' , '-2.75% ' ],
229
+ 'permutation_41 ' => ['-0.0275 ' , '- 2.75% ' ],
230
+ 'permutation_42 ' => ['-0.0275 ' , ' - 2.75% ' ],
231
+ 'permutation_43 ' => ['-0.0275 ' , ' -2.75 % ' ],
232
+ 'permutation_44 ' => ['-2. 75 % ' , '-2. 75 % ' ],
233
+ 'permutation_45 ' => ['% ' , '% ' ],
234
+ 'permutation_46 ' => ['0.02 ' , '%2 ' ],
235
+ 'permutation_47 ' => ['0.02 ' , '% 2 ' ],
236
+ 'permutation_48 ' => ['0.02 ' , ' %2 ' ],
237
+ 'permutation_49 ' => ['0.02 ' , '% 2 ' ],
238
+ 'permutation_50 ' => ['0.02 ' , ' % 2 ' ],
239
+ 'permutation_51 ' => ['0.02 ' , ' 2 % ' ],
240
+ 'permutation_52 ' => ['-0.02 ' , '-2% ' ],
241
+ 'permutation_53 ' => ['-0.02 ' , '- %2 ' ],
242
+ 'permutation_54 ' => ['-0.02 ' , ' -%2 ' ],
243
+ 'permutation_55 ' => ['2%2 ' , '2%2 ' ],
244
+ 'permutation_56 ' => [' 2% % ' , ' 2% % ' ],
245
+ 'permutation_57 ' => [' % 2 - ' , ' % 2 - ' ],
246
+ 'permutation_58 ' => ['-0.02 ' , '%-2 ' ],
247
+ 'permutation_59 ' => ['-0.02 ' , ' % - 2 ' ],
248
+ 'permutation_60 ' => ['-0.0275 ' , '%-2.75 ' ],
249
+ 'permutation_61 ' => ['-0.0275 ' , ' % - 2.75 ' ],
250
+ 'permutation_62 ' => ['-0.0275 ' , ' % - 2.75 ' ],
251
+ 'permutation_63 ' => ['-0.0275 ' , ' % - 2.75 ' ],
252
+ 'permutation_64 ' => ['0.0275 ' , ' % + 2.75 ' ],
253
+ 'permutation_65 ' => ['0.0275 ' , ' % + 2.75 ' ],
254
+ 'permutation_66 ' => ['0.0275 ' , ' % + 2.75 ' ],
255
+ 'permutation_67 ' => ['0.02 ' , '+2% ' ],
256
+ 'permutation_68 ' => ['0.02 ' , ' +2% ' ],
257
+ 'permutation_69 ' => ['0.02 ' , '+ 2% ' ],
258
+ 'permutation_70 ' => ['0.02 ' , '+2 % ' ],
259
+ 'permutation_71 ' => ['0.0275 ' , '+2.75% ' ],
260
+ 'permutation_72 ' => ['0.0275 ' , ' +2.75% ' ],
261
+ 'permutation_73 ' => ['0.0275 ' , '+2.75 % ' ],
262
+ 'permutation_74 ' => ['0.0275 ' , ' + 2.75 % ' ],
263
+ 'permutation_75 ' => ['-2.5E-6 ' , '-2.5E-4% ' ],
264
+ 'permutation_76 ' => ['200 ' , '2E4% ' ],
265
+ 'permutation_77 ' => ['-2.5E-8 ' , '-%2.50E-06 ' ],
266
+ 'permutation_78 ' => [' - % 2.50 E -06 ' , ' - % 2.50 E -06 ' ],
267
+ 'permutation_79 ' => ['-2.5E-8 ' , ' - % 2.50E-06 ' ],
268
+ 'permutation_80 ' => [' - % 2.50E- 06 ' , ' - % 2.50E- 06 ' ],
269
+ 'permutation_81 ' => [' - % 2.50E - 06 ' , ' - % 2.50E - 06 ' ],
270
+ 'permutation_82 ' => ['-2.5E-6 ' , '-2.5e-4% ' ],
271
+ 'permutation_83 ' => ['200 ' , '2e4% ' ],
272
+ 'permutation_84 ' => ['-2.5E-8 ' , '-%2.50e-06 ' ],
273
+ 'permutation_85 ' => [' - % 2.50 e -06 ' , ' - % 2.50 e -06 ' ],
274
+ 'permutation_86 ' => ['-2.5E-8 ' , ' - % 2.50e-06 ' ],
275
+ 'permutation_87 ' => [' - % 2.50e- 06 ' , ' - % 2.50e- 06 ' ],
276
+ 'permutation_88 ' => [' - % 2.50e - 06 ' , ' - % 2.50e - 06 ' ],
277
+ ];
278
+ }
151
279
}
0 commit comments