tagged release 0.7.1
[parrot.git] / languages / tcl / t / cmd_if.t
blobd66e15ababdafee1bf5aa3a97b73b506d170f989
1 #!perl
3 # Copyright (C) 2004-2008, The Perl Foundation.
4 # $Id$
6 # the following lines re-execute this as a tcl script
7 # the \ at the end of these lines makes them a comment in tcl \
8 use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
9 use Tcl::Test; #\
10 __DATA__
12 source lib/test_more.tcl
13 plan 18
15 eval_is {
16  set a ""
17  if { 1 == 1 } {
18    set a true
19  } {
20    set a false
21  }
22  set a
23 } true {simple if}
25 eval_is {
26  set a ""
27  if { 1 == 1 } {
28    set a true
29  } else {
30    set a false
31  }
32  set a
33 } true {if/else}
35 eval_is {
36  set a ""
37  if { 1 != 1 } then {
38    set a true
39  } {
40    set a false
41  }
42  set a
43 } false {simple if with then}
45 eval_is {
46  set a ""
47  if { 1 == 1 } then {
48    set a true
49  } else {
50    set a false
51  }
52  set a
53 } true {simple if with then, else}
55 eval_is {
56  set a ""
57  if { 1 != 1 } then {
58    set a true
59  } elseif { 2==2 } {
60    set a blue
61  }
62  set a
63 } blue {if with then, elseif}
65 eval_is {
66   set a ""
67   if 0 then {
68     set a if
69   } elseif 1 then {
70     set a elseif
71   }
72   set a
73 } elseif {if with then, elseif with then}
75 eval_is {
76  set a ""
77  if { 1 != 1 } then {
78    set a true
79  } elseif { 2 != 2 } {
80    set a blue
81  } else {
82    set a whee
83  }
84  set a
85 } whee {if with then, elseif, else}
87 eval_is {
88  set a ""
89  if { 1 != 1 } {
90    set a 1
91  } elseif { 2 != 2 } {
92    set a 2
93  } {
94    set a 3
95  }
96  set a
97 } 3 {if with elseif, implicit else}
99 eval_is {
100  set a ""
101  if { 1 != 1 } {
102    set a no
104  set a
105 } {} {if with implicit then, false}
107 eval_is {
108  set a ""
109  if { 1 == 1 } {
110    set a true
112  set a
113 } true {if with implicit then, true}
115 eval_is {
116   set a ""
117   if 0 then {
118     set a then
119   } elseif 0 {
120     set a elseif
121   }
122   set a
123 } {} {nothing is true}
125 eval_is {
126   if {"foo"} then {error moo}
127 } {expected boolean value but got "foo"} \
128   {expected boolean}
130 eval_is {
131   set a ""
132   if 2 then {set a true}
133   set a
134 } true {numeric non-0 is true}
137 eval_is {
138   namespace eval lib {
139     set val {}
140     proc a {} {error ok}
141     if {[a]} {}
142   }
143 } ok {namespace resolution in cond}
145 eval_is {
146   namespace eval lib {
147     set val {}
148     proc a {} {error ok}
149     if 1 a
150   }
151 } ok {namespace resolution in body}
153 eval_is {if {}} \
154   {empty expression
155 in expression ""} \
156   {expression errors before [if] errors}
158 eval_is {if 0 then} \
159   {wrong # args: no script following "then" argument} \
160   {no script following then}
162 eval_is {if 0} \
163   {wrong # args: no script following "0" argument} \
164   {no script following conditional}