sl@0: # This file is a Tcl script to test out the the procedures in file
sl@0: # tkIndexObj.c, which implement indexed table lookups.  The tests here
sl@0: # are organized in the standard fashion for Tcl tests.
sl@0: #
sl@0: # Copyright (c) 1997 Sun Microsystems, Inc.
sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0: #
sl@0: # See the file "license.terms" for information on usage and redistribution
sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0: #
sl@0: # RCS: @(#) $Id: indexObj.test,v 1.7.18.4 2006/04/06 18:57:30 dgp Exp $
sl@0: 
sl@0: if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0:     package require tcltest
sl@0:     namespace import -force ::tcltest::*
sl@0: }
sl@0: 
sl@0: if {[info commands testindexobj] == {}} {
sl@0:     puts "This application hasn't been compiled with the \"testindexobj\""
sl@0:     puts "command, so I can't test Tcl_GetIndexFromObj etc."
sl@0:     ::tcltest::cleanupTests
sl@0:     return 
sl@0: }
sl@0: 
sl@0: test indexObj-1.1 {exact match} {
sl@0:     testindexobj 1 1 xyz abc def xyz alm
sl@0: } {2}
sl@0: test indexObj-1.2 {exact match} {
sl@0:     testindexobj 1 1 abc abc def xyz alm
sl@0: } {0}
sl@0: test indexObj-1.3 {exact match} {
sl@0:     testindexobj 1 1 alm abc def xyz alm
sl@0: } {3}
sl@0: test indexObj-1.4 {unique abbreviation} {
sl@0:     testindexobj 1 1 xy abc def xalb xyz alm
sl@0: } {3}
sl@0: test indexObj-1.5 {multiple abbreviations and exact match} {
sl@0:     testindexobj 1 1 x abc def xalb xyz alm x
sl@0: } {5}
sl@0: test indexObj-1.6 {forced exact match} {
sl@0:     testindexobj 1 0 xy abc def xalb xy alm
sl@0: } {3}
sl@0: test indexObj-1.7 {forced exact match} {
sl@0:     testindexobj 1 0 x abc def xalb xyz alm x
sl@0: } {5}
sl@0: test indexObj-1.8 {exact match of empty values} {
sl@0:     testindexobj 1 1 {} a aa aaa {} b bb bbb
sl@0: } 3
sl@0: test indexObj-1.9 {exact match of empty values} {
sl@0:     testindexobj 1 0 {} a aa aaa {} b bb bbb
sl@0: } 3
sl@0: 
sl@0: test indexObj-2.1 {no match} {
sl@0:     list [catch {testindexobj 1 1 dddd abc def xalb xyz alm x} msg] $msg
sl@0: } {1 {bad token "dddd": must be abc, def, xalb, xyz, alm, or x}}
sl@0: test indexObj-2.2 {no match} {
sl@0:     list [catch {testindexobj 1 1 dddd abc} msg] $msg
sl@0: } {1 {bad token "dddd": must be abc}}
sl@0: test indexObj-2.3 {no match: no abbreviations} {
sl@0:     list [catch {testindexobj 1 0 xy abc def xalb xyz alm} msg] $msg
sl@0: } {1 {bad token "xy": must be abc, def, xalb, xyz, or alm}}
sl@0: test indexObj-2.4 {ambiguous value} {
sl@0:     list [catch {testindexobj 1 1 d dumb daughter a c} msg] $msg
sl@0: } {1 {ambiguous token "d": must be dumb, daughter, a, or c}}
sl@0: test indexObj-2.5 {omit error message} {
sl@0:     list [catch {testindexobj 0 1 d x} msg] $msg
sl@0: } {1 {}}
sl@0: test indexObj-2.6 {TCL_EXACT => no "ambiguous" error message} {
sl@0:     list [catch {testindexobj 1 0 d dumb daughter a c} msg] $msg
sl@0: } {1 {bad token "d": must be dumb, daughter, a, or c}}
sl@0: test indexObj-2.7 {exact match of empty values} {
sl@0:     list [catch {testindexobj 1 1 {} a b c} msg] $msg
sl@0: } {1 {ambiguous token "": must be a, b, or c}}
sl@0: test indexObj-2.8 {exact match of empty values: singleton case} {
sl@0:     list [catch {testindexobj 1 0 {} a} msg] $msg
sl@0: } {1 {bad token "": must be a}}
sl@0: test indexObj-2.9 {non-exact match of empty values: singleton case} {
sl@0:     # NOTE this is a special case.  Although the empty string is a
sl@0:     # unique prefix, we have an established history of rejecting
sl@0:     # empty lookup keys, requiring any unique prefix match to have
sl@0:     # at least one character.
sl@0:     list [catch {testindexobj 1 1 {} a} msg] $msg
sl@0: } {1 {bad token "": must be a}}
sl@0: 
sl@0: test indexObj-3.1 {cache result to skip next lookup} {
sl@0:     testindexobj check 42
sl@0: } {42}
sl@0: 
sl@0: test indexObj-4.1 {free old internal representation} {
sl@0:     set x {a b}
sl@0:     lindex $x 1
sl@0:     testindexobj 1 1 $x abc def {a b} zzz
sl@0: } {2}
sl@0: 
sl@0: test indexObj-5.1 {Tcl_WrongNumArgs} {
sl@0:     testwrongnumargs 1 "?option?" mycmd
sl@0: } "wrong # args: should be \"mycmd ?option?\""
sl@0: test indexObj-5.2 {Tcl_WrongNumArgs} {
sl@0:     testwrongnumargs 2 "bar" mycmd foo
sl@0: } "wrong # args: should be \"mycmd foo bar\""
sl@0: test indexObj-5.3 {Tcl_WrongNumArgs} {
sl@0:     testwrongnumargs 0 "bar" mycmd foo
sl@0: } "wrong # args: should be \"bar\""
sl@0: test indexObj-5.4 {Tcl_WrongNumArgs} {
sl@0:     testwrongnumargs 0 "" mycmd foo
sl@0: } "wrong # args: should be \"\""
sl@0: test indexObj-5.5 {Tcl_WrongNumArgs} {
sl@0:     testwrongnumargs 1 "" mycmd foo
sl@0: } "wrong # args: should be \"mycmd\""
sl@0: test indexObj-5.6 {Tcl_WrongNumArgs} {
sl@0:     testwrongnumargs 2 "" mycmd foo
sl@0: } "wrong # args: should be \"mycmd foo\""
sl@0: 
sl@0: test indexObj-6.1 {Tcl_GetIndexFromObjStruct} {
sl@0:     set x a
sl@0:     testgetindexfromobjstruct $x 0
sl@0: } "wrong # args: should be \"testgetindexfromobjstruct a 0\""
sl@0: test indexObj-6.2 {Tcl_GetIndexFromObjStruct} {
sl@0:     set x a
sl@0:     testgetindexfromobjstruct $x 0
sl@0:     testgetindexfromobjstruct $x 0
sl@0: } "wrong # args: should be \"testgetindexfromobjstruct a 0\""
sl@0: test indexObj-6.3 {Tcl_GetIndexFromObjStruct} {
sl@0:     set x c
sl@0:     testgetindexfromobjstruct $x 1
sl@0: } "wrong # args: should be \"testgetindexfromobjstruct c 1\""
sl@0: test indexObj-6.4 {Tcl_GetIndexFromObjStruct} {
sl@0:     set x c
sl@0:     testgetindexfromobjstruct $x 1
sl@0:     testgetindexfromobjstruct $x 1
sl@0: } "wrong # args: should be \"testgetindexfromobjstruct c 1\""
sl@0: 
sl@0: # cleanup
sl@0: ::tcltest::cleanupTests
sl@0: return