os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/case.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# Commands covered:  case
sl@0
     2
#
sl@0
     3
# This file contains a collection of tests for one or more of the Tcl
sl@0
     4
# built-in commands.  Sourcing this file into Tcl runs the tests and
sl@0
     5
# generates output for errors.  No output means no errors were found.
sl@0
     6
#
sl@0
     7
# Copyright (c) 1991-1993 The Regents of the University of California.
sl@0
     8
# Copyright (c) 1994 Sun Microsystems, Inc.
sl@0
     9
# Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0
    10
#
sl@0
    11
# See the file "license.terms" for information on usage and redistribution
sl@0
    12
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    13
#
sl@0
    14
# RCS: @(#) $Id: case.test,v 1.5 2000/04/10 17:18:57 ericm Exp $
sl@0
    15
sl@0
    16
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    17
    package require tcltest
sl@0
    18
    namespace import -force ::tcltest::*
sl@0
    19
}
sl@0
    20
sl@0
    21
test case-1.1 {simple pattern} {
sl@0
    22
    case a in a {format 1} b {format 2} c {format 3} default {format 4}
sl@0
    23
} 1
sl@0
    24
test case-1.2 {simple pattern} {
sl@0
    25
    case b a {format 1} b {format 2} c {format 3} default {format 4}
sl@0
    26
} 2
sl@0
    27
test case-1.3 {simple pattern} {
sl@0
    28
    case x in a {format 1} b {format 2} c {format 3} default {format 4}
sl@0
    29
} 4
sl@0
    30
test case-1.4 {simple pattern} {
sl@0
    31
    case x a {format 1} b {format 2} c {format 3}
sl@0
    32
} {}
sl@0
    33
test case-1.5 {simple pattern matches many times} {
sl@0
    34
    case b a {format 1} b {format 2} b {format 3} b {format 4}
sl@0
    35
} 2
sl@0
    36
test case-1.6 {fancier pattern} {
sl@0
    37
    case cx a {format 1} *c {format 2} *x {format 3} default {format 4}
sl@0
    38
} 3
sl@0
    39
test case-1.7 {list of patterns} {
sl@0
    40
    case abc in {a b c} {format 1} {def abc ghi} {format 2}
sl@0
    41
} 2
sl@0
    42
sl@0
    43
test case-2.1 {error in executed command} {
sl@0
    44
    list [catch {case a in a {error "Just a test"} default {format 1}} msg] \
sl@0
    45
	    $msg $errorInfo
sl@0
    46
} {1 {Just a test} {Just a test
sl@0
    47
    while executing
sl@0
    48
"error "Just a test""
sl@0
    49
    ("a" arm line 1)
sl@0
    50
    invoked from within
sl@0
    51
"case a in a {error "Just a test"} default {format 1}"}}
sl@0
    52
test case-2.2 {error: not enough args} {
sl@0
    53
    list [catch {case} msg] $msg
sl@0
    54
} {1 {wrong # args: should be "case string ?in? patList body ... ?default body?"}}
sl@0
    55
test case-2.3 {error: pattern with no body} {
sl@0
    56
    list [catch {case a b} msg] $msg
sl@0
    57
} {1 {extra case pattern with no body}}
sl@0
    58
test case-2.4 {error: pattern with no body} {
sl@0
    59
    list [catch {case a in b {format 1} c} msg] $msg
sl@0
    60
} {1 {extra case pattern with no body}}
sl@0
    61
test case-2.5 {error in default command} {
sl@0
    62
    list [catch {case foo in a {error case1} default {error case2} \
sl@0
    63
	    b {error case 3}} msg] $msg $errorInfo
sl@0
    64
} {1 case2 {case2
sl@0
    65
    while executing
sl@0
    66
"error case2"
sl@0
    67
    ("default" arm line 1)
sl@0
    68
    invoked from within
sl@0
    69
"case foo in a {error case1} default {error case2}  b {error case 3}"}}
sl@0
    70
sl@0
    71
test case-3.1 {single-argument form for pattern/command pairs} {
sl@0
    72
    case b in {
sl@0
    73
	a {format 1}
sl@0
    74
	b {format 2}
sl@0
    75
	default {format 6}
sl@0
    76
    }
sl@0
    77
} {2}
sl@0
    78
test case-3.2 {single-argument form for pattern/command pairs} {
sl@0
    79
    case b {
sl@0
    80
	a {format 1}
sl@0
    81
	b {format 2}
sl@0
    82
	default {format 6}
sl@0
    83
    }
sl@0
    84
} {2}
sl@0
    85
test case-3.3 {single-argument form for pattern/command pairs} {
sl@0
    86
    list [catch {case z in {a 2 b}} msg] $msg
sl@0
    87
} {1 {extra case pattern with no body}}
sl@0
    88
sl@0
    89
# cleanup
sl@0
    90
::tcltest::cleanupTests
sl@0
    91
return
sl@0
    92
sl@0
    93
sl@0
    94
sl@0
    95
sl@0
    96
sl@0
    97
sl@0
    98
sl@0
    99
sl@0
   100
sl@0
   101
sl@0
   102
sl@0
   103