home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / if-old.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  4.6 KB  |  157 lines  |  [TEXT/ALFA]

  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. #
  12. # See the file "license.terms" for information on usage and redistribution
  13. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14. #
  15. # SCCS: @(#) if-old.test 1.10 96/10/22 11:33:06
  16.  
  17. if {[string compare test [info procs test]] == 1} then {source defs}
  18.  
  19. test if-old-1.1 {taking proper branch} {
  20.     set a {}
  21.     if 0 {set a 1} else {set a 2}
  22.     set a
  23. } 2
  24. test if-old-1.2 {taking proper branch} {
  25.     set a {}
  26.     if 1 {set a 1} else {set a 2}
  27.     set a
  28. } 1
  29. test if-old-1.3 {taking proper branch} {
  30.     set a {}
  31.     if 1<2 {set a 1}
  32.     set a
  33. } 1
  34. test if-old-1.4 {taking proper branch} {
  35.     set a {}
  36.     if 1>2 {set a 1}
  37.     set a
  38. } {}
  39. test if-old-1.5 {taking proper branch} {
  40.     set a {}
  41.     if 0 {set a 1} else {}
  42.     set a
  43. } {}
  44. test if-old-1.5 {taking proper branch} {
  45.     set a {}
  46.     if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
  47.     set a
  48. } {2}
  49. test if-old-1.6 {taking proper branch} {
  50.     set a {}
  51.     if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
  52.     set a
  53. } {3}
  54. test if-old-1.7 {taking proper branch} {
  55.     set a {}
  56.     if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
  57.     set a
  58. } {4}
  59. test if-old-1.8 {taking proper branch, multiline test expr} {
  60.     set a {}
  61.     if {($tcl_platform(platform) != "foobar1") && \
  62.     ($tcl_platform(platform) != "foobar2")} {set a 3} else {set a 4}
  63.     set a
  64. } {3}
  65.  
  66.  
  67. test if-old-2.1 {optional then-else args} {
  68.     set a 44
  69.     if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
  70.     set a
  71. } 2
  72. test if-old-2.2 {optional then-else args} {
  73.     set a 44
  74.     if 1 then {set a 1} else {set a 2}
  75.     set a
  76. } 1
  77. test if-old-2.3 {optional then-else args} {
  78.     set a 44
  79.     if 0 {set a 1} else {set a 2}
  80.     set a
  81. } 2
  82. test if-old-2.4 {optional then-else args} {
  83.     set a 44
  84.     if 1 {set a 1} else {set a 2}
  85.     set a
  86. } 1
  87. test if-old-2.5 {optional then-else args} {
  88.     set a 44
  89.     if 0 then {set a 1} {set a 2}
  90.     set a
  91. } 2
  92. test if-old-2.6 {optional then-else args} {
  93.     set a 44
  94.     if 1 then {set a 1} {set a 2}
  95.     set a
  96. } 1
  97. test if-old-2.7 {optional then-else args} {
  98.     set a 44
  99.     if 0 then {set a 1} else {set a 2}
  100.     set a
  101. } 2
  102. test if-old-2.8 {optional then-else args} {
  103.     set a 44
  104.     if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
  105.     set a
  106. } 4
  107.  
  108. test if-old-3.1 {return value} {
  109.     if 1 then {set a 22; concat abc}
  110. } abc
  111. test if-old-3.2 {return value} {
  112.     if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
  113. } def
  114. test if-old-3.3 {return value} {
  115.     if 0 then {set a 22; concat abc} else {concat def}
  116. } def
  117. test if-old-3.4 {return value} {
  118.     if 0 then {set a 22; concat abc}
  119. } {}
  120. test if-old-3.5 {return value} {
  121.     if 0 then {set a 22; concat abc} elseif 0 {concat def}
  122. } {}
  123.  
  124. test if-old-4.1 {error conditions} {
  125.     list [catch {if} msg] $msg
  126. } {1 {wrong # args: no expression after "if" argument}}
  127. test if-old-4.2 {error conditions} {
  128.     list [catch {if {[error "error in condition"]} foo} msg] $msg
  129. } {1 {error in condition}}
  130. test if-old-4.3 {error conditions} {
  131.     list [catch {if 2} msg] $msg
  132. } {1 {wrong # args: no script following "2" argument}}
  133. test if-old-4.4 {error conditions} {
  134.     list [catch {if 2 then} msg] $msg
  135. } {1 {wrong # args: no script following "then" argument}}
  136. test if-old-4.5 {error conditions} {
  137.     list [catch {if 2 the} msg] $msg
  138. } {1 {invalid command name "the"}}
  139. test if-old-4.6 {error conditions} {
  140.     list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
  141. } {1 {error in then clause}}
  142. test if-old-4.7 {error conditions} {
  143.     list [catch {if 0 then foo elseif} msg] $msg
  144. } {1 {wrong # args: no expression after "elseif" argument}}
  145. test if-old-4.8 {error conditions} {
  146.     list [catch {if 0 then foo elsei} msg] $msg
  147. } {1 {invalid command name "elsei"}}
  148. test if-old-4.9 {error conditions} {
  149.     list [catch {if 0 then foo elseif 0 bar else} msg] $msg
  150. } {1 {wrong # args: no script following "else" argument}}
  151. test if-old-4.10 {error conditions} {
  152.     list [catch {if 0 then foo elseif 0 bar els} msg] $msg
  153. } {1 {invalid command name "els"}}
  154. test if-old-4.11 {error conditions} {
  155.     list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
  156. } {1 {error in else clause}}
  157.