* src/pmc/scalar.pmc:
[parrot.git] / t / op / sprintf_tests
blob322fcec0fce721598c1b82da6413fecb4986b8f9
1 # template  data            expected            description (optional)
2 %6. 6s          ''                              %6. 6s INVALID          (See use of $w in code above)
3 %6 .6s          ''                              %6 .6s INVALID
4 %6.6 s          ''                              %6.6 s INVALID
5 %A                      ''                              %A INVALID
6 %B                      ''                              %B INVALID
7 %C                      ''                              %C INVALID
8 %D                      0x7fffffff              2147483647                      Synonym for %ld
9 %E                      123456.789              1.234568E+05            Like %e, but using upper-case "E"
10 %F                      123456.789              123456.789000           Synonym for %f
11 %G                      1234567.89              1.23457E+06                     Like %g, but using upper-case "E"
12 %G                      1234567e96              1.23457E+102
13 %G                      .1234567e-101   1.23457E-102
14 %G                      12345.6789              12345.7
15 %G                      1234567e96              1.23457E+102            exponent too big skip: os390
16 %G                      .1234567e-101   1.23457E-102            exponent too small skip: os390
17 %H                      ''                              %H INVALID
18 %I                      ''                              %I INVALID
19 %J                      ''                              %J INVALID
20 %K                      ''                              %K INVALID
21 %L                      ''                              %L INVALID
22 %M                      ''                              %M INVALID
23 %N                      ''                              %N INVALID
24 %O                      2**32-1                 37777777777                     Synonym for %lo
25 %P                      ''                              %P INVALID
26 %Q                      ''                              %Q INVALID
27 %R                      ''                              %R INVALID
28 %S                      ''                              %S INVALID
29 %T                      ''                              %T INVALID
30 %U                      2**32-1 4294967295      Synonym for %lu
31 %V                      ''                              %V INVALID
32 %W                      ''                              %W INVALID
33 %X                      2**32-1                 FFFFFFFF                        Like %x, but with u/c letters
34 %#X                     2**32-1                 0XFFFFFFFF
35 %Y                      ''                              %Y INVALID
36 %Z                      ''                              %Z INVALID
37 %a                      ''                              %a INVALID
38 %b                      2**32-1                 11111111111111111111111111111111
39 %+b                     2**32-1                 11111111111111111111111111111111
40 %#b                     2**32-1                 0b11111111111111111111111111111111
41 %34b            2**32-1                   11111111111111111111111111111111
42 %034b           2**32-1                 0011111111111111111111111111111111
43 %-34b           2**32-1                 11111111111111111111111111111111  
44 %-034b          2**32-1                 11111111111111111111111111111111  
45 %c                      65                              A
46 %10c            65                                       A
47 %#10c           65                                       A                              # modifier: no effect
48 %010c           65                              000000000A
49 %10lc           65                                       A                              l modifier: no effect
50 %10hc           65                                       A                              h modifier: no effect
51 %10.5c          65                                       A                              precision: no effect
52 %-10c           65                              A         
53 %d                      123456.789              123456
54 %d                      -123456.789             -123456
55 %d                      0                               0
56 %+d                     0                               +0
57 %0d                     0                               0
58 %.0d            0                               
59 %+.0d           0                               +
60 %.0d            1                               1
61 %d                      1                               1
62 %+d                     1                               +1
63 %#3.2d          1                                01                                     # modifier: no effect
64 %3.2d           1                                01
65 %03.2d          1                               001
66 %-3.2d          1                               01 
67 %-03.2d         1                               01                                      zero pad + left just.: no effect
68 %d                      -1                              -1
69 %+d                     -1                              -1
70 %hd                     1                               1                                       More extensive testing of
71 %ld                     1                               1                                       length modifiers would be
72 %Vd                     1                               1                                       platform-specific
73 %vd                     chr(1)                  1
74 %+vd            chr(1)                  +1
75 %#vd            chr(1)                  1
76 %vd                     "\01\02\03"             1.2.3
77 %vd                     v1.2.3                  1.2.3
78 %vd                     [version::qv("1.2.3")]          1.2.3
79 %vd                     [version->new("1.2")]           1.200
80 %vd                     [version->new("1.02")]          1.20
81 %vd                     [version->new("1.002")]         1.2
82 %vd                     [version->new("1048576.5")]     1048576.500
83 %vd                     [version->new("50")]            50.0
84 %v.3d           "\01\02\03"                                     001.002.003
85 %0v3d           "\01\02\03"                                     001.002.003
86 %v.3d           [version::qv("1.2.3")]          001.002.003
87 %-v3d           "\01\02\03"                                     1  .2  .3  
88 %+-v3d          "\01\02\03"                                     +1 .2  .3  
89 %+-v3d          [version::qv("1.2.3")]          +1 .2  .3  
90 %v4.3d          "\01\02\03"                                      001. 002. 003
91 %0v4.3d         "\01\02\03"                                     0001.0002.0003
92 %0*v2d          ['-', "\0\7\14"]                        00-07-12
93 %v.*d           ["\01\02\03", 3]                        001.002.003
94 %0v*d           ["\01\02\03", 3]                        001.002.003
95 %-v*d           ["\01\02\03", 3]                        1  .2  .3  
96 %+-v*d          ["\01\02\03", 3]                        +1 .2  .3  
97 %v*.*d          ["\01\02\03", 4, 3]                      001. 002. 003
98 %0v*.*d         ["\01\02\03", 4, 3]                     0001.0002.0003
99 %0*v*d          ['-', "\0\7\13", 2]                     00-07-11
100 %0*v*d          ['-', version::qv("0.7.11"), 2] 00-07-11
101 %e                      1234.875                1.234875e+03
102 %e                      0.000012345             1.234500e-05
103 %e                      1234567E96              1.234567e+102
104 %e                      0                               0.000000e+00
105 %e                      .1234567E-101   1.234567e-102
106 %+e                     1234.875                +1.234875e+03
107 %#e                     1234.875                1.234875e+03
108 %e                      -1234.875               -1.234875e+03
109 %+e                     -1234.875               -1.234875e+03
110 %#e                     -1234.875               -1.234875e+03
111 %.0e            1234.875                1e+03
112 %#.0e           1234.875                1.e+03
113 %.0e            1.875                   2e+00
114 %.0e            0.875                   9e-01
115 %.*e            [0, 1234.875]   1e+03
116 %.1e            1234.875                1.2e+03
117 %-12.4e         1234.875                1.2349e+03  
118 %12.4e          1234.875                  1.2349e+03
119 %+-12.4e        1234.875                +1.2349e+03 
120 %+12.4e         1234.875                 +1.2349e+03
121 %+-12.4e        -1234.875               -1.2349e+03 
122 %+12.4e         -1234.875                -1.2349e+03
123 %e                      1234567E96              1.234567e+102           exponent too big skip: os390
124 %e                      .1234567E-101   1.234567e-102           exponent too small skip: os390
125 %f                      1234.875                1234.875000
126 %+f                     1234.875                +1234.875000
127 %#f                     1234.875                1234.875000
128 %f                      -1234.875               -1234.875000
129 %+f                     -1234.875               -1234.875000
130 %#f                     -1234.875               -1234.875000
131 %6f                     1234.875                1234.875000
132 %*f                     [6, 1234.875]   1234.875000
133 %.0f            -0.1                    -0                                      C library bug: no minus skip: VMS
134 %.0f            1234.875                1235
135 %.1f            1234.875                1234.9
136 %-8.1f          1234.875                1234.9  
137 %8.1f           1234.875                  1234.9
138 %+-8.1f         1234.875                +1234.9 
139 %+8.1f          1234.875                 +1234.9
140 %+-8.1f         -1234.875               -1234.9 
141 %+8.1f          -1234.875                -1234.9
142 %*.*f           [5, 2, 12.3456] 12.35
143 %f                      0                               0.000000
144 %.0f            0                               0
145 %.0f            2**38                   274877906944            Should have exact int'l rep'n
146 %.0f            0.1                             0
147 %.0f            0.6                             1                                       Known to fail with sfio, (irix|nonstop-ux|powerux); -DHAS_LDBL_SPRINTF_BUG may fix
148 %.0f            -0.6                    -1                                      Known to fail with sfio, (irix|nonstop-ux|powerux); -DHAS_LDBL_SPRINTF_BUG may fix
149 %.0f            1.6     2
150 %.0f            -1.6                    -2
151 %.0f            1                               1
152 %#.0f           1                               1.
153 %.0lf           1                               1                                       'l' should have no effect
154 %.0hf           1                               %.0hf INVALID           'h' should be rejected
155 %g                      12345.6789              12345.7
156 %+g                     12345.6789              +12345.7
157 %#g                     12345.6789              12345.7
158 %.0g            -0.0                    -0                                      C99 standard mandates minus sign but C89 does not skip: MSWin32 VMS hpux:10.20 openbsd netbsd:1.5 irix
159 %.0g            12345.6789              1e+04
160 %#.0g           12345.6789              1.e+04
161 %.2g            12345.6789              1.2e+04
162 %.*g            [2, 12345.6789] 1.2e+04
163 %.9g            12345.6789              12345.6789
164 %12.9g          12345.6789                12345.6789
165 %012.9g         12345.6789              0012345.6789
166 %-12.9g         12345.6789              12345.6789  
167 %*.*g           [-12, 9, 12345.6789]    12345.6789  
168 %-012.9g                12345.6789      12345.6789  
169 %g                      -12345.6789             -12345.7
170 %+g                     -12345.6789             -12345.7
171 %g                      1234567.89              1.23457e+06
172 %+g                     1234567.89              +1.23457e+06
173 %#g                     1234567.89              1.23457e+06
174 %g                      -1234567.89             -1.23457e+06
175 %+g                     -1234567.89             -1.23457e+06
176 %#g                     -1234567.89             -1.23457e+06
177 %g                      0.00012345              0.00012345
178 %g                      0.000012345             1.2345e-05
179 %g                      1234567E96              1.23457e+102
180 %g                      .1234567E-101   1.23457e-102
181 %g                      0                               0
182 %13g            1234567.89                1.23457e+06
183 %+13g           1234567.89               +1.23457e+06
184 %013g           1234567.89              001.23457e+06
185 %-13g           1234567.89              1.23457e+06  
186 %g                      .1234567E-101   1.23457e-102    exponent too small skip: os390
187 %g                      1234567E96              1.23457e+102    exponent too big skip: os390
188 %h                      ''                              %h INVALID
189 %i                      123456.789              123456  Synonym for %d
190 %j                      ''                              %j INVALID
191 %k                      ''                              %k INVALID
192 %l                      ''                              %l INVALID
193 %m                      ''                              %m INVALID
194 %s                      sprintf('%%n%n %d', $n, $n)     %n 2    Slight sneakiness to test %n
195 %o                      2**32-1                 37777777777
196 %+o                     2**32-1                 37777777777
197 %#o                     2**32-1                 037777777777
198 %o                      642                             1202                    check smaller octals across platforms
199 %+o                     642                             1202
200 %#o                     642                             01202
201 %d      $p=sprintf('%p',$p);$p=~/^[0-9a-f]+$/   1       Coarse hack: hex from %p?
202 %d      $p=sprintf('%-8p',$p);$p=~/^[0-9a-f]+\s*$/      1       Coarse hack: hex from %p?
203 %#p     ''      %#p INVALID
204 %q      ''      %q INVALID
205 %r      ''      %r INVALID
206 %s      'string'        string
207 %10s    'string'            string
208 %+10s   'string'            string
209 %#10s   'string'            string
210 %010s   'string'        0000string
211 %0*s    [10, 'string']  0000string
212 %-10s   'string'        string    
213 %3s     'string'        string
214 %.3s    'string'        str
215 %.*s    [3, 'string']   str
216 %t      ''      %t INVALID
217 %u      2**32-1 4294967295
218 %+u     2**32-1 4294967295
219 %#u     2**32-1 4294967295
220 %12u    2**32-1   4294967295
221 %012u   2**32-1 004294967295
222 %-12u   2**32-1 4294967295  
223 %-012u  2**32-1 4294967295  
224 %v      ''      %v INVALID
225 %w      ''      %w INVALID
226 %x      2**32-1 ffffffff
227 %+x     2**32-1 ffffffff
228 %#x     2**32-1 0xffffffff
229 %10x    2**32-1   ffffffff
230 %010x   2**32-1 00ffffffff
231 %-10x   2**32-1 ffffffff  
232 %-010x  2**32-1 ffffffff  
233 %0-10x  2**32-1 ffffffff  
234 %0*x    [-10, ,2**32-1] ffffffff  
235 %vx     [version::qv("1.2.3")]  1.2.3
236 %vx     [version::qv("1.20.300")]       1.14.12c
237 %y      ''      %y INVALID
238 %z      ''      %z INVALID
239 %2$d %1$d       [12, 34]        34 12
240 %*2$d   [12, 3]  12
241 %2$d %d [12, 34]        34 12
242 %2$d %d %d      [12, 34]        34 12 34
243 %3$d %d %d      [12, 34, 56]    56 12 34
244 %2$*3$d %d      [12, 34, 3]      34 12
245 %*3$2$d %d      [12, 34, 3]     %*3$2$d 12 INVALID
246 %2$d    12      0 UNINIT
247 %0$d    12      %0$d INVALID
248 %1$$d   12      %1$$d INVALID
249 %1$1$d  12      %1$1$d INVALID
250 %*2$*2$d        [12, 3] %*2$*2$d INVALID
251 %*2*2$d [12, 3] %*2*2$d INVALID
252 %*2$1d  [12, 3] %*2$1d INVALID
253 %0v2.2d ''      
254 %vc,%d  [63, 64, 65]    %vc,63 INVALID
255 %v%,%d  [63, 64, 65]    %v%,63 INVALID
256 %vd,%d  ["\x1", 2, 3]   1,2
257 %vf,%d  [1, 2, 3]       %vf,1 INVALID
258 %vF,%d  [1, 2, 3]       %vF,1 INVALID
259 %ve,%d  [1, 2, 3]       %ve,1 INVALID
260 %vE,%d  [1, 2, 3]       %vE,1 INVALID
261 %vg,%d  [1, 2, 3]       %vg,1 INVALID
262 %vG,%d  [1, 2, 3]       %vG,1 INVALID
263 %vp     ''      %vp INVALID
264 %vn     ''      %vn INVALID
265 %vs,%d  [1, 2, 3]       %vs,1 INVALID
266 %v_     ''      %v_ INVALID
267 %v#x    ''      %v#x INVALID
268 %v02x   "\x66\x6f\x6f\012"      66.6f.6f.0a
269 %#v.8b  "\141\000\142"  0b01100001.00000000.0b01100010  perl #39530
270 %#v.4o  "\141\000\142"  0141.0000.0142  perl #39530
271 %#v.3i  "\141\000\142"  097.000.098     perl #39530
272 %#v.2x  "\141\000\142"  0x61.00.0x62    perl #39530
273 %#v.2X  "\141\000\142"  0X61.00.0X62    perl #39530
274 %#v.8b  "\141\017\142"  0b01100001.0b00001111.0b01100010        perl #39530
275 %#v.4o  "\141\017\142"  0141.0017.0142  perl #39530
276 %#v.3i  "\141\017\142"  097.015.098     perl #39530
277 %#v.2x  "\141\017\142"  0x61.0x0f.0x62  perl #39530
278 %#v.2X  "\141\017\142"  0X61.0X0F.0X62  perl #39530
279 %#*v.8b ["][", "\141\000\142"]  0b01100001][00000000][0b01100010        perl #39530
280 %#*v.4o ["][", "\141\000\142"]  0141][0000][0142        perl #39530
281 %#*v.3i ["][", "\141\000\142"]  097][000][098   perl #39530
282 %#*v.2x ["][", "\141\000\142"]  0x61][00][0x62  perl #39530
283 %#*v.2X ["][", "\141\000\142"]  0X61][00][0X62  perl #39530
284 %#*v.8b ["][", "\141\017\142"]  0b01100001][0b00001111][0b01100010      perl #39530
285 %#*v.4o ["][", "\141\017\142"]  0141][0017][0142        perl #39530
286 %#*v.3i ["][", "\141\017\142"]  097][015][098   perl #39530
287 %#*v.2x ["][", "\141\017\142"]  0x61][0x0f][0x62        perl #39530
288 %#*v.2X ["][", "\141\017\142"]  0X61][0X0F][0X62        perl #39530
289 %#v.8b  "\141\x{1e01}\000\142\x{1e03}"  0b01100001.0b1111000000001.00000000.0b01100010.0b1111000000011  perl #39530
290 %#v.4o  "\141\x{1e01}\000\142\x{1e03}"  0141.017001.0000.0142.017003    perl #39530
291 %#v.3i  "\141\x{1e01}\000\142\x{1e03}"  097.7681.000.098.7683   perl #39530
292 %#v.2x  "\141\x{1e01}\000\142\x{1e03}"  0x61.0x1e01.00.0x62.0x1e03      perl #39530
293 %#v.2X  "\141\x{1e01}\000\142\x{1e03}"  0X61.0X1E01.00.0X62.0X1E03      perl #39530
294 %#v.8b  "\141\x{1e01}\017\142\x{1e03}"  0b01100001.0b1111000000001.0b00001111.0b01100010.0b1111000000011        perl #39530
295 %#v.4o  "\141\x{1e01}\017\142\x{1e03}"  0141.017001.0017.0142.017003    perl #39530
296 %#v.3i  "\141\x{1e01}\017\142\x{1e03}"  097.7681.015.098.7683   perl #39530
297 %#v.2x  "\141\x{1e01}\017\142\x{1e03}"  0x61.0x1e01.0x0f.0x62.0x1e03    perl #39530
298 %#v.2X  "\141\x{1e01}\017\142\x{1e03}"  0X61.0X1E01.0X0F.0X62.0X1E03    perl #39530
299 %V-%s   ["Hello"]       %V-Hello INVALID
300 %K %d %d        [13, 29]        %K 13 29 INVALID
301 %*.*K %d        [13, 29, 76]    %*.*K 13 INVALID
302 %4$K %d [45, 67]        %4$K 45 INVALID
303 %d %K %d        [23, 45]        23 %K 45 INVALID
304 %*v*999\$d %d %d        [11, 22, 33]    %*v*999\$d 11 22 INVALID
305 %#b     0       0
306 %#o     0       0
307 %#x     0       0
308 %2147483647$v2d ''      
309 %*2147483647$v2d        ''       UNINIT
311 # vim: sw=4 et