sl@0
|
1 |
# Commands covered: if
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains the original set of tests for Tcl's if command.
|
sl@0
|
4 |
# Since the if command is now compiled, a new set of tests covering
|
sl@0
|
5 |
# the new implementation is in the file "if.test". Sourcing this file
|
sl@0
|
6 |
# into Tcl runs the tests and generates output for errors.
|
sl@0
|
7 |
# No output means no errors were found.
|
sl@0
|
8 |
#
|
sl@0
|
9 |
# Copyright (c) 1991-1993 The Regents of the University of California.
|
sl@0
|
10 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
|
sl@0
|
11 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
14 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# RCS: @(#) $Id: if-old.test,v 1.5.24.1 2003/03/27 13:11:12 dkf Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
19 |
package require tcltest
|
sl@0
|
20 |
namespace import -force ::tcltest::*
|
sl@0
|
21 |
}
|
sl@0
|
22 |
|
sl@0
|
23 |
test if-old-1.1 {taking proper branch} {
|
sl@0
|
24 |
set a {}
|
sl@0
|
25 |
if 0 {set a 1} else {set a 2}
|
sl@0
|
26 |
set a
|
sl@0
|
27 |
} 2
|
sl@0
|
28 |
test if-old-1.2 {taking proper branch} {
|
sl@0
|
29 |
set a {}
|
sl@0
|
30 |
if 1 {set a 1} else {set a 2}
|
sl@0
|
31 |
set a
|
sl@0
|
32 |
} 1
|
sl@0
|
33 |
test if-old-1.3 {taking proper branch} {
|
sl@0
|
34 |
set a {}
|
sl@0
|
35 |
if 1<2 {set a 1}
|
sl@0
|
36 |
set a
|
sl@0
|
37 |
} 1
|
sl@0
|
38 |
test if-old-1.4 {taking proper branch} {
|
sl@0
|
39 |
set a {}
|
sl@0
|
40 |
if 1>2 {set a 1}
|
sl@0
|
41 |
set a
|
sl@0
|
42 |
} {}
|
sl@0
|
43 |
test if-old-1.5 {taking proper branch} {
|
sl@0
|
44 |
set a {}
|
sl@0
|
45 |
if 0 {set a 1} else {}
|
sl@0
|
46 |
set a
|
sl@0
|
47 |
} {}
|
sl@0
|
48 |
test if-old-1.6 {taking proper branch} {
|
sl@0
|
49 |
set a {}
|
sl@0
|
50 |
if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
|
sl@0
|
51 |
set a
|
sl@0
|
52 |
} {2}
|
sl@0
|
53 |
test if-old-1.7 {taking proper branch} {
|
sl@0
|
54 |
set a {}
|
sl@0
|
55 |
if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
|
sl@0
|
56 |
set a
|
sl@0
|
57 |
} {3}
|
sl@0
|
58 |
test if-old-1.8 {taking proper branch} {
|
sl@0
|
59 |
set a {}
|
sl@0
|
60 |
if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
|
sl@0
|
61 |
set a
|
sl@0
|
62 |
} {4}
|
sl@0
|
63 |
test if-old-1.9 {taking proper branch, multiline test expr} {
|
sl@0
|
64 |
set a {}
|
sl@0
|
65 |
if {($tcl_platform(platform) != "foobar1") && \
|
sl@0
|
66 |
($tcl_platform(platform) != "foobar2")} {set a 3} else {set a 4}
|
sl@0
|
67 |
set a
|
sl@0
|
68 |
} {3}
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
test if-old-2.1 {optional then-else args} {
|
sl@0
|
72 |
set a 44
|
sl@0
|
73 |
if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
|
sl@0
|
74 |
set a
|
sl@0
|
75 |
} 2
|
sl@0
|
76 |
test if-old-2.2 {optional then-else args} {
|
sl@0
|
77 |
set a 44
|
sl@0
|
78 |
if 1 then {set a 1} else {set a 2}
|
sl@0
|
79 |
set a
|
sl@0
|
80 |
} 1
|
sl@0
|
81 |
test if-old-2.3 {optional then-else args} {
|
sl@0
|
82 |
set a 44
|
sl@0
|
83 |
if 0 {set a 1} else {set a 2}
|
sl@0
|
84 |
set a
|
sl@0
|
85 |
} 2
|
sl@0
|
86 |
test if-old-2.4 {optional then-else args} {
|
sl@0
|
87 |
set a 44
|
sl@0
|
88 |
if 1 {set a 1} else {set a 2}
|
sl@0
|
89 |
set a
|
sl@0
|
90 |
} 1
|
sl@0
|
91 |
test if-old-2.5 {optional then-else args} {
|
sl@0
|
92 |
set a 44
|
sl@0
|
93 |
if 0 then {set a 1} {set a 2}
|
sl@0
|
94 |
set a
|
sl@0
|
95 |
} 2
|
sl@0
|
96 |
test if-old-2.6 {optional then-else args} {
|
sl@0
|
97 |
set a 44
|
sl@0
|
98 |
if 1 then {set a 1} {set a 2}
|
sl@0
|
99 |
set a
|
sl@0
|
100 |
} 1
|
sl@0
|
101 |
test if-old-2.7 {optional then-else args} {
|
sl@0
|
102 |
set a 44
|
sl@0
|
103 |
if 0 then {set a 1} else {set a 2}
|
sl@0
|
104 |
set a
|
sl@0
|
105 |
} 2
|
sl@0
|
106 |
test if-old-2.8 {optional then-else args} {
|
sl@0
|
107 |
set a 44
|
sl@0
|
108 |
if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
|
sl@0
|
109 |
set a
|
sl@0
|
110 |
} 4
|
sl@0
|
111 |
|
sl@0
|
112 |
test if-old-3.1 {return value} {
|
sl@0
|
113 |
if 1 then {set a 22; concat abc}
|
sl@0
|
114 |
} abc
|
sl@0
|
115 |
test if-old-3.2 {return value} {
|
sl@0
|
116 |
if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
|
sl@0
|
117 |
} def
|
sl@0
|
118 |
test if-old-3.3 {return value} {
|
sl@0
|
119 |
if 0 then {set a 22; concat abc} else {concat def}
|
sl@0
|
120 |
} def
|
sl@0
|
121 |
test if-old-3.4 {return value} {
|
sl@0
|
122 |
if 0 then {set a 22; concat abc}
|
sl@0
|
123 |
} {}
|
sl@0
|
124 |
test if-old-3.5 {return value} {
|
sl@0
|
125 |
if 0 then {set a 22; concat abc} elseif 0 {concat def}
|
sl@0
|
126 |
} {}
|
sl@0
|
127 |
|
sl@0
|
128 |
test if-old-4.1 {error conditions} {
|
sl@0
|
129 |
list [catch {if} msg] $msg
|
sl@0
|
130 |
} {1 {wrong # args: no expression after "if" argument}}
|
sl@0
|
131 |
test if-old-4.2 {error conditions} {
|
sl@0
|
132 |
list [catch {if {[error "error in condition"]} foo} msg] $msg
|
sl@0
|
133 |
} {1 {error in condition}}
|
sl@0
|
134 |
test if-old-4.3 {error conditions} {
|
sl@0
|
135 |
list [catch {if 2} msg] $msg
|
sl@0
|
136 |
} {1 {wrong # args: no script following "2" argument}}
|
sl@0
|
137 |
test if-old-4.4 {error conditions} {
|
sl@0
|
138 |
list [catch {if 2 then} msg] $msg
|
sl@0
|
139 |
} {1 {wrong # args: no script following "then" argument}}
|
sl@0
|
140 |
test if-old-4.5 {error conditions} {
|
sl@0
|
141 |
list [catch {if 2 the} msg] $msg
|
sl@0
|
142 |
} {1 {invalid command name "the"}}
|
sl@0
|
143 |
test if-old-4.6 {error conditions} {
|
sl@0
|
144 |
list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
|
sl@0
|
145 |
} {1 {error in then clause}}
|
sl@0
|
146 |
test if-old-4.7 {error conditions} {
|
sl@0
|
147 |
list [catch {if 0 then foo elseif} msg] $msg
|
sl@0
|
148 |
} {1 {wrong # args: no expression after "elseif" argument}}
|
sl@0
|
149 |
test if-old-4.8 {error conditions} {
|
sl@0
|
150 |
list [catch {if 0 then foo elsei} msg] $msg
|
sl@0
|
151 |
} {1 {invalid command name "elsei"}}
|
sl@0
|
152 |
test if-old-4.9 {error conditions} {
|
sl@0
|
153 |
list [catch {if 0 then foo elseif 0 bar else} msg] $msg
|
sl@0
|
154 |
} {1 {wrong # args: no script following "else" argument}}
|
sl@0
|
155 |
test if-old-4.10 {error conditions} {
|
sl@0
|
156 |
list [catch {if 0 then foo elseif 0 bar els} msg] $msg
|
sl@0
|
157 |
} {1 {invalid command name "els"}}
|
sl@0
|
158 |
test if-old-4.11 {error conditions} {
|
sl@0
|
159 |
list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
|
sl@0
|
160 |
} {1 {error in else clause}}
|
sl@0
|
161 |
|
sl@0
|
162 |
# cleanup
|
sl@0
|
163 |
::tcltest::cleanupTests
|
sl@0
|
164 |
return
|