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