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