os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/if-old.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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.5.24.1 2003/03/27 13:11:12 dkf Exp $
    17 
    18 if {[lsearch [namespace children] ::tcltest] == -1} {
    19     package require tcltest
    20     namespace import -force ::tcltest::*
    21 }
    22 
    23 test 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
    28 test 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
    33 test if-old-1.3 {taking proper branch} {
    34     set a {}
    35     if 1<2 {set a 1}
    36     set a
    37 } 1
    38 test if-old-1.4 {taking proper branch} {
    39     set a {}
    40     if 1>2 {set a 1}
    41     set a
    42 } {}
    43 test if-old-1.5 {taking proper branch} {
    44     set a {}
    45     if 0 {set a 1} else {}
    46     set a
    47 } {}
    48 test 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}
    53 test 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}
    58 test 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}
    63 test 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 
    71 test 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
    76 test 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
    81 test 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
    86 test 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
    91 test 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
    96 test 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
   101 test 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
   106 test 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 
   112 test if-old-3.1 {return value} {
   113     if 1 then {set a 22; concat abc}
   114 } abc
   115 test if-old-3.2 {return value} {
   116     if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
   117 } def
   118 test if-old-3.3 {return value} {
   119     if 0 then {set a 22; concat abc} else {concat def}
   120 } def
   121 test if-old-3.4 {return value} {
   122     if 0 then {set a 22; concat abc}
   123 } {}
   124 test if-old-3.5 {return value} {
   125     if 0 then {set a 22; concat abc} elseif 0 {concat def}
   126 } {}
   127 
   128 test if-old-4.1 {error conditions} {
   129     list [catch {if} msg] $msg
   130 } {1 {wrong # args: no expression after "if" argument}}
   131 test if-old-4.2 {error conditions} {
   132     list [catch {if {[error "error in condition"]} foo} msg] $msg
   133 } {1 {error in condition}}
   134 test if-old-4.3 {error conditions} {
   135     list [catch {if 2} msg] $msg
   136 } {1 {wrong # args: no script following "2" argument}}
   137 test if-old-4.4 {error conditions} {
   138     list [catch {if 2 then} msg] $msg
   139 } {1 {wrong # args: no script following "then" argument}}
   140 test if-old-4.5 {error conditions} {
   141     list [catch {if 2 the} msg] $msg
   142 } {1 {invalid command name "the"}}
   143 test 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}}
   146 test 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}}
   149 test if-old-4.8 {error conditions} {
   150     list [catch {if 0 then foo elsei} msg] $msg
   151 } {1 {invalid command name "elsei"}}
   152 test 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}}
   155 test 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"}}
   158 test 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
   164 return