Skip to content
Tcl Source Code Artifact [526f4637c5]
Login

Artifact [526f4637c5]

Artifact 526f4637c5d2dc5d4157824be633fc64163b657ec9e62cc580046d74a21c7b6b:


# Copyright © 1991-1994 The Regents of the University of California.
# Copyright © 1994 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

# You may distribute and/or modify this program under the terms of the GNU
# Affero General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# See the file "COPYING" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

# This file tests the AssocData facility of Tcl
#
# 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.

if {"::tcltest" ni [namespace children]} {
    package require tcltest 2.5
    namespace import -force ::tcltest::*
}

::tcltest::loadTestedCommands
catch [list package require -exact tcl::test [info patchlevel]]

testConstraint testgetassocdata [llength [info commands testgetassocdata]]
testConstraint testsetassocdata [llength [info commands testsetassocdata]]
testConstraint testdelassocdata [llength [info commands testdelassocdata]]

test assocd-1.1 {testing setting assoc data} testsetassocdata {
   testsetassocdata a 1
} ""
test assocd-1.2 {testing setting assoc data} testsetassocdata {
   testsetassocdata a 2
} ""
test assocd-1.3 {testing setting assoc data} testsetassocdata {
   testsetassocdata 123 456
} ""
test assocd-1.4 {testing setting assoc data} testsetassocdata {
   testsetassocdata abc "abc d e f"
} ""

test assocd-2.1 {testing getting assoc data} -setup {
    testsetassocdata a 2
} -constraints {testgetassocdata} -body {
    testgetassocdata a
} -result 2
test assocd-2.2 {testing getting assoc data} -setup {
    testsetassocdata 123 456
} -constraints {testgetassocdata} -body {
    testgetassocdata 123
} -result 456
test assocd-2.3 {testing getting assoc data} -setup {
   testsetassocdata abc "abc d e f"
} -constraints {testgetassocdata} -body {
   testgetassocdata abc
} -result "abc d e f"
test assocd-2.4 {testing getting assoc data} testgetassocdata {
   testgetassocdata xxx
} ""

test assocd-3.1 {testing deleting assoc data} testdelassocdata {
   testdelassocdata a
} ""
test assocd-3.2 {testing deleting assoc data} testdelassocdata {
   testdelassocdata 123
} ""
test assocd-3.3 {testing deleting assoc data} testdelassocdata {
   list [catch {testdelassocdata nonexistent} msg] $msg
} {0 {}}

# cleanup
cleanupTests
return