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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [tests/] [methods.test] - Diff between revs 578 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 1765
#
#
# Tests for argument lists and method execution
# Tests for argument lists and method execution
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#   AUTHOR:  Michael J. McLennan
#   AUTHOR:  Michael J. McLennan
#            Bell Labs Innovations for Lucent Technologies
#            Bell Labs Innovations for Lucent Technologies
#            mmclennan@lucent.com
#            mmclennan@lucent.com
#            http://www.tcltk.com/itcl
#            http://www.tcltk.com/itcl
#
#
#      RCS:  $Id: methods.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
#      RCS:  $Id: methods.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#            Copyright (c) 1993-1998  Lucent Technologies, Inc.
#            Copyright (c) 1993-1998  Lucent Technologies, Inc.
# ======================================================================
# ======================================================================
# See the file "license.terms" for information on usage and
# See the file "license.terms" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
if {[string compare test [info procs test]] == 1} then {source defs}
if {[string compare test [info procs test]] == 1} then {source defs}
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#  Methods with various argument lists
#  Methods with various argument lists
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
test methods-1.1 {define a class with lots of methods and arg lists} {
test methods-1.1 {define a class with lots of methods and arg lists} {
    itcl::class test_args {
    itcl::class test_args {
        method none {} {
        method none {} {
            return "none"
            return "none"
        }
        }
        method two {x y} {
        method two {x y} {
            return "two: $x $y"
            return "two: $x $y"
        }
        }
        method defvals {x {y def1} {z def2}} {
        method defvals {x {y def1} {z def2}} {
            return "defvals: $x $y $z"
            return "defvals: $x $y $z"
        }
        }
        method varargs {x {y def1} args} {
        method varargs {x {y def1} args} {
            return "varargs: $x $y ($args)"
            return "varargs: $x $y ($args)"
        }
        }
        method nomagic {args x} {
        method nomagic {args x} {
            return "nomagic: $args $x"
            return "nomagic: $args $x"
        }
        }
        method clash {x bang boom} {
        method clash {x bang boom} {
            return "clash: $x $bang $boom"
            return "clash: $x $bang $boom"
        }
        }
        proc crash {x bang boom} {
        proc crash {x bang boom} {
            return "crash: $x $bang $boom"
            return "crash: $x $bang $boom"
        }
        }
        variable bang "ok"
        variable bang "ok"
        common boom "no-problem"
        common boom "no-problem"
    }
    }
} ""
} ""
test methods-1.2 {create an object to execute tests} {
test methods-1.2 {create an object to execute tests} {
    test_args ta
    test_args ta
} {ta}
} {ta}
test methods-1.3 {argument checking: not enough args} {
test methods-1.3 {argument checking: not enough args} {
    list [catch {ta two 1} msg] $msg
    list [catch {ta two 1} msg] $msg
} {1 {wrong # args: should be "ta two x y"}}
} {1 {wrong # args: should be "ta two x y"}}
test methods-1.4a {argument checking: too many args} {
test methods-1.4a {argument checking: too many args} {
    list [catch {ta two 1 2 3} msg] $msg
    list [catch {ta two 1 2 3} msg] $msg
} {1 {wrong # args: should be "ta two x y"}}
} {1 {wrong # args: should be "ta two x y"}}
test methods-1.4b {argument checking: too many args} {
test methods-1.4b {argument checking: too many args} {
    list [catch {ta none 1 2 3} msg] $msg
    list [catch {ta none 1 2 3} msg] $msg
} {1 {wrong # args: should be "ta none"}}
} {1 {wrong # args: should be "ta none"}}
test methods-1.5a {argument checking: just right} {
test methods-1.5a {argument checking: just right} {
    list [catch {ta two 1 2} msg] $msg
    list [catch {ta two 1 2} msg] $msg
} {0 {two: 1 2}}
} {0 {two: 1 2}}
test methods-1.5b {argument checking: just right} {
test methods-1.5b {argument checking: just right} {
    list [catch {ta none} msg] $msg
    list [catch {ta none} msg] $msg
} {0 none}
} {0 none}
test methods-1.6a {default arguments: not enough args} {
test methods-1.6a {default arguments: not enough args} {
    list [catch {ta defvals} msg] $msg
    list [catch {ta defvals} msg] $msg
} {1 {wrong # args: should be "ta defvals x ?y? ?z?"}}
} {1 {wrong # args: should be "ta defvals x ?y? ?z?"}}
test methods-1.6b {default arguments: missing arguments supplied} {
test methods-1.6b {default arguments: missing arguments supplied} {
    list [catch {ta defvals 1} msg] $msg
    list [catch {ta defvals 1} msg] $msg
} {0 {defvals: 1 def1 def2}}
} {0 {defvals: 1 def1 def2}}
test methods-1.6c {default arguments: missing arguments supplied} {
test methods-1.6c {default arguments: missing arguments supplied} {
    list [catch {ta defvals 1 2} msg] $msg
    list [catch {ta defvals 1 2} msg] $msg
} {0 {defvals: 1 2 def2}}
} {0 {defvals: 1 2 def2}}
test methods-1.6d {default arguments: all arguments assigned} {
test methods-1.6d {default arguments: all arguments assigned} {
    list [catch {ta defvals 1 2 3} msg] $msg
    list [catch {ta defvals 1 2 3} msg] $msg
} {0 {defvals: 1 2 3}}
} {0 {defvals: 1 2 3}}
test methods-1.6e {default arguments: too many args} {
test methods-1.6e {default arguments: too many args} {
    list [catch {ta defvals 1 2 3 4} msg] $msg
    list [catch {ta defvals 1 2 3 4} msg] $msg
} {1 {wrong # args: should be "ta defvals x ?y? ?z?"}}
} {1 {wrong # args: should be "ta defvals x ?y? ?z?"}}
test methods-1.7a {variable arguments: not enough args} {
test methods-1.7a {variable arguments: not enough args} {
    list [catch {ta varargs} msg] $msg
    list [catch {ta varargs} msg] $msg
} {1 {wrong # args: should be "ta varargs x ?y? ?arg arg ...?"}}
} {1 {wrong # args: should be "ta varargs x ?y? ?arg arg ...?"}}
test methods-1.7b {variable arguments: empty} {
test methods-1.7b {variable arguments: empty} {
    list [catch {ta varargs 1 2} msg] $msg
    list [catch {ta varargs 1 2} msg] $msg
} {0 {varargs: 1 2 ()}}
} {0 {varargs: 1 2 ()}}
test methods-1.7c {variable arguments: one} {
test methods-1.7c {variable arguments: one} {
    list [catch {ta varargs 1 2 one} msg] $msg
    list [catch {ta varargs 1 2 one} msg] $msg
} {0 {varargs: 1 2 (one)}}
} {0 {varargs: 1 2 (one)}}
test methods-1.7d {variable arguments: two} {
test methods-1.7d {variable arguments: two} {
    list [catch {ta varargs 1 2 one two} msg] $msg
    list [catch {ta varargs 1 2 one two} msg] $msg
} {0 {varargs: 1 2 (one two)}}
} {0 {varargs: 1 2 (one two)}}
test methods-1.8 {magic "args" argument has no magic unless at end of list} {
test methods-1.8 {magic "args" argument has no magic unless at end of list} {
    list [catch {ta nomagic 1 2 3 4} msg] $msg
    list [catch {ta nomagic 1 2 3 4} msg] $msg
} {1 {wrong # args: should be "ta nomagic args x"}}
} {1 {wrong # args: should be "ta nomagic args x"}}
test methods-1.9 {formal args don't clobber class members} {
test methods-1.9 {formal args don't clobber class members} {
    list [catch {ta clash 1 2 3} msg] $msg \
    list [catch {ta clash 1 2 3} msg] $msg \
         [ta info variable bang -value] \
         [ta info variable bang -value] \
         [ta info variable boom -value]
         [ta info variable boom -value]
} {0 {clash: 1 2 3} ok no-problem}
} {0 {clash: 1 2 3} ok no-problem}
test methods-1.10 {formal args don't clobber class members} {
test methods-1.10 {formal args don't clobber class members} {
    list [catch {test_args::crash 4 5 6} msg] $msg \
    list [catch {test_args::crash 4 5 6} msg] $msg \
         [ta info variable bang -value] \
         [ta info variable bang -value] \
         [ta info variable boom -value]
         [ta info variable boom -value]
} {0 {crash: 4 5 6} ok no-problem}
} {0 {crash: 4 5 6} ok no-problem}
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#  Clean up
#  Clean up
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
delete class test_args
delete class test_args
 
 

powered by: WebSVN 2.1.0

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