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.12 2005/08/08 14:08:05 dgp Exp $ |
---|
14 | |
---|
15 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
16 | package require tcltest |
---|
17 | namespace import -force ::tcltest::* |
---|
18 | } |
---|
19 | |
---|
20 | testConstraint testgetint [llength [info commands testgetint]] |
---|
21 | testConstraint longIs32bit [expr {int(0x80000000) < 0}] |
---|
22 | testConstraint longIs64bit [expr {int(0x8000000000000000) < 0}] |
---|
23 | |
---|
24 | test get-1.1 {Tcl_GetInt procedure} testgetint { |
---|
25 | testgetint 44 { 22} |
---|
26 | } {66} |
---|
27 | test get-1.2 {Tcl_GetInt procedure} testgetint { |
---|
28 | testgetint 44 -3 |
---|
29 | } {41} |
---|
30 | test get-1.3 {Tcl_GetInt procedure} testgetint { |
---|
31 | testgetint 44 +8 |
---|
32 | } {52} |
---|
33 | test get-1.4 {Tcl_GetInt procedure} testgetint { |
---|
34 | list [catch {testgetint 44 foo} msg] $msg |
---|
35 | } {1 {expected integer but got "foo"}} |
---|
36 | test get-1.5 {Tcl_GetInt procedure} testgetint { |
---|
37 | list [catch {testgetint 44 {16 }} msg] $msg |
---|
38 | } {0 60} |
---|
39 | test get-1.6 {Tcl_GetInt procedure} testgetint { |
---|
40 | list [catch {testgetint 44 {16 x}} msg] $msg |
---|
41 | } {1 {expected integer but got "16 x"}} |
---|
42 | test get-1.7 {Tcl_GetInt procedure} {testgetint longIs64bit} { |
---|
43 | list [catch {testgetint 44 18446744073709551616} msg] $msg $errorCode |
---|
44 | } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} |
---|
45 | test get-1.8 {Tcl_GetInt procedure} {testgetint longIs64bit} { |
---|
46 | list [catch {testgetint 18446744073709551614} msg] $msg |
---|
47 | } {0 -2} |
---|
48 | test get-1.9 {Tcl_GetInt procedure} {testgetint longIs64bit} { |
---|
49 | list [catch {testgetint +18446744073709551614} msg] $msg |
---|
50 | } {0 -2} |
---|
51 | test get-1.10 {Tcl_GetInt procedure} {testgetint longIs64bit} { |
---|
52 | list [catch {testgetint -18446744073709551614} msg] $msg |
---|
53 | } {0 2} |
---|
54 | test get-1.11 {Tcl_GetInt procedure} {testgetint longIs32bit} { |
---|
55 | list [catch {testgetint 44 4294967296} msg] $msg $errorCode |
---|
56 | } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} |
---|
57 | test get-1.12 {Tcl_GetInt procedure} {testgetint longIs32bit} { |
---|
58 | list [catch {testgetint 4294967294} msg] $msg |
---|
59 | } {0 -2} |
---|
60 | test get-1.13 {Tcl_GetInt procedure} {testgetint longIs32bit} { |
---|
61 | list [catch {testgetint +4294967294} msg] $msg |
---|
62 | } {0 -2} |
---|
63 | test get-1.14 {Tcl_GetInt procedure} {testgetint longIs32bit} { |
---|
64 | list [catch {testgetint -4294967294} msg] $msg |
---|
65 | } {0 2} |
---|
66 | |
---|
67 | test get-2.1 {Tcl_GetInt procedure} { |
---|
68 | format %g 1.23 |
---|
69 | } {1.23} |
---|
70 | test get-2.2 {Tcl_GetInt procedure} { |
---|
71 | format %g { 1.23 } |
---|
72 | } {1.23} |
---|
73 | test get-2.3 {Tcl_GetInt procedure} { |
---|
74 | list [catch {format %g clip} msg] $msg |
---|
75 | } {1 {expected floating-point number but got "clip"}} |
---|
76 | test get-2.4 {Tcl_GetInt procedure} { |
---|
77 | format %g .000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 |
---|
78 | } 0 |
---|
79 | |
---|
80 | test get-3.1 {Tcl_GetInt(FromObj), bad numbers} { |
---|
81 | # SF bug #634856 |
---|
82 | set result "" |
---|
83 | set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1" "+12345678987654321" "++12345678987654321"] |
---|
84 | foreach num $numbers { |
---|
85 | lappend result [catch {format %ld $num} msg] $msg |
---|
86 | } |
---|
87 | set result |
---|
88 | } {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"}} |
---|
89 | test get-3.2 {Tcl_GetDouble(FromObj), bad numbers} { |
---|
90 | set result "" |
---|
91 | set numbers [list 1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0"] |
---|
92 | foreach num $numbers { |
---|
93 | lappend result [catch {format %g $num} msg] $msg |
---|
94 | } |
---|
95 | set result |
---|
96 | } {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"}} |
---|
97 | |
---|
98 | # cleanup |
---|
99 | ::tcltest::cleanupTests |
---|
100 | return |
---|