summaryrefslogtreecommitdiffstats
path: root/tests/format.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/format.test')
-rw-r--r--tests/format.test108
1 files changed, 64 insertions, 44 deletions
diff --git a/tests/format.test b/tests/format.test
index c440603..d43b7eb 100644
--- a/tests/format.test
+++ b/tests/format.test
@@ -15,26 +15,25 @@ if {[lsearch [namespace children] ::tcltest] == -1} {
namespace import -force ::tcltest::*
}
-# The following code is needed because some versions of SCO Unix have
-# a round-off error in sprintf which would cause some of the tests to
-# fail. Someday I hope this code shouldn't be necessary (code added
-# 9/9/91).
-
-set ::tcltest::testConstraints(roundOffBug) \
- [expr {"[format %7.1e 68.514]" != "6.8e+01"}]
+# %u output depends on word length, so this test is not portable.
+testConstraint longIs32bit [expr {int(0x80000000) < 0}]
+testConstraint longIs64bit [expr {int(0x8000000000000000) < 0}]
+testConstraint wideIs64bit \
+ [expr {(wide(0x80000000) > 0) && (wide(0x8000000000000000) < 0)}]
+testConstraint wideBiggerThanInt [expr {wide(0x80000000) != int(0x80000000)}]
test format-1.1 {integer formatting} {
format "%*d %d %d %d" 6 34 16923 -12 -1
} { 34 16923 -12 -1}
-test format-1.2 {integer formatting} {nonPortable} {
+test format-1.2 {integer formatting} {
format "%4d %4d %4d %4d %d %#x %#X" 6 34 16923 -12 -1 14 12
} { 6 34 16923 -12 -1 0xe 0XC}
-
-# %u output depends on word length, so this test is not portable.
-
-test format-1.3 {integer formatting} {nonPortable} {
+test format-1.3 {integer formatting} longIs32bit {
format "%4u %4u %4u %4u %d %#o" 6 34 16923 -12 -1 0
} { 6 34 16923 4294967284 -1 0}
+test format-1.3.1 {integer formatting} longIs64bit {
+ format "%4u %4u %4u %4u %d %#o" 6 34 16923 -12 -1 0
+} { 6 34 16923 18446744073709551604 -1 0}
test format-1.4 {integer formatting} {
format "%-4d %-4i %-4d %-4ld" 6 34 16923 -12 -1
} {6 34 16923 -12 }
@@ -44,25 +43,38 @@ test format-1.5 {integer formatting} {
test format-1.6 {integer formatting} {
format "%00*d" 6 34
} {000034}
-
# Printing negative numbers in hex or octal format depends on word
# length, so these tests are not portable.
-
-test format-1.7 {integer formatting} {nonPortable} {
+test format-1.7 {integer formatting} longIs32bit {
format "%4x %4x %4x %4x" 6 34 16923 -12 -1
} { 6 22 421b fffffff4}
-test format-1.8 {integer formatting} {nonPortable} {
+test format-1.7.1 {integer formatting} longIs64bit {
+ format "%4x %4x %4x %4x" 6 34 16923 -12 -1
+} { 6 22 421b fffffffffffffff4}
+test format-1.8 {integer formatting} longIs32bit {
format "%#x %#X %#X %#x" 6 34 16923 -12 -1
} {0x6 0X22 0X421B 0xfffffff4}
-test format-1.9 {integer formatting} {nonPortable} {
+test format-1.8.1 {integer formatting} longIs64bit {
+ format "%#x %#X %#X %#x" 6 34 16923 -12 -1
+} {0x6 0X22 0X421B 0xfffffffffffffff4}
+test format-1.9 {integer formatting} longIs32bit {
format "%#20x %#20x %#20x %#20x" 6 34 16923 -12 -1
} { 0x6 0x22 0x421b 0xfffffff4}
-test format-1.10 {integer formatting} {nonPortable} {
+test format-1.9.1 {integer formatting} longIs64bit {
+ format "%#20x %#20x %#20x %#20x" 6 34 16923 -12 -1
+} { 0x6 0x22 0x421b 0xfffffffffffffff4}
+test format-1.10 {integer formatting} longIs32bit {
format "%-#20x %-#20x %-#20x %-#20x" 6 34 16923 -12 -1
} {0x6 0x22 0x421b 0xfffffff4 }
-test format-1.11 {integer formatting} {nonPortable} {
+test format-1.10.1 {integer formatting} longIs64bit {
+ format "%-#20x %-#20x %-#20x %-#20x" 6 34 16923 -12 -1
+} {0x6 0x22 0x421b 0xfffffffffffffff4 }
+test format-1.11 {integer formatting} longIs32bit {
format "%-#20o %#-20o %#-20o %#-20o" 6 34 16923 -12 -1
} {06 042 041033 037777777764 }
+test format-1.11.1 {integer formatting} longIs64bit {
+ format "%-#20o %#-20o %#-20o %#-20o" 6 34 16923 -12 -1
+} {06 042 041033 01777777777777777777764}
test format-2.1 {string formatting} {
format "%s %s %c %s" abcd {This is a very long test string.} 120 x
@@ -129,19 +141,19 @@ test format-4.1 {e and f formats} {eformat} {
test format-4.2 {e and f formats} {eformat} {
format "%20e %20e %20e %20e" 34.2e12 68.514 -.125 -16000. .000053
} { 3.420000e+13 6.851400e+01 -1.250000e-01 -1.600000e+04}
-test format-4.3 {e and f formats} {eformat roundOffBug} {
+test format-4.3 {e and f formats} {eformat} {
format "%.1e %.1e %.1e %.1e" 34.2e12 68.514 -.126 -16000. .000053
} {3.4e+13 6.9e+01 -1.3e-01 -1.6e+04}
-test format-4.4 {e and f formats} {eformat roundOffBug} {
+test format-4.4 {e and f formats} {eformat} {
format "%020e %020e %020e %020e" 34.2e12 68.514 -.126 -16000. .000053
} {000000003.420000e+13 000000006.851400e+01 -00000001.260000e-01 -00000001.600000e+04}
-test format-4.5 {e and f formats} {eformat roundOffBug} {
+test format-4.5 {e and f formats} {eformat} {
format "%7.1e %7.1e %7.1e %7.1e" 34.2e12 68.514 -.126 -16000. .000053
} {3.4e+13 6.9e+01 -1.3e-01 -1.6e+04}
-test format-4.6 {e and f formats roundOffBug} {
+test format-4.6 {e and f formats} {
format "%f %f %f %f" 34.2e12 68.514 -.125 -16000. .000053
} {34200000000000.000000 68.514000 -0.125000 -16000.000000}
-test format-4.7 {e and f formats} {nonPortable} {
+test format-4.7 {e and f formats} {
format "%.4f %.4f %.4f %.4f %.4f" 34.2e12 68.514 -.125 -16000. .000053
} {34200000000000.0000 68.5140 -0.1250 -16000.0000 0.0001}
test format-4.8 {e and f formats} {eformat} {
@@ -354,13 +366,13 @@ test format-9.1 {long result} {
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
} {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}
-test format-10.1 {"h" format specifier} {nonPortable} {
+test format-10.1 {"h" format specifier} {
format %hd 0xffff
} -1
-test format-10.2 {"h" format specifier} {nonPortable} {
+test format-10.2 {"h" format specifier} {
format %hx 0x10fff
} fff
-test format-10.3 {"h" format specifier} {nonPortable} {
+test format-10.3 {"h" format specifier} {
format %hd 0x10000
} 0
test format-10.4 {"h" format specifier} {
@@ -412,6 +424,7 @@ test format-11.12 {XPG3 %$n specifiers} {
test format-12.1 {negative width specifiers} {
format "%*d" -47 25
} {25 }
+
test format-13.1 {tcl_precision fuzzy comparison} {
catch {unset a}
catch {unset b}
@@ -461,6 +474,7 @@ test format-13.5 {tcl_precision fuzzy comparison} {
set c [expr $a + $b]
format {%0.10f %0.12f %0.15f} $c $c $c
} {1.4444444444 1.444444444444 1.444444444443990}
+
test format-14.1 {testing MAX_FLOAT_SIZE for 0 and 1} {
format {%s} ""
} {}
@@ -480,6 +494,12 @@ test format-15.3 {testing %0..s 0 padding for chars/strings} {
test format-15.4 {testing %0..s 0 padding for chars/strings} {
format %05c 61
} {0000=}
+test format-15.5 {testing %d space padding for integers} {
+ format "(% 1d) (% 1d)" 10 -10
+} {( 10) (-10)}
+test format-15.6 {testing %d plus padding for integers} {
+ format "(%+1d) (%+1d)" 10 -10
+} {(+10) (-10)}
set a "0123456789"
set b ""
@@ -488,35 +508,23 @@ for {set i 0} {$i < 290} {incr i} {
}
for {set i 290} {$i < 400} {incr i} {
test format-16.[expr $i -289] {testing MAX_FLOAT_SIZE} {
- format {%s} $b
+ format {%s} $b
} $b
append b "x"
}
-::tcltest::testConstraint 64bitInts \
- [expr {0x80000000 > 0}]
-::tcltest::testConstraint wideIntExpressions \
- [expr {wide(0x80000000) != int(0x80000000)}]
-
-test format-17.1 {testing %d with wide} {64bitInts wideIntExpressions} {
+test format-17.1 {testing %d with wide} {wideIs64bit wideBiggerThanInt} {
format %d 7810179016327718216
} 1819043144
-test format-17.2 {testing %ld with wide} {64bitInts} {
+test format-17.2 {testing %ld with wide} {wideIs64bit} {
format %ld 7810179016327718216
} 7810179016327718216
-test format-17.3 {testing %ld with non-wide} {64bitInts} {
+test format-17.3 {testing %ld with non-wide} {wideIs64bit} {
format %ld 42
} 42
test format-17.4 {testing %l with non-integer} {
format %lf 1
} 1.000000
-test format-17.5 {type conversions with wides} {
- set a 0xAAAAAAAA ;# NB: Careful to make separate objects here!
- set b 0xAAAAAAA; append b A
- set result [expr {$a == $b}]
- format %x $a
- lappend result [expr {$a == $b}]
-} {1 1}
test format-18.1 {do not demote existing numeric values} {
set a 0xaaaaaaaa
@@ -535,7 +543,7 @@ test format-18.1 {do not demote existing numeric values} {
format %08x $b
lappend result [expr {$a == $b}]
} {1 1 1 1}
-test format-18.2 {do not demote existing numeric values} {wideIntExpressions} {
+test format-18.2 {do not demote existing numeric values} {wideBiggerThanInt} {
set a [expr {0xaaaaaaaaaa + 1}]
set b 0xaaaaaaaaab
list [format %08x $a] [expr {$a == $b}]
@@ -549,6 +557,14 @@ test format-19.1 {
list [expr { ~ $x }] [format %08x [expr { ~$x }]]
} -match regexp -result {-2414724693 f*701239ab}
+test format-19.2 {Bug 1867855} {
+ format %llx 0
+} 0
+
+test format-19.3 {Bug 2830354} {
+ string length [format %340f 0]
+} 340
+
# cleanup
catch {unset a}
catch {unset b}
@@ -556,3 +572,7 @@ catch {unset c}
catch {unset d}
::tcltest::cleanupTests
return
+
+# Local Variables:
+# mode: tcl
+# End: