os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/get.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 # Commands covered:  none
     2 #
     3 # This file contains a collection of tests for the procedures in the
     4 # file tclGet.c.  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) 1995-1996 Sun Microsystems, Inc.
     8 # Copyright (c) 1998-1999 by Scriptics Corporation.
     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: get.test,v 1.8 2002/11/19 02:34:50 hobbs Exp $
    14 
    15 if {[lsearch [namespace children] ::tcltest] == -1} {
    16     package require tcltest
    17     namespace import -force ::tcltest::*
    18 }
    19 
    20 test get-1.1 {Tcl_GetInt procedure} {
    21     set x 44
    22     incr x { 	  22}
    23 } {66}
    24 test get-1.2 {Tcl_GetInt procedure} {
    25     set x 44
    26     incr x -3
    27 } {41}
    28 test get-1.3 {Tcl_GetInt procedure} {
    29     set x 44
    30     incr x +8
    31 } {52}
    32 test get-1.4 {Tcl_GetInt procedure} {
    33     set x 44
    34     list [catch {incr x foo} msg] $msg
    35 } {1 {expected integer but got "foo"}}
    36 test get-1.5 {Tcl_GetInt procedure} {
    37     set x 44
    38     list [catch {incr x {16	 }} msg] $msg
    39 } {0 60}
    40 test get-1.6 {Tcl_GetInt procedure} {
    41     set x 44
    42     list [catch {incr x {16	 x}} msg] $msg
    43 } {1 {expected integer but got "16	 x"}}
    44 
    45 # The following tests are non-portable because they depend on
    46 # word size.
    47 
    48 if {wide(0x80000000) > wide(0)} {
    49     test get-1.7 {Tcl_GetInt procedure} {
    50 	set x 44
    51 	list [catch {eval incr x 18446744073709551616} msg] $msg $errorCode
    52     } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
    53     test get-1.8 {Tcl_GetInt procedure} {
    54 	set x 0
    55 	list [catch {incr x 18446744073709551614} msg] $msg
    56     } {0 -2}
    57     test get-1.9 {Tcl_GetInt procedure} {
    58 	set x 0
    59 	list [catch {incr x +18446744073709551614} msg] $msg
    60     } {0 -2}
    61     test get-1.10 {Tcl_GetInt procedure} {
    62 	set x 0
    63 	list [catch {incr x -18446744073709551614} msg] $msg
    64     } {0 2}
    65 } else {
    66     test get-1.11 {Tcl_GetInt procedure} {
    67 	set x 44
    68 	list [catch {incr x 4294967296} msg] $msg $errorCode
    69     } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
    70     test get-1.12 {Tcl_GetInt procedure} {
    71 	set x 0
    72 	list [catch {incr x 4294967294} msg] $msg
    73     } {0 -2}
    74     test get-1.13 {Tcl_GetInt procedure} {
    75 	set x 0
    76 	list [catch {incr x +4294967294} msg] $msg
    77     } {0 -2}
    78     test get-1.14 {Tcl_GetInt procedure} {
    79 	set x 0
    80 	list [catch {incr x -4294967294} msg] $msg
    81     } {0 2}
    82 }
    83 
    84 test get-2.1 {Tcl_GetInt procedure} {
    85     format %g 1.23
    86 } {1.23}
    87 test get-2.2 {Tcl_GetInt procedure} {
    88     format %g { 	 1.23 	}
    89 } {1.23}
    90 test get-2.3 {Tcl_GetInt procedure} {
    91     list [catch {format %g clip} msg] $msg
    92 } {1 {expected floating-point number but got "clip"}}
    93 test get-2.4 {Tcl_GetInt procedure} {nonPortable} {
    94     list [catch {format %g .000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001} msg] $msg $errorCode
    95 } {1 {floating-point value too small to represent} {ARITH UNDERFLOW {floating-point value too small to represent}}}
    96 
    97 test get-3.1 {Tcl_GetInt(FromObj), bad numbers} {
    98     # SF bug #634856
    99     set result ""
   100     set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1" "+12345678987654321" "++12345678987654321"]
   101     foreach num $numbers {
   102 	lappend result [catch {format %ld $num} msg] $msg
   103     }
   104     set result
   105 } {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"}}
   106 test get-3.2 {Tcl_GetDouble(FromObj), bad numbers} {
   107     set result ""
   108     set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"]
   109     foreach num $numbers {
   110 	lappend result [catch {format %g $num} msg] $msg
   111     }
   112     set result
   113 } {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"}}
   114 
   115 # cleanup
   116 ::tcltest::cleanupTests
   117 return
   118 
   119 
   120 
   121 
   122 
   123 
   124 
   125 
   126 
   127 
   128 
   129