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