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