Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/format.test @ 68

Last change on this file since 68 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 19.8 KB
Line 
1# Commands covered:  format
2#
3# This file contains a collection of tests for one or more of the Tcl
4# built-in commands.  Sourcing this file into Tcl runs the tests and
5# generates output for errors.  No output means no errors were found.
6#
7# Copyright (c) 1991-1994 The Regents of the University of California.
8# Copyright (c) 1994-1998 Sun Microsystems, Inc.
9#
10# See the file "license.terms" for information on usage and redistribution
11# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12#
13# RCS: @(#) $Id: format.test,v 1.25 2008/01/10 16:09:23 dgp Exp $
14
15if {[lsearch [namespace children] ::tcltest] == -1} {
16    package require tcltest 2
17    namespace import -force ::tcltest::*
18}
19
20# %u output depends on word length, so this test is not portable.
21testConstraint longIs32bit [expr {int(0x80000000) < 0}]
22testConstraint longIs64bit [expr {int(0x8000000000000000) < 0}]
23testConstraint wideIs64bit \
24        [expr {(wide(0x80000000) > 0) && (wide(0x8000000000000000) < 0)}]
25testConstraint wideBiggerThanInt [expr {wide(0x80000000) != int(0x80000000)}]
26
27test format-1.1 {integer formatting} {
28    format "%*d %d %d %d" 6 34 16923 -12 -1
29} {    34 16923 -12 -1}
30test format-1.2 {integer formatting} {
31    format "%4d %4d %4d %4d %d %#x %#X" 6 34 16923 -12 -1 14 12
32} {   6   34 16923  -12 -1 0xe 0XC}
33test format-1.3 {integer formatting} longIs32bit {
34    format "%4u %4u %4u %4u %d %#o" 6 34 16923 -12 -1 0
35} {   6   34 16923 4294967284 -1 0}
36test format-1.3.1 {integer formatting} longIs64bit {
37    format "%4u %4u %4u %4u %d %#o" 6 34 16923 -12 -1 0
38} {   6   34 16923 18446744073709551604 -1 0}
39test format-1.4 {integer formatting} {
40    format "%-4d %-4i %-4d %-4ld" 6 34 16923 -12 -1
41} {6    34   16923 -12 }
42test format-1.5 {integer formatting} {
43    format "%04d %04d %04d %04i" 6 34 16923 -12 -1
44} {0006 0034 16923 -012}
45test format-1.6 {integer formatting} {
46    format "%00*d" 6 34
47} {000034}
48# Printing negative numbers in hex or octal format depends on word
49# length, so these tests are not portable.
50test format-1.7 {integer formatting} longIs32bit {
51    format "%4x %4x %4x %4x" 6 34 16923 -12 -1
52} {   6   22 421b fffffff4}
53test format-1.7.1 {integer formatting} longIs64bit {
54    format "%4x %4x %4x %4x" 6 34 16923 -12 -1
55} {   6   22 421b fffffffffffffff4}
56test format-1.8 {integer formatting} longIs32bit {
57    format "%#x %#X %#X %#x" 6 34 16923 -12 -1
58} {0x6 0X22 0X421B 0xfffffff4}
59test format-1.8.1 {integer formatting} longIs64bit {
60    format "%#x %#X %#X %#x" 6 34 16923 -12 -1
61} {0x6 0X22 0X421B 0xfffffffffffffff4}
62test format-1.9 {integer formatting} longIs32bit {
63    format "%#20x %#20x %#20x %#20x" 6 34 16923 -12 -1
64} {                 0x6                 0x22               0x421b           0xfffffff4}
65test format-1.9.1 {integer formatting} longIs64bit {
66    format "%#20x %#20x %#20x %#20x" 6 34 16923 -12 -1
67} {                 0x6                 0x22               0x421b   0xfffffffffffffff4}
68test format-1.10 {integer formatting} longIs32bit {
69    format "%-#20x %-#20x %-#20x %-#20x" 6 34 16923 -12 -1
70} {0x6                  0x22                 0x421b               0xfffffff4          }
71test format-1.10.1 {integer formatting} longIs64bit {
72    format "%-#20x %-#20x %-#20x %-#20x" 6 34 16923 -12 -1
73} {0x6                  0x22                 0x421b               0xfffffffffffffff4  }
74test format-1.11 {integer formatting} longIs32bit {
75    format "%-#20o %#-20o %#-20o %#-20o" 6 34 16923 -12 -1
76} {06                   042                  041033               037777777764        }
77test format-1.11.1 {integer formatting} longIs64bit {
78    format "%-#20o %#-20o %#-20o %#-20o" 6 34 16923 -12 -1
79} {06                   042                  041033               01777777777777777777764}
80
81test format-2.1 {string formatting} {
82    format "%s %s %c %s" abcd {This is a very long test string.} 120 x
83} {abcd This is a very long test string. x x}
84test format-2.2 {string formatting} {
85    format "%20s %20s %20c %20s" abcd {This is a very long test string.} 120 x
86} {                abcd This is a very long test string.                    x                    x}
87test format-2.3 {string formatting} {
88    format "%.10s %.10s %c %.10s" abcd {This is a very long test string.} 120 x
89} {abcd This is a  x x}
90test format-2.4 {string formatting} {
91    format "%s %s %% %c %s" abcd {This is a very long test string.} 120 x
92} {abcd This is a very long test string. % x x}
93test format-2.5 {string formatting, embedded nulls} {
94    format "%10s" abc\0def
95} "   abc\0def"
96test format-2.6 {string formatting, international chars} {
97    format "%10s" abc\ufeffdef
98} "   abc\ufeffdef"
99test format-2.7 {string formatting, international chars} {
100    format "%.5s" abc\ufeffdef
101} "abc\ufeffd"
102test format-2.8 {string formatting, international chars} {
103    format "foo\ufeffbar%s" baz
104} "foo\ufeffbarbaz"
105test format-2.9 {string formatting, width} {
106    format "a%5sa" f
107} "a    fa"
108test format-2.10 {string formatting, width} {
109    format "a%-5sa" f
110} "af    a"
111test format-2.11 {string formatting, width} {
112    format "a%2sa" foo
113} "afooa"
114test format-2.12 {string formatting, width} {
115    format "a%0sa" foo
116} "afooa"
117test format-2.13 {string formatting, precision} {
118    format "a%.2sa" foobarbaz
119} "afoa"
120test format-2.14 {string formatting, precision} {
121    format "a%.sa" foobarbaz
122} "aa"
123test format-2.15 {string formatting, precision} {
124    list [catch {format "a%.-2sa" foobarbaz} msg] $msg
125} {1 {bad field specifier "-"}}
126test format-2.16 {string formatting, width and precision} {
127    format "a%5.2sa" foobarbaz
128} "a   foa"
129test format-2.17 {string formatting, width and precision} {
130    format "a%5.7sa" foobarbaz
131} "afoobarba"
132
133test format-3.1 {Tcl_FormatObjCmd: character formatting} {
134    format "|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|" 65 65 65 65 65 65 3 65 -4 65
135} "|A|A|A|A|A     |     A|  A|A   |"
136test format-3.2 {Tcl_FormatObjCmd: international character formatting} {
137    format "|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|" 0xa2 0x4e4e 0x25a 0xc3 0xff08 0 3 0x6575 -4 0x4e4f
138} "|\ua2|\u4e4e|\u25a|\uc3|\uff08     |     \0|  \u6575|\u4e4f   |"
139
140test format-4.1 {e and f formats} {eformat} {
141    format "%e %e %e %e" 34.2e12 68.514 -.125 -16000. .000053
142} {3.420000e+13 6.851400e+01 -1.250000e-01 -1.600000e+04}
143test format-4.2 {e and f formats} {eformat} {
144    format "%20e %20e %20e %20e" 34.2e12 68.514 -.125 -16000. .000053
145} {        3.420000e+13         6.851400e+01        -1.250000e-01        -1.600000e+04}
146test format-4.3 {e and f formats} {eformat} {
147    format "%.1e %.1e %.1e %.1e" 34.2e12 68.514 -.126 -16000. .000053
148} {3.4e+13 6.9e+01 -1.3e-01 -1.6e+04}
149test format-4.4 {e and f formats} {eformat} {
150    format "%020e %020e %020e %020e" 34.2e12 68.514 -.126 -16000. .000053
151} {000000003.420000e+13 000000006.851400e+01 -00000001.260000e-01 -00000001.600000e+04}
152test format-4.5 {e and f formats} {eformat} {
153    format "%7.1e %7.1e %7.1e %7.1e" 34.2e12 68.514 -.126 -16000. .000053
154} {3.4e+13 6.9e+01 -1.3e-01 -1.6e+04}
155test format-4.6 {e and f formats} {
156    format "%f %f %f %f" 34.2e12 68.514 -.125 -16000. .000053
157} {34200000000000.000000 68.514000 -0.125000 -16000.000000}
158test format-4.7 {e and f formats} {
159    format "%.4f %.4f %.4f %.4f %.4f" 34.2e12 68.514 -.125 -16000. .000053
160} {34200000000000.0000 68.5140 -0.1250 -16000.0000 0.0001}
161test format-4.8 {e and f formats} {eformat} {
162    format "%.4e %.5e %.6e" -9.99996 -9.99996 9.99996
163} {-1.0000e+01 -9.99996e+00 9.999960e+00}
164test format-4.9 {e and f formats} {
165    format "%.4f %.5f %.6f" -9.99996 -9.99996 9.99996
166} {-10.0000 -9.99996 9.999960}
167test format-4.10 {e and f formats} {
168    format "%20f %-20f %020f" -9.99996 -9.99996 9.99996
169} {           -9.999960 -9.999960            0000000000009.999960}
170test format-4.11 {e and f formats} {
171    format "%-020f %020f" -9.99996 -9.99996 9.99996
172} {-9.999960            -000000000009.999960}
173test format-4.12 {e and f formats} {eformat} {
174    format "%.0e %#.0e" -9.99996 -9.99996 9.99996
175} {-1e+01 -1.e+01}
176test format-4.13 {e and f formats} {
177    format "%.0f %#.0f" -9.99996 -9.99996 9.99996
178} {-10 -10.}
179test format-4.14 {e and f formats} {
180    format "%.4f %.5f %.6f" -9.99996 -9.99996 9.99996
181} {-10.0000 -9.99996 9.999960}
182test format-4.15 {e and f formats} {
183    format "%3.0f %3.0f %3.0f %3.0f" 1.0 1.1 1.01 1.001
184} {  1   1   1   1}
185test format-4.16 {e and f formats} {
186    format "%3.1f %3.1f %3.1f %3.1f" 0.0 0.1 0.01 0.001
187} {0.0 0.1 0.0 0.0}
188
189test format-5.1 {g-format} {eformat} {
190    format "%.3g" 12341.0
191} {1.23e+04}
192test format-5.2 {g-format} {eformat} {
193    format "%.3G" 1234.12345
194} {1.23E+03}
195test format-5.3 {g-format} {
196    format "%.3g" 123.412345
197} {123}
198test format-5.4 {g-format} {
199    format "%.3g" 12.3412345
200} {12.3}
201test format-5.5 {g-format} {
202    format "%.3g" 1.23412345
203} {1.23}
204test format-5.6 {g-format} {
205    format "%.3g" 1.23412345
206} {1.23}
207test format-5.7 {g-format} {
208    format "%.3g" .123412345
209} {0.123}
210test format-5.8 {g-format} {
211    format "%.3g" .012341
212} {0.0123}
213test format-5.9 {g-format} {
214    format "%.3g" .0012341
215} {0.00123}
216test format-5.10 {g-format} {
217    format "%.3g" .00012341
218} {0.000123}
219test format-5.11 {g-format} {eformat} {
220    format "%.3g" .00001234
221} {1.23e-05}
222test format-5.12 {g-format} {eformat} {
223    format "%.4g" 9999.6
224} {1e+04}
225test format-5.13 {g-format} {
226    format "%.4g" 999.96
227} {1000}
228test format-5.14 {g-format} {
229    format "%.3g" 1.0
230} {1}
231test format-5.15 {g-format} {
232    format "%.3g" .1
233} {0.1}
234test format-5.16 {g-format} {
235    format "%.3g" .01
236} {0.01}
237test format-5.17 {g-format} {
238    format "%.3g" .001
239} {0.001}
240test format-5.18 {g-format} {eformat} {
241    format "%.3g" .00001
242} {1e-05}
243test format-5.19 {g-format} {eformat} {
244    format "%#.3g" 1234.0
245} {1.23e+03}
246test format-5.20 {g-format} {eformat} {
247    format "%#.3G" 9999.5
248} {1.00E+04}
249
250test format-6.1 {floating-point zeroes} {eformat} {
251    format "%e %f %g" 0.0 0.0 0.0 0.0
252} {0.000000e+00 0.000000 0}
253test format-6.2 {floating-point zeroes} {eformat} {
254    format "%.4e %.4f %.4g" 0.0 0.0 0.0 0.0
255} {0.0000e+00 0.0000 0}
256test format-6.3 {floating-point zeroes} {eformat} {
257    format "%#.4e %#.4f %#.4g" 0.0 0.0 0.0 0.0
258} {0.0000e+00 0.0000 0.000}
259test format-6.4 {floating-point zeroes} {eformat} {
260    format "%.0e %.0f %.0g" 0.0 0.0 0.0 0.0
261} {0e+00 0 0}
262test format-6.5 {floating-point zeroes} {eformat} {
263    format "%#.0e %#.0f %#.0g" 0.0 0.0 0.0 0.0
264} {0.e+00 0. 0.}
265test format-6.6 {floating-point zeroes} {
266    format "%3.0f %3.0f %3.0f %3.0f" 0.0 0.0 0.0 0.0
267} {  0   0   0   0}
268test format-6.7 {floating-point zeroes} {
269    format "%3.0f %3.0f %3.0f %3.0f" 1.0 1.1 1.01 1.001
270} {  1   1   1   1}
271test format-6.8 {floating-point zeroes} {
272    format "%3.1f %3.1f %3.1f %3.1f" 0.0 0.1 0.01 0.001
273} {0.0 0.1 0.0 0.0}
274
275test format-7.1 {various syntax features} {
276    format "%*.*f" 12 3 12.345678901
277} {      12.346}
278test format-7.2 {various syntax features} {
279    format "%0*.*f" 12 3 12.345678901
280} {00000012.346}
281test format-7.3 {various syntax features} {
282    format "\*\t\\n"
283} {*    \n}
284
285test format-8.1 {error conditions} {
286    catch format
287} 1
288test format-8.2 {error conditions} {
289    catch format msg
290    set msg
291} {wrong # args: should be "format formatString ?arg arg ...?"}
292test format-8.3 {error conditions} {
293    catch {format %*d}
294} 1
295test format-8.4 {error conditions} {
296    catch {format %*d} msg
297    set msg
298} {not enough arguments for all format specifiers}
299test format-8.5 {error conditions} {
300    catch {format %*.*f 12}
301} 1
302test format-8.6 {error conditions} {
303    catch {format %*.*f 12} msg
304    set msg
305} {not enough arguments for all format specifiers}
306test format-8.7 {error conditions} {
307    catch {format %*.*f 12 3}
308} 1
309test format-8.8 {error conditions} {
310    catch {format %*.*f 12 3} msg
311    set msg
312} {not enough arguments for all format specifiers}
313test format-8.9 {error conditions} {
314    list [catch {format %*d x 3} msg] $msg
315} {1 {expected integer but got "x"}}
316test format-8.10 {error conditions} {
317    list [catch {format %*.*f 2 xyz 3} msg] $msg
318} {1 {expected integer but got "xyz"}}
319test format-8.11 {error conditions} {
320    catch {format %d 2a}
321} 1
322test format-8.12 {error conditions} {
323    catch {format %d 2a} msg
324    set msg
325} {expected integer but got "2a"}
326test format-8.13 {error conditions} {
327    catch {format %c 2x}
328} 1
329test format-8.14 {error conditions} {
330    catch {format %c 2x} msg
331    set msg
332} {expected integer but got "2x"}
333test format-8.15 {error conditions} {
334    catch {format %f 2.1z}
335} 1
336test format-8.16 {error conditions} {
337    catch {format %f 2.1z} msg
338    set msg
339} {expected floating-point number but got "2.1z"}
340test format-8.17 {error conditions} {
341    catch {format ab%}
342} 1
343test format-8.18 {error conditions} {
344    catch {format ab% 12} msg
345    set msg
346} {format string ended in middle of field specifier}
347test format-8.19 {error conditions} {
348    catch {format %q x}
349} 1
350test format-8.20 {error conditions} {
351    catch {format %q x} msg
352    set msg
353} {bad field specifier "q"}
354test format-8.21 {error conditions} {
355    catch {format %d}
356} 1
357test format-8.22 {error conditions} {
358    catch {format %d} msg
359    set msg
360} {not enough arguments for all format specifiers}
361test format-8.23 {error conditions} {
362    catch {format "%d %d" 24 xyz} msg
363    set msg
364} {expected integer but got "xyz"}
365
366test format-9.1 {long result} {
367    set a {1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}
368    format {1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG %s %s} $a $a
369} {1111 2222 3333 4444 5555 6666 7777 8888 9999 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz AAAA BBBB CCCC DDDD EEEE FFFF GGGG 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}
370
371test format-10.1 {"h" format specifier} {
372    format %hd 0xffff
373} -1
374test format-10.2 {"h" format specifier} {
375    format %hx 0x10fff
376} fff
377test format-10.3 {"h" format specifier} {
378    format %hd 0x10000
379} 0
380test format-10.4 {"h" format specifier} {
381    # Bug 1154163: This is minimal behaviour for %hx specifier!
382    format %hx 1
383} 1
384test format-10.5 {"h" format specifier} {
385    # Bug 1284178: Highly out-of-range values shouldn't cause errors
386    format %hu 0x100000000
387} 0
388
389test format-11.1 {XPG3 %$n specifiers} {
390    format {%2$d %1$d} 4 5
391} {5 4}
392test format-11.2 {XPG3 %$n specifiers} {
393    format {%2$d %1$d %1$d %3$d} 4 5 6
394} {5 4 4 6}
395test format-11.3 {XPG3 %$n specifiers} {
396    list [catch {format {%2$d %3$d} 4 5} msg] $msg
397} {1 {"%n$" argument index out of range}}
398test format-11.4 {XPG3 %$n specifiers} {
399    list [catch {format {%2$d %0$d} 4 5 6} msg] $msg
400} {1 {"%n$" argument index out of range}}
401test format-11.5 {XPG3 %$n specifiers} {
402    list [catch {format {%d %1$d} 4 5 6} msg] $msg
403} {1 {cannot mix "%" and "%n$" conversion specifiers}}
404test format-11.6 {XPG3 %$n specifiers} {
405    list [catch {format {%2$d %d} 4 5 6} msg] $msg
406} {1 {cannot mix "%" and "%n$" conversion specifiers}}
407test format-11.7 {XPG3 %$n specifiers} {
408    list [catch {format {%2$d %3d} 4 5 6} msg] $msg
409} {1 {cannot mix "%" and "%n$" conversion specifiers}}
410test format-11.8 {XPG3 %$n specifiers} {
411    format {%2$*d %3$d} 1 10 4
412} {         4 4}
413test format-11.9 {XPG3 %$n specifiers} {
414    format {%2$.*s %4$d} 1 5 abcdefghijklmnop 44
415} {abcde 44}
416test format-11.10 {XPG3 %$n specifiers} {
417    list [catch {format {%2$*d} 4} msg] $msg
418} {1 {"%n$" argument index out of range}}
419test format-11.11 {XPG3 %$n specifiers} {
420    list [catch {format {%2$*d} 4 5} msg] $msg
421} {1 {"%n$" argument index out of range}}
422test format-11.12 {XPG3 %$n specifiers} {
423    list [catch {format {%2$*d} 4 5 6} msg] $msg
424} {0 {    6}}
425
426test format-12.1 {negative width specifiers} {
427    format "%*d" -47 25
428} {25                                             }
429
430test format-13.1 {tcl_precision fuzzy comparison} {
431    catch {unset a}
432    catch {unset b}
433    catch {unset c}
434    catch {unset d}
435    set a 0.0000000000001
436    set b 0.00000000000001
437    set c 0.00000000000000001
438    set d [expr $a + $b + $c]
439    format {%0.10f %0.12f %0.15f %0.17f} $d $d $d $d
440} {0.0000000000 0.000000000000 0.000000000000110 0.00000000000011001}
441test format-13.2 {tcl_precision fuzzy comparison} {
442    catch {unset a}
443    catch {unset b}
444    catch {unset c}
445    catch {unset d}
446    set a 0.000000000001
447    set b 0.000000000000005
448    set c 0.0000000000000008
449    set d [expr $a + $b + $c]
450    format {%0.10f %0.12f %0.15f %0.17f} $d $d $d $d
451} {0.0000000000 0.000000000001 0.000000000001006 0.00000000000100580}
452test format-13.3 {tcl_precision fuzzy comparison} {
453    catch {unset a}
454    catch {unset b}
455    catch {unset c}
456    set a 0.00000000000099
457    set b 0.000000000000011
458    set c [expr $a + $b]
459    format {%0.10f %0.12f %0.15f %0.17f} $c $c $c $c
460} {0.0000000000 0.000000000001 0.000000000001001 0.00000000000100100}
461test format-13.4 {tcl_precision fuzzy comparison} {
462    catch {unset a}
463    catch {unset b}
464    catch {unset c}
465    set a 0.444444444444
466    set b 0.33333333333333
467    set c [expr $a + $b]
468    format {%0.10f %0.12f %0.15f %0.16f} $c $c $c $c
469} {0.7777777778 0.777777777777 0.777777777777330 0.7777777777773300}
470test format-13.5 {tcl_precision fuzzy comparison} {
471    catch {unset a}
472    catch {unset b}
473    catch {unset c}
474    set a 0.444444444444
475    set b 0.99999999999999
476    set c [expr $a + $b]
477    format {%0.10f %0.12f %0.15f} $c $c $c
478} {1.4444444444 1.444444444444 1.444444444443990}
479
480test format-14.1 {testing MAX_FLOAT_SIZE for 0 and 1} {
481    format {%s} ""
482} {}
483test format-14.2 {testing MAX_FLOAT_SIZE for 0 and 1} {
484    format {%s} "a"
485} {a}
486
487test format-15.1 {testing %0..s 0 padding for chars/strings} {
488    format %05s a
489} {0000a}
490test format-15.2 {testing %0..s 0 padding for chars/strings} {
491    format "% 5s" a
492} {    a}
493test format-15.3 {testing %0..s 0 padding for chars/strings} {
494    format %5s a
495} {    a}
496test format-15.4 {testing %0..s 0 padding for chars/strings} {
497    format %05c 61
498} {0000=}
499
500set a "0123456789"
501set b ""
502for {set i 0} {$i < 290} {incr i} {
503    append b $a
504}
505for {set i 290} {$i < 400} {incr i} {
506    test format-16.[expr $i -289] {testing MAX_FLOAT_SIZE} {
507        format {%s} $b
508    } $b
509    append b "x"
510}
511
512test format-17.1 {testing %d with wide} {wideIs64bit wideBiggerThanInt} {
513    format %d 7810179016327718216
514} 1819043144
515test format-17.2 {testing %ld with wide} {wideIs64bit} {
516    format %ld 7810179016327718216
517} 7810179016327718216
518test format-17.3 {testing %ld with non-wide} {wideIs64bit} {
519    format %ld 42
520} 42
521test format-17.4 {testing %l with non-integer} {
522    format %lf 1
523} 1.000000
524
525test format-18.1 {do not demote existing numeric values} {
526    set a 0xaaaaaaaa
527    # Ensure $a and $b are separate objects
528    set b 0xaaaa
529    append b aaaa
530
531    set result [expr {$a == $b}]
532    format %08lx $b
533    lappend result [expr {$a == $b}]
534
535    set b 0xaaaa
536    append b aaaa
537
538    lappend result [expr {$a == $b}]
539    format %08x $b
540    lappend result [expr {$a == $b}]
541} {1 1 1 1}
542test format-18.2 {do not demote existing numeric values} {wideBiggerThanInt} {
543    set a [expr {0xaaaaaaaaaa + 1}]
544    set b 0xaaaaaaaaab
545    list [format %08x $a] [expr {$a == $b}]
546} {aaaaaaab 1}
547
548test format-19.1 {
549    regression test - tcl-core message by Brian Griffin on
550    26 0ctober 2004
551} -body {
552    set x 0x8fedc654
553    list [expr { ~ $x }] [format %08x [expr { ~$x }]]
554} -match regexp -result {-2414724693 f*701239ab}
555
556test format-19.2 {Bug 1867855} {
557    format %llx 0
558} 0
559
560# cleanup
561catch {unset a}
562catch {unset b}
563catch {unset c}
564catch {unset d}
565::tcltest::cleanupTests
566return
567
568# Local Variables:
569# mode: tcl
570# End:
Note: See TracBrowser for help on using the repository browser.