OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [case.test] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Commands covered:  case
2
#
3
# This file contains a collection of tests for one or more of the Tcl
4
# built-in commands.  Sourcing this file into Tcl runs the tests and
5
# generates output for errors.  No output means no errors were found.
6
#
7
# Copyright (c) 1991-1993 The Regents of the University of California.
8
# Copyright (c) 1994 Sun Microsystems, Inc.
9
#
10
# See the file "license.terms" for information on usage and redistribution
11
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
#
13
# RCS: @(#) $Id: case.test,v 1.1.1.1 2002-01-16 10:25:35 markom Exp $
14
 
15
if {[string compare test [info procs test]] == 1} then {source defs}
16
 
17
test case-1.1 {simple pattern} {
18
    case a in a {format 1} b {format 2} c {format 3} default {format 4}
19
} 1
20
test case-1.2 {simple pattern} {
21
    case b a {format 1} b {format 2} c {format 3} default {format 4}
22
} 2
23
test case-1.3 {simple pattern} {
24
    case x in a {format 1} b {format 2} c {format 3} default {format 4}
25
} 4
26
test case-1.4 {simple pattern} {
27
    case x a {format 1} b {format 2} c {format 3}
28
} {}
29
test case-1.5 {simple pattern matches many times} {
30
    case b a {format 1} b {format 2} b {format 3} b {format 4}
31
} 2
32
test case-1.6 {fancier pattern} {
33
    case cx a {format 1} *c {format 2} *x {format 3} default {format 4}
34
} 3
35
test case-1.7 {list of patterns} {
36
    case abc in {a b c} {format 1} {def abc ghi} {format 2}
37
} 2
38
 
39
test case-2.1 {error in executed command} {
40
    list [catch {case a in a {error "Just a test"} default {format 1}} msg] \
41
            $msg $errorInfo
42
} {1 {Just a test} {Just a test
43
    while executing
44
"error "Just a test""
45
    ("a" arm line 1)
46
    invoked from within
47
"case a in a {error "Just a test"} default {format 1}"}}
48
test case-2.2 {error: not enough args} {
49
    list [catch {case} msg] $msg
50
} {1 {wrong # args: should be "case string ?in? patList body ... ?default body?"}}
51
test case-2.3 {error: pattern with no body} {
52
    list [catch {case a b} msg] $msg
53
} {1 {extra case pattern with no body}}
54
test case-2.4 {error: pattern with no body} {
55
    list [catch {case a in b {format 1} c} msg] $msg
56
} {1 {extra case pattern with no body}}
57
test case-2.5 {error in default command} {
58
    list [catch {case foo in a {error case1} default {error case2} \
59
            b {error case 3}} msg] $msg $errorInfo
60
} {1 case2 {case2
61
    while executing
62
"error case2"
63
    ("default" arm line 1)
64
    invoked from within
65
"case foo in a {error case1} default {error case2}  b {error case 3}"}}
66
 
67
test case-3.1 {single-argument form for pattern/command pairs} {
68
    case b in {
69
        a {format 1}
70
        b {format 2}
71
        default {format 6}
72
    }
73
} {2}
74
test case-3.2 {single-argument form for pattern/command pairs} {
75
    case b {
76
        a {format 1}
77
        b {format 2}
78
        default {format 6}
79
    }
80
} {2}
81
test case-3.3 {single-argument form for pattern/command pairs} {
82
    list [catch {case z in {a 2 b}} msg] $msg
83
} {1 {extra case pattern with no body}}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.