Debian Codegraph @

tests/get.test

raw
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 if {"::tcltest" ni [namespace children]} {
14 package require tcltest 2.5
15 namespace import -force ::tcltest::*
16 }
17
18 ::tcltest::loadTestedCommands
19 catch [list package require -exact Tcltest [info patchlevel]]
20
21 testConstraint testgetint [llength [info commands testgetint]]
22 testConstraint testdoubleobj [llength [info commands testdoubleobj]]
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 {
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 {
46 list [catch {testgetint 18446744073709551614} msg] $msg $errorCode
47 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
48 test get-1.9 {Tcl_GetInt procedure} testgetint {
49 list [catch {testgetint +18446744073709551614} msg] $msg $errorCode
50 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
51 test get-1.10 {Tcl_GetInt procedure} testgetint {
52 list [catch {testgetint -18446744073709551614} msg] $msg $errorCode
53 } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
54 test get-1.11 {Tcl_GetInt procedure} testgetint {
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 {
58 list [catch {testgetint 4294967294} msg] $msg
59 } {0 -2}
60 test get-1.13 {Tcl_GetInt procedure} testgetint {
61 list [catch {testgetint +4294967294} msg] $msg
62 } {0 -2}
63 test get-1.14 {Tcl_GetInt procedure} testgetint {
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 # Bug 7114ac6141
98 test get-3.3 {tcl_GetInt with iffy numbers} testgetint {
99 lmap x {0 " 0" "0 " " 0 " " 0xa " " 010 " " 0o10 " " 0b10 "} {
100 catch {testgetint 44 $x} x
101 set x
102 }
103 } {44 44 44 44 54 52 52 46}
104 test get-3.4 {Tcl_GetDouble with iffy numbers} testdoubleobj {
105 lmap x {0 0.0 " .0" ".0 " " 0e0 " "09" "- 0" "-0" "0o12" "0b10"} {
106 catch {testdoubleobj set 1 $x} x
107 set x
108 }
109 } {0.0 0.0 0.0 0.0 0.0 {expected floating-point number but got "09" (looks like invalid octal number)} {expected floating-point number but got "- 0"} 0.0 10.0 2.0}
110
111 # cleanup
112 ::tcltest::cleanupTests
113 return
114
115 # Local Variables:
116 # mode: tcl
117 # End: