Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/indexObj.test @ 47

Last change on this file since 47 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 5.3 KB
Line 
1# This file is a Tcl script to test out the the procedures in file
2# tkIndexObj.c, which implement indexed table lookups.  The tests here
3# are organized in the standard fashion for Tcl tests.
4#
5# Copyright (c) 1997 Sun Microsystems, Inc.
6# Copyright (c) 1998-1999 by Scriptics Corporation.
7#
8# See the file "license.terms" for information on usage and redistribution
9# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10#
11# RCS: @(#) $Id: indexObj.test,v 1.15 2006/04/06 18:57:58 dgp Exp $
12
13if {[lsearch [namespace children] ::tcltest] == -1} {
14    package require tcltest
15    namespace import -force ::tcltest::*
16}
17
18testConstraint testindexobj [llength [info commands testindexobj]]
19
20test indexObj-1.1 {exact match} testindexobj {
21    testindexobj 1 1 xyz abc def xyz alm
22} {2}
23test indexObj-1.2 {exact match} testindexobj {
24    testindexobj 1 1 abc abc def xyz alm
25} {0}
26test indexObj-1.3 {exact match} testindexobj {
27    testindexobj 1 1 alm abc def xyz alm
28} {3}
29test indexObj-1.4 {unique abbreviation} testindexobj {
30    testindexobj 1 1 xy abc def xalb xyz alm
31} {3}
32test indexObj-1.5 {multiple abbreviations and exact match} testindexobj {
33    testindexobj 1 1 x abc def xalb xyz alm x
34} {5}
35test indexObj-1.6 {forced exact match} testindexobj {
36    testindexobj 1 0 xy abc def xalb xy alm
37} {3}
38test indexObj-1.7 {forced exact match} testindexobj {
39    testindexobj 1 0 x abc def xalb xyz alm x
40} {5}
41test indexObj-1.8 {exact match of empty values} testindexobj {
42    testindexobj 1 1 {} a aa aaa {} b bb bbb
43} 3
44test indexObj-1.9 {exact match of empty values} testindexobj {
45    testindexobj 1 0 {} a aa aaa {} b bb bbb
46} 3
47
48test indexObj-2.1 {no match} testindexobj {
49    list [catch {testindexobj 1 1 dddd abc def xalb xyz alm x} msg] $msg
50} {1 {bad token "dddd": must be abc, def, xalb, xyz, alm, or x}}
51test indexObj-2.2 {no match} testindexobj {
52    list [catch {testindexobj 1 1 dddd abc} msg] $msg
53} {1 {bad token "dddd": must be abc}}
54test indexObj-2.3 {no match: no abbreviations} testindexobj {
55    list [catch {testindexobj 1 0 xy abc def xalb xyz alm} msg] $msg
56} {1 {bad token "xy": must be abc, def, xalb, xyz, or alm}}
57test indexObj-2.4 {ambiguous value} testindexobj {
58    list [catch {testindexobj 1 1 d dumb daughter a c} msg] $msg
59} {1 {ambiguous token "d": must be dumb, daughter, a, or c}}
60test indexObj-2.5 {omit error message} testindexobj {
61    list [catch {testindexobj 0 1 d x} msg] $msg
62} {1 {}}
63test indexObj-2.6 {TCL_EXACT => no "ambiguous" error message} testindexobj {
64    list [catch {testindexobj 1 0 d dumb daughter a c} msg] $msg
65} {1 {bad token "d": must be dumb, daughter, a, or c}}
66test indexObj-2.7 {exact match of empty values} testindexobj {
67    list [catch {testindexobj 1 1 {} a b c} msg] $msg
68} {1 {ambiguous token "": must be a, b, or c}}
69test indexObj-2.8 {exact match of empty values: singleton case} testindexobj {
70    list [catch {testindexobj 1 0 {} a} msg] $msg
71} {1 {bad token "": must be a}}
72test indexObj-2.9 {non-exact match of empty values: singleton case} testindexobj {
73    # NOTE this is a special case.  Although the empty string is a
74    # unique prefix, we have an established history of rejecting
75    # empty lookup keys, requiring any unique prefix match to have
76    # at least one character.
77    list [catch {testindexobj 1 1 {} a} msg] $msg
78} {1 {bad token "": must be a}}
79
80test indexObj-3.1 {cache result to skip next lookup} testindexobj {
81    testindexobj check 42
82} {42}
83
84test indexObj-4.1 {free old internal representation} testindexobj {
85    set x {a b}
86    lindex $x 1
87    testindexobj 1 1 $x abc def {a b} zzz
88} {2}
89
90test indexObj-5.1 {Tcl_WrongNumArgs} testindexobj {
91    testwrongnumargs 1 "?option?" mycmd
92} "wrong # args: should be \"mycmd ?option?\""
93test indexObj-5.2 {Tcl_WrongNumArgs} testindexobj {
94    testwrongnumargs 2 "bar" mycmd foo
95} "wrong # args: should be \"mycmd foo bar\""
96test indexObj-5.3 {Tcl_WrongNumArgs} testindexobj {
97    testwrongnumargs 0 "bar" mycmd foo
98} "wrong # args: should be \"bar\""
99test indexObj-5.4 {Tcl_WrongNumArgs} testindexobj {
100    testwrongnumargs 0 "" mycmd foo
101} "wrong # args: should be \"\""
102test indexObj-5.5 {Tcl_WrongNumArgs} testindexobj {
103    testwrongnumargs 1 "" mycmd foo
104} "wrong # args: should be \"mycmd\""
105test indexObj-5.6 {Tcl_WrongNumArgs} testindexobj {
106    testwrongnumargs 2 "" mycmd foo
107} "wrong # args: should be \"mycmd foo\""
108# Contrast this with test proc-3.6; they have to be like this because
109# of [Bug 1066837] so Itcl won't break.
110test indexObj-5.7 {Tcl_WrongNumArgs} testindexobj {
111    testwrongnumargs 2 "fee fi" "fo fum" foo bar
112} "wrong # args: should be \"fo fum foo fee fi\""
113
114test indexObj-6.1 {Tcl_GetIndexFromObjStruct} testindexobj {
115    set x a
116    testgetindexfromobjstruct $x 0
117} "wrong # args: should be \"testgetindexfromobjstruct a 0\""
118test indexObj-6.2 {Tcl_GetIndexFromObjStruct} testindexobj {
119    set x a
120    testgetindexfromobjstruct $x 0
121    testgetindexfromobjstruct $x 0
122} "wrong # args: should be \"testgetindexfromobjstruct a 0\""
123test indexObj-6.3 {Tcl_GetIndexFromObjStruct} testindexobj {
124    set x c
125    testgetindexfromobjstruct $x 1
126} "wrong # args: should be \"testgetindexfromobjstruct c 1\""
127test indexObj-6.4 {Tcl_GetIndexFromObjStruct} testindexobj {
128    set x c
129    testgetindexfromobjstruct $x 1
130    testgetindexfromobjstruct $x 1
131} "wrong # args: should be \"testgetindexfromobjstruct c 1\""
132
133# cleanup
134::tcltest::cleanupTests
135return
136
137# Local Variables:
138# mode: tcl
139# End:
Note: See TracBrowser for help on using the repository browser.