archie/tcl7.6/tests/if.test

149 lines
4.1 KiB
Plaintext
Raw Normal View History

2024-05-27 16:13:40 +02:00
# Commands covered: if
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 1991-1993 The Regents of the University of California.
2024-05-27 16:40:40 +02:00
# Copyright (c) 1994 Sun Microsystems, Inc.
2024-05-27 16:13:40 +02:00
#
2024-05-27 16:40:40 +02:00
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
2024-05-27 16:13:40 +02:00
#
2024-05-27 16:40:40 +02:00
# SCCS: @(#) if.test 1.9 96/10/08 17:41:14
2024-05-27 16:13:40 +02:00
if {[string compare test [info procs test]] == 1} then {source defs}
test if-1.1 {taking proper branch} {
set a {}
if 0 {set a 1} else {set a 2}
set a
} 2
test if-1.2 {taking proper branch} {
set a {}
if 1 {set a 1} else {set a 2}
set a
} 1
test if-1.3 {taking proper branch} {
set a {}
if 1<2 {set a 1}
set a
} 1
test if-1.4 {taking proper branch} {
set a {}
if 1>2 {set a 1}
set a
} {}
test if-1.5 {taking proper branch} {
set a {}
if 0 {set a 1} else {}
set a
} {}
2024-05-27 16:40:40 +02:00
test if-1.6 {taking proper branch} {
2024-05-27 16:13:40 +02:00
set a {}
if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
set a
} {2}
2024-05-27 16:40:40 +02:00
test if-1.7 {taking proper branch} {
2024-05-27 16:13:40 +02:00
set a {}
if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
set a
} {3}
2024-05-27 16:40:40 +02:00
test if-1.8 {taking proper branch} {
2024-05-27 16:13:40 +02:00
set a {}
if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
set a
} {4}
test if-2.1 {optional then-else args} {
set a 44
if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
set a
} 2
test if-2.2 {optional then-else args} {
set a 44
if 1 then {set a 1} else {set a 2}
set a
} 1
test if-2.3 {optional then-else args} {
set a 44
if 0 {set a 1} else {set a 2}
set a
} 2
test if-2.4 {optional then-else args} {
set a 44
if 1 {set a 1} else {set a 2}
set a
} 1
test if-2.5 {optional then-else args} {
set a 44
if 0 then {set a 1} {set a 2}
set a
} 2
test if-2.6 {optional then-else args} {
set a 44
if 1 then {set a 1} {set a 2}
set a
} 1
test if-2.7 {optional then-else args} {
set a 44
if 0 then {set a 1} else {set a 2}
set a
} 2
test if-2.8 {optional then-else args} {
set a 44
if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
set a
} 4
test if-3.1 {return value} {
if 1 then {set a 22; concat abc}
} abc
test if-3.2 {return value} {
if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
} def
test if-3.3 {return value} {
if 0 then {set a 22; concat abc} else {concat def}
} def
test if-3.4 {return value} {
if 0 then {set a 22; concat abc}
} {}
test if-3.5 {return value} {
if 0 then {set a 22; concat abc} elseif 0 {concat def}
} {}
test if-4.1 {error conditions} {
list [catch {if} msg] $msg
} {1 {wrong # args: no expression after "if" argument}}
test if-4.2 {error conditions} {
list [catch {if {[error "error in condition"]}} msg] $msg
} {1 {error in condition}}
test if-4.3 {error conditions} {
list [catch {if 2} msg] $msg
} {1 {wrong # args: no script following "2" argument}}
test if-4.4 {error conditions} {
list [catch {if 2 then} msg] $msg
} {1 {wrong # args: no script following "then" argument}}
test if-4.5 {error conditions} {
list [catch {if 2 the} msg] $msg
2024-05-27 16:40:40 +02:00
} {1 {invalid command name "the"}}
2024-05-27 16:13:40 +02:00
test if-4.6 {error conditions} {
list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
} {1 {error in then clause}}
test if-4.7 {error conditions} {
list [catch {if 0 then foo elseif} msg] $msg
} {1 {wrong # args: no expression after "elseif" argument}}
test if-4.8 {error conditions} {
list [catch {if 0 then foo elsei} msg] $msg
2024-05-27 16:40:40 +02:00
} {1 {invalid command name "elsei"}}
2024-05-27 16:13:40 +02:00
test if-4.9 {error conditions} {
list [catch {if 0 then foo elseif 0 bar else} msg] $msg
} {1 {wrong # args: no script following "else" argument}}
test if-4.10 {error conditions} {
list [catch {if 0 then foo elseif 0 bar els} msg] $msg
2024-05-27 16:40:40 +02:00
} {1 {invalid command name "els"}}
2024-05-27 16:13:40 +02:00
test if-4.11 {error conditions} {
list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
} {1 {error in else clause}}