1--TEST--
2Test parsing of quantities
3--EXTENSIONS--
4zend_test
5--FILE--
6<?php
7
8// This test checks valid formats do not throw any warnings.
9foreach (['', ' '] as $leadingWS) {
10  foreach (['', '+', '-'] as $sign) {
11    foreach (['', ' '] as $midWS) {
12      foreach (['', 'K', 'k', 'M', 'm', 'G', 'g'] as $exp) {
13        foreach (['', ' '] as $trailingWS) {
14          // Decimal
15          $setting = sprintf('%s%s1%s%s%s',
16                             $leadingWS, $sign, $midWS, $exp, $trailingWS);
17          printf("# \"%s\"\n", $setting);
18          var_dump(zend_test_zend_ini_parse_quantity($setting));
19          print "\n";
20
21          if ($exp !== 'g' && $exp !== 'G') { // Would overflow
22              // Octal
23              $setting = sprintf('%s%s0123%s%s%s',
24                                 $leadingWS, $sign, $midWS, $exp, $trailingWS);
25              printf("# \"%s\"\n", $setting);
26              var_dump(zend_test_zend_ini_parse_quantity($setting));
27              print "\n";
28          }
29        }
30      }
31    }
32  }
33}
34--EXPECT--
35# "1"
36int(1)
37
38# "0123"
39int(83)
40
41# "1 "
42int(1)
43
44# "0123 "
45int(83)
46
47# "1K"
48int(1024)
49
50# "0123K"
51int(84992)
52
53# "1K "
54int(1024)
55
56# "0123K "
57int(84992)
58
59# "1k"
60int(1024)
61
62# "0123k"
63int(84992)
64
65# "1k "
66int(1024)
67
68# "0123k "
69int(84992)
70
71# "1M"
72int(1048576)
73
74# "0123M"
75int(87031808)
76
77# "1M "
78int(1048576)
79
80# "0123M "
81int(87031808)
82
83# "1m"
84int(1048576)
85
86# "0123m"
87int(87031808)
88
89# "1m "
90int(1048576)
91
92# "0123m "
93int(87031808)
94
95# "1G"
96int(1073741824)
97
98# "1G "
99int(1073741824)
100
101# "1g"
102int(1073741824)
103
104# "1g "
105int(1073741824)
106
107# "1 "
108int(1)
109
110# "0123 "
111int(83)
112
113# "1  "
114int(1)
115
116# "0123  "
117int(83)
118
119# "1 K"
120int(1024)
121
122# "0123 K"
123int(84992)
124
125# "1 K "
126int(1024)
127
128# "0123 K "
129int(84992)
130
131# "1 k"
132int(1024)
133
134# "0123 k"
135int(84992)
136
137# "1 k "
138int(1024)
139
140# "0123 k "
141int(84992)
142
143# "1 M"
144int(1048576)
145
146# "0123 M"
147int(87031808)
148
149# "1 M "
150int(1048576)
151
152# "0123 M "
153int(87031808)
154
155# "1 m"
156int(1048576)
157
158# "0123 m"
159int(87031808)
160
161# "1 m "
162int(1048576)
163
164# "0123 m "
165int(87031808)
166
167# "1 G"
168int(1073741824)
169
170# "1 G "
171int(1073741824)
172
173# "1 g"
174int(1073741824)
175
176# "1 g "
177int(1073741824)
178
179# "+1"
180int(1)
181
182# "+0123"
183int(83)
184
185# "+1 "
186int(1)
187
188# "+0123 "
189int(83)
190
191# "+1K"
192int(1024)
193
194# "+0123K"
195int(84992)
196
197# "+1K "
198int(1024)
199
200# "+0123K "
201int(84992)
202
203# "+1k"
204int(1024)
205
206# "+0123k"
207int(84992)
208
209# "+1k "
210int(1024)
211
212# "+0123k "
213int(84992)
214
215# "+1M"
216int(1048576)
217
218# "+0123M"
219int(87031808)
220
221# "+1M "
222int(1048576)
223
224# "+0123M "
225int(87031808)
226
227# "+1m"
228int(1048576)
229
230# "+0123m"
231int(87031808)
232
233# "+1m "
234int(1048576)
235
236# "+0123m "
237int(87031808)
238
239# "+1G"
240int(1073741824)
241
242# "+1G "
243int(1073741824)
244
245# "+1g"
246int(1073741824)
247
248# "+1g "
249int(1073741824)
250
251# "+1 "
252int(1)
253
254# "+0123 "
255int(83)
256
257# "+1  "
258int(1)
259
260# "+0123  "
261int(83)
262
263# "+1 K"
264int(1024)
265
266# "+0123 K"
267int(84992)
268
269# "+1 K "
270int(1024)
271
272# "+0123 K "
273int(84992)
274
275# "+1 k"
276int(1024)
277
278# "+0123 k"
279int(84992)
280
281# "+1 k "
282int(1024)
283
284# "+0123 k "
285int(84992)
286
287# "+1 M"
288int(1048576)
289
290# "+0123 M"
291int(87031808)
292
293# "+1 M "
294int(1048576)
295
296# "+0123 M "
297int(87031808)
298
299# "+1 m"
300int(1048576)
301
302# "+0123 m"
303int(87031808)
304
305# "+1 m "
306int(1048576)
307
308# "+0123 m "
309int(87031808)
310
311# "+1 G"
312int(1073741824)
313
314# "+1 G "
315int(1073741824)
316
317# "+1 g"
318int(1073741824)
319
320# "+1 g "
321int(1073741824)
322
323# "-1"
324int(-1)
325
326# "-0123"
327int(-83)
328
329# "-1 "
330int(-1)
331
332# "-0123 "
333int(-83)
334
335# "-1K"
336int(-1024)
337
338# "-0123K"
339int(-84992)
340
341# "-1K "
342int(-1024)
343
344# "-0123K "
345int(-84992)
346
347# "-1k"
348int(-1024)
349
350# "-0123k"
351int(-84992)
352
353# "-1k "
354int(-1024)
355
356# "-0123k "
357int(-84992)
358
359# "-1M"
360int(-1048576)
361
362# "-0123M"
363int(-87031808)
364
365# "-1M "
366int(-1048576)
367
368# "-0123M "
369int(-87031808)
370
371# "-1m"
372int(-1048576)
373
374# "-0123m"
375int(-87031808)
376
377# "-1m "
378int(-1048576)
379
380# "-0123m "
381int(-87031808)
382
383# "-1G"
384int(-1073741824)
385
386# "-1G "
387int(-1073741824)
388
389# "-1g"
390int(-1073741824)
391
392# "-1g "
393int(-1073741824)
394
395# "-1 "
396int(-1)
397
398# "-0123 "
399int(-83)
400
401# "-1  "
402int(-1)
403
404# "-0123  "
405int(-83)
406
407# "-1 K"
408int(-1024)
409
410# "-0123 K"
411int(-84992)
412
413# "-1 K "
414int(-1024)
415
416# "-0123 K "
417int(-84992)
418
419# "-1 k"
420int(-1024)
421
422# "-0123 k"
423int(-84992)
424
425# "-1 k "
426int(-1024)
427
428# "-0123 k "
429int(-84992)
430
431# "-1 M"
432int(-1048576)
433
434# "-0123 M"
435int(-87031808)
436
437# "-1 M "
438int(-1048576)
439
440# "-0123 M "
441int(-87031808)
442
443# "-1 m"
444int(-1048576)
445
446# "-0123 m"
447int(-87031808)
448
449# "-1 m "
450int(-1048576)
451
452# "-0123 m "
453int(-87031808)
454
455# "-1 G"
456int(-1073741824)
457
458# "-1 G "
459int(-1073741824)
460
461# "-1 g"
462int(-1073741824)
463
464# "-1 g "
465int(-1073741824)
466
467# " 1"
468int(1)
469
470# " 0123"
471int(83)
472
473# " 1 "
474int(1)
475
476# " 0123 "
477int(83)
478
479# " 1K"
480int(1024)
481
482# " 0123K"
483int(84992)
484
485# " 1K "
486int(1024)
487
488# " 0123K "
489int(84992)
490
491# " 1k"
492int(1024)
493
494# " 0123k"
495int(84992)
496
497# " 1k "
498int(1024)
499
500# " 0123k "
501int(84992)
502
503# " 1M"
504int(1048576)
505
506# " 0123M"
507int(87031808)
508
509# " 1M "
510int(1048576)
511
512# " 0123M "
513int(87031808)
514
515# " 1m"
516int(1048576)
517
518# " 0123m"
519int(87031808)
520
521# " 1m "
522int(1048576)
523
524# " 0123m "
525int(87031808)
526
527# " 1G"
528int(1073741824)
529
530# " 1G "
531int(1073741824)
532
533# " 1g"
534int(1073741824)
535
536# " 1g "
537int(1073741824)
538
539# " 1 "
540int(1)
541
542# " 0123 "
543int(83)
544
545# " 1  "
546int(1)
547
548# " 0123  "
549int(83)
550
551# " 1 K"
552int(1024)
553
554# " 0123 K"
555int(84992)
556
557# " 1 K "
558int(1024)
559
560# " 0123 K "
561int(84992)
562
563# " 1 k"
564int(1024)
565
566# " 0123 k"
567int(84992)
568
569# " 1 k "
570int(1024)
571
572# " 0123 k "
573int(84992)
574
575# " 1 M"
576int(1048576)
577
578# " 0123 M"
579int(87031808)
580
581# " 1 M "
582int(1048576)
583
584# " 0123 M "
585int(87031808)
586
587# " 1 m"
588int(1048576)
589
590# " 0123 m"
591int(87031808)
592
593# " 1 m "
594int(1048576)
595
596# " 0123 m "
597int(87031808)
598
599# " 1 G"
600int(1073741824)
601
602# " 1 G "
603int(1073741824)
604
605# " 1 g"
606int(1073741824)
607
608# " 1 g "
609int(1073741824)
610
611# " +1"
612int(1)
613
614# " +0123"
615int(83)
616
617# " +1 "
618int(1)
619
620# " +0123 "
621int(83)
622
623# " +1K"
624int(1024)
625
626# " +0123K"
627int(84992)
628
629# " +1K "
630int(1024)
631
632# " +0123K "
633int(84992)
634
635# " +1k"
636int(1024)
637
638# " +0123k"
639int(84992)
640
641# " +1k "
642int(1024)
643
644# " +0123k "
645int(84992)
646
647# " +1M"
648int(1048576)
649
650# " +0123M"
651int(87031808)
652
653# " +1M "
654int(1048576)
655
656# " +0123M "
657int(87031808)
658
659# " +1m"
660int(1048576)
661
662# " +0123m"
663int(87031808)
664
665# " +1m "
666int(1048576)
667
668# " +0123m "
669int(87031808)
670
671# " +1G"
672int(1073741824)
673
674# " +1G "
675int(1073741824)
676
677# " +1g"
678int(1073741824)
679
680# " +1g "
681int(1073741824)
682
683# " +1 "
684int(1)
685
686# " +0123 "
687int(83)
688
689# " +1  "
690int(1)
691
692# " +0123  "
693int(83)
694
695# " +1 K"
696int(1024)
697
698# " +0123 K"
699int(84992)
700
701# " +1 K "
702int(1024)
703
704# " +0123 K "
705int(84992)
706
707# " +1 k"
708int(1024)
709
710# " +0123 k"
711int(84992)
712
713# " +1 k "
714int(1024)
715
716# " +0123 k "
717int(84992)
718
719# " +1 M"
720int(1048576)
721
722# " +0123 M"
723int(87031808)
724
725# " +1 M "
726int(1048576)
727
728# " +0123 M "
729int(87031808)
730
731# " +1 m"
732int(1048576)
733
734# " +0123 m"
735int(87031808)
736
737# " +1 m "
738int(1048576)
739
740# " +0123 m "
741int(87031808)
742
743# " +1 G"
744int(1073741824)
745
746# " +1 G "
747int(1073741824)
748
749# " +1 g"
750int(1073741824)
751
752# " +1 g "
753int(1073741824)
754
755# " -1"
756int(-1)
757
758# " -0123"
759int(-83)
760
761# " -1 "
762int(-1)
763
764# " -0123 "
765int(-83)
766
767# " -1K"
768int(-1024)
769
770# " -0123K"
771int(-84992)
772
773# " -1K "
774int(-1024)
775
776# " -0123K "
777int(-84992)
778
779# " -1k"
780int(-1024)
781
782# " -0123k"
783int(-84992)
784
785# " -1k "
786int(-1024)
787
788# " -0123k "
789int(-84992)
790
791# " -1M"
792int(-1048576)
793
794# " -0123M"
795int(-87031808)
796
797# " -1M "
798int(-1048576)
799
800# " -0123M "
801int(-87031808)
802
803# " -1m"
804int(-1048576)
805
806# " -0123m"
807int(-87031808)
808
809# " -1m "
810int(-1048576)
811
812# " -0123m "
813int(-87031808)
814
815# " -1G"
816int(-1073741824)
817
818# " -1G "
819int(-1073741824)
820
821# " -1g"
822int(-1073741824)
823
824# " -1g "
825int(-1073741824)
826
827# " -1 "
828int(-1)
829
830# " -0123 "
831int(-83)
832
833# " -1  "
834int(-1)
835
836# " -0123  "
837int(-83)
838
839# " -1 K"
840int(-1024)
841
842# " -0123 K"
843int(-84992)
844
845# " -1 K "
846int(-1024)
847
848# " -0123 K "
849int(-84992)
850
851# " -1 k"
852int(-1024)
853
854# " -0123 k"
855int(-84992)
856
857# " -1 k "
858int(-1024)
859
860# " -0123 k "
861int(-84992)
862
863# " -1 M"
864int(-1048576)
865
866# " -0123 M"
867int(-87031808)
868
869# " -1 M "
870int(-1048576)
871
872# " -0123 M "
873int(-87031808)
874
875# " -1 m"
876int(-1048576)
877
878# " -0123 m"
879int(-87031808)
880
881# " -1 m "
882int(-1048576)
883
884# " -0123 m "
885int(-87031808)
886
887# " -1 G"
888int(-1073741824)
889
890# " -1 G "
891int(-1073741824)
892
893# " -1 g"
894int(-1073741824)
895
896# " -1 g "
897int(-1073741824)
898