sl@0: # Commands covered:  none
sl@0: #
sl@0: # This file contains a collection of tests for the procedures in the
sl@0: # file tclGet.c.  Sourcing this file into Tcl runs the tests and
sl@0: # generates output for errors.  No output means no errors were found.
sl@0: #
sl@0: # Copyright (c) 1995-1996 Sun Microsystems, Inc.
sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0: #
sl@0: # See the file "license.terms" for information on usage and redistribution
sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0: #
sl@0: # RCS: @(#) $Id: get.test,v 1.8 2002/11/19 02:34:50 hobbs Exp $
sl@0: 
sl@0: if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0:     package require tcltest
sl@0:     namespace import -force ::tcltest::*
sl@0: }
sl@0: 
sl@0: test get-1.1 {Tcl_GetInt procedure} {
sl@0:     set x 44
sl@0:     incr x { 	  22}
sl@0: } {66}
sl@0: test get-1.2 {Tcl_GetInt procedure} {
sl@0:     set x 44
sl@0:     incr x -3
sl@0: } {41}
sl@0: test get-1.3 {Tcl_GetInt procedure} {
sl@0:     set x 44
sl@0:     incr x +8
sl@0: } {52}
sl@0: test get-1.4 {Tcl_GetInt procedure} {
sl@0:     set x 44
sl@0:     list [catch {incr x foo} msg] $msg
sl@0: } {1 {expected integer but got "foo"}}
sl@0: test get-1.5 {Tcl_GetInt procedure} {
sl@0:     set x 44
sl@0:     list [catch {incr x {16	 }} msg] $msg
sl@0: } {0 60}
sl@0: test get-1.6 {Tcl_GetInt procedure} {
sl@0:     set x 44
sl@0:     list [catch {incr x {16	 x}} msg] $msg
sl@0: } {1 {expected integer but got "16	 x"}}
sl@0: 
sl@0: # The following tests are non-portable because they depend on
sl@0: # word size.
sl@0: 
sl@0: if {wide(0x80000000) > wide(0)} {
sl@0:     test get-1.7 {Tcl_GetInt procedure} {
sl@0: 	set x 44
sl@0: 	list [catch {eval incr x 18446744073709551616} msg] $msg $errorCode
sl@0:     } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
sl@0:     test get-1.8 {Tcl_GetInt procedure} {
sl@0: 	set x 0
sl@0: 	list [catch {incr x 18446744073709551614} msg] $msg
sl@0:     } {0 -2}
sl@0:     test get-1.9 {Tcl_GetInt procedure} {
sl@0: 	set x 0
sl@0: 	list [catch {incr x +18446744073709551614} msg] $msg
sl@0:     } {0 -2}
sl@0:     test get-1.10 {Tcl_GetInt procedure} {
sl@0: 	set x 0
sl@0: 	list [catch {incr x -18446744073709551614} msg] $msg
sl@0:     } {0 2}
sl@0: } else {
sl@0:     test get-1.11 {Tcl_GetInt procedure} {
sl@0: 	set x 44
sl@0: 	list [catch {incr x 4294967296} msg] $msg $errorCode
sl@0:     } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
sl@0:     test get-1.12 {Tcl_GetInt procedure} {
sl@0: 	set x 0
sl@0: 	list [catch {incr x 4294967294} msg] $msg
sl@0:     } {0 -2}
sl@0:     test get-1.13 {Tcl_GetInt procedure} {
sl@0: 	set x 0
sl@0: 	list [catch {incr x +4294967294} msg] $msg
sl@0:     } {0 -2}
sl@0:     test get-1.14 {Tcl_GetInt procedure} {
sl@0: 	set x 0
sl@0: 	list [catch {incr x -4294967294} msg] $msg
sl@0:     } {0 2}
sl@0: }
sl@0: 
sl@0: test get-2.1 {Tcl_GetInt procedure} {
sl@0:     format %g 1.23
sl@0: } {1.23}
sl@0: test get-2.2 {Tcl_GetInt procedure} {
sl@0:     format %g { 	 1.23 	}
sl@0: } {1.23}
sl@0: test get-2.3 {Tcl_GetInt procedure} {
sl@0:     list [catch {format %g clip} msg] $msg
sl@0: } {1 {expected floating-point number but got "clip"}}
sl@0: test get-2.4 {Tcl_GetInt procedure} {nonPortable} {
sl@0:     list [catch {format %g .000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001} msg] $msg $errorCode
sl@0: } {1 {floating-point value too small to represent} {ARITH UNDERFLOW {floating-point value too small to represent}}}
sl@0: 
sl@0: test get-3.1 {Tcl_GetInt(FromObj), bad numbers} {
sl@0:     # SF bug #634856
sl@0:     set result ""
sl@0:     set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1" "+12345678987654321" "++12345678987654321"]
sl@0:     foreach num $numbers {
sl@0: 	lappend result [catch {format %ld $num} msg] $msg
sl@0:     }
sl@0:     set result
sl@0: } {0 1 0 1 1 {expected integer but got "++1"} 1 {expected integer but got "+-1"} 1 {expected integer but got "-+1"} 0 -1 1 {expected integer but got "--1"} 1 {expected integer but got "- +1"} 0 12345678987654321 1 {expected integer but got "++12345678987654321"}}
sl@0: test get-3.2 {Tcl_GetDouble(FromObj), bad numbers} {
sl@0:     set result ""
sl@0:     set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"]
sl@0:     foreach num $numbers {
sl@0: 	lappend result [catch {format %g $num} msg] $msg
sl@0:     }
sl@0:     set result
sl@0: } {0 1 0 1 1 {expected floating-point number but got "++1.0"} 1 {expected floating-point number but got "+-1.0"} 1 {expected floating-point number but got "-+1.0"} 0 -1 1 {expected floating-point number but got "--1.0"} 1 {expected floating-point number but got "- +1.0"}}
sl@0: 
sl@0: # cleanup
sl@0: ::tcltest::cleanupTests
sl@0: return
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: