Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/if-old.test @ 31

Last change on this file since 31 was 25, checked in by landauf, 17 years ago

added tcl to libs

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