diff options
Diffstat (limited to 'tcl/tests/scan.test')
-rw-r--r-- | tcl/tests/scan.test | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/tcl/tests/scan.test b/tcl/tests/scan.test index 1296d9cf3d7..4ff4841d1e6 100644 --- a/tcl/tests/scan.test +++ b/tcl/tests/scan.test @@ -14,10 +14,12 @@ # RCS: @(#) $Id$ if {[lsearch [namespace children] ::tcltest] == -1} { - package require tcltest + package require tcltest 2 namespace import -force ::tcltest::* } +::tcltest::testConstraint 64bitInts [expr {0x80000000 > 0}] + test scan-1.1 {BuildCharSet, CharInSet} { list [scan foo {%[^o]} x] $x } {1 f} @@ -231,9 +233,20 @@ test scan-4.39 {Tcl_ScanObjCmd, base-16 integer scanning} { list [scan {+1238 -123a 0123} {%x%x%x} x y z] $x $y $z } {3 4664 -4666 291} test scan-4.40 {Tcl_ScanObjCmd, base-16 integer scanning} { + # The behavior changed in 8.4a4/8.3.4cvs (6 Feb) to correctly + # return '1' for 0x1 scanned via %x, to comply with 8.0 and C scanf. + # Bug #495213 set x {} list [scan {aBcDeF AbCdEf 0x1} {%x%x%x} x y z] $x $y $z -} {3 11259375 11259375 0} +} {3 11259375 11259375 1} +test scan-4.40.1 {Tcl_ScanObjCmd, base-16 integer scanning} { + set x {} + list [scan {0xF 0x00A0B 0X0XF} {%x %x %x} x y z] $x $y $z +} {3 15 2571 0} +test scan-4.40.2 {Tcl_ScanObjCmd, base-16 integer scanning} { + catch {unset x} + list [scan {xF} {%x} x] [info exists x] +} {0 0} test scan-4.41 {Tcl_ScanObjCmd, base-unknown integer scanning} { set x {} list [scan {10 010 0x10} {%i%i%i} x y z] $x $y $z @@ -324,6 +337,35 @@ test scan-4.61 {Tcl_ScanObjCmd, set errors} { set result } {1 {couldn't set variable "z"couldn't set variable "y"} abc} +# procedure that returns the range of integers + +proc int_range {} { + for { set MIN_INT 1 } { $MIN_INT > 0 } {} { + set MIN_INT [expr { $MIN_INT << 1 }] + } + set MAX_INT [expr { ~ $MIN_INT }] + return [list $MIN_INT $MAX_INT] +} + +test scan-4.62 {scanning of large and negative octal integers} { + foreach { MIN_INT MAX_INT } [int_range] {} + set scanstring [format {%o %o %o} -1 $MIN_INT $MAX_INT] + list [scan $scanstring {%o %o %o} a b c] \ + [expr { $a == -1 }] [expr { $b == $MIN_INT }] [expr { $c == $MAX_INT }] +} {3 1 1 1} +test scan-4.63 {scanning of large and negative hex integers} { + foreach { MIN_INT MAX_INT } [int_range] {} + set scanstring [format {%x %x %x} -1 $MIN_INT $MAX_INT] + list [scan $scanstring {%x %x %x} a b c] \ + [expr { $a == -1 }] [expr { $b == $MIN_INT }] [expr { $c == $MAX_INT }] +} {3 1 1 1} + +# clean up from last two tests + +catch { + rename int_range {} +} + test scan-5.1 {integer scanning} { set a {}; set b {}; set c {}; set d {} list [scan "-20 1476 \n33 0" "%d %d %d %d" a b c d] $a $b $c $d @@ -376,6 +418,12 @@ test scan-5.11 {integer scanning} {nonPortable} { [expr {$b == -16 || $b == 0x7fffffff}] } {2 4294967280 1} +test scan-5.12 {integer scanning} {64bitInts} { + set a {}; set b {}; set c {} + list [scan "7810179016327718216,6c63546f6c6c6548,661432506755433062510" \ + %ld,%lx,%lo a b c] $a $b $c +} {3 7810179016327718216 7810179016327718216 7810179016327718216} + test scan-6.1 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} list [scan "2.1 -3.0e8 .99962 a" "%f%g%e%f" a b c d] $a $b $c $d @@ -630,18 +678,3 @@ test scan-13.8 {Tcl_ScanObjCmd, inline XPG case lots of arguments} { # cleanup ::tcltest::cleanupTests return - - - - - - - - - - - - - - - |