1--TEST--
2Test vsprintf() function : usage variations - scientific formats with non-scientific values
3--FILE--
4<?php
5/* Prototype  : string vsprintf(string format, array args)
6 * Description: Return a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vsprintf() when different scientific formats and non-scientific values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15echo "*** Testing vsprintf() : scientific formats and non-scientific values ***\n";
16
17// defining array of non-scientific formats
18$formats =
19  '%e %+e %-e
20   %le %Le %4e %-4e
21   %10.4e %-10.4e %04e %04.4e
22   %\'#2e %\'2e %\'$2e %\'_2e
23   %3$e %4$e %1$e %2$e';
24
25// Arrays of non scientific values for the format defined in $format.
26// Each sub array contains non scientific values which correspond to each format in $format
27$args_array = array(
28
29  // array of float values
30  array(2.2, .2, 10.2,
31        123456.234, 123456.234, -1234.6789, +1234.6789,
32        20.00, +212.2, -411000000000, 2212.000000000001,
33        12345.780, 12.000000011111, -12.00000111111, -123456.234,
34        3.33, +4.44, 1.11,-2.22 ),
35
36  // array of strings
37  array(" ", ' ', 'hello',
38        '123hello', "123hello", '-123hello', '+123hello',
39        "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
40        "1234hello", "hello\0world", "NULL", "true",
41        "3", "4", '1', '2'),
42
43  // different arrays
44  array( array(0), array(1, 2), array(-1, -1),
45         array("123"), array('123'), array('-123'), array("-123"),
46         array(true), array(false), array(TRUE), array(FALSE),
47         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
48         array("3"), array("4"), array("1"), array("2") ),
49
50  // array of boolean data
51  array( true, TRUE, false,
52         TRUE, 0, FALSE, 1,
53         true, false, TRUE, FALSE,
54         0, 1, 1, 0,
55         1, TRUE, 0, FALSE),
56
57);
58
59// looping to test vsprintf() with different scientific formats from the above $format array
60// and with non-scientific values from the above $args_array array
61$counter = 1;
62foreach($args_array as $args) {
63  echo "\n-- Iteration $counter --\n";
64  var_dump( vsprintf($formats, $args) );
65  $counter++;
66}
67
68echo "Done";
69?>
70--EXPECTF--
71*** Testing vsprintf() : scientific formats and non-scientific values ***
72
73-- Iteration 1 --
74string(232) "2.200000e+0 +2.000000e-1 1.020000e+1
75   1.234562e+5 e -1.234679e+3 1.234679e+3
76    2.0000e+1 2.1220e+2  -4.110000e+11 2.2120e+3
77   1.234578e+4 1.200000e+1 -1.200000e+1 -1.234562e+5
78   1.020000e+1 1.234562e+5 2.200000e+0 2.000000e-1"
79
80-- Iteration 2 --
81string(228) "0.000000e+0 +0.000000e+0 0.000000e+0
82   1.230000e+2 e -1.230000e+2 1.230000e+2
83    0.0000e+0 0.0000e+0  1.234560e+5 0.0000e+0
84   1.234000e+3 0.000000e+0 0.000000e+0 0.000000e+0
85   0.000000e+0 1.230000e+2 0.000000e+0 0.000000e+0"
86
87-- Iteration 3 --
88string(227) "1.000000e+0 +1.000000e+0 1.000000e+0
89   1.000000e+0 e 1.000000e+0 1.000000e+0
90    1.0000e+0 1.0000e+0  1.000000e+0 1.0000e+0
91   1.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0
92   1.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0"
93
94-- Iteration 4 --
95string(227) "1.000000e+0 +1.000000e+0 0.000000e+0
96   1.000000e+0 e 0.000000e+0 1.000000e+0
97    1.0000e+0 0.0000e+0  1.000000e+0 0.0000e+0
98   0.000000e+0 1.000000e+0 1.000000e+0 0.000000e+0
99   0.000000e+0 1.000000e+0 1.000000e+0 1.000000e+0"
100Done
101