home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / set.test < prev    next >
Encoding:
Text File  |  1995-04-25  |  21.0 KB  |  678 lines

  1. # Commands covered:  set, unset, array
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994-1995 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) set.test 1.17 95/04/25 14:36:48
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. proc ignore args {}
  18.  
  19. # Simple variable operations.
  20.  
  21. catch {unset a}
  22. test set-1.1 {basic variable setting and unsetting} {
  23.     set a 22
  24. } 22
  25. test set-1.2 {basic variable setting and unsetting} {
  26.     set a 123
  27.     set a
  28. } 123
  29. test set-1.3 {basic variable setting and unsetting} {
  30.     set a xxx
  31.     format %s $a
  32. } xxx
  33. test set-1.4 {basic variable setting and unsetting} {
  34.     set a 44
  35.     unset a
  36.     list [catch {set a} msg] $msg
  37. } {1 {can't read "a": no such variable}}
  38.  
  39. # Basic array operations.
  40.  
  41. catch {unset a}
  42. set a(xyz) 2
  43. set a(44) 3
  44. set {a(a long name)} test
  45. test set-2.1 {basic array operations} {
  46.     lsort [array names a]
  47. } {44 {a long name} xyz}
  48. test set-2.2 {basic array operations} {
  49.     set a(44)
  50. } 3
  51. test set-2.3 {basic array operations} {
  52.     set a(xyz)
  53. } 2
  54. test set-2.4 {basic array operations} {
  55.     set "a(a long name)"
  56. } test
  57. test set-2.5 {basic array operations} {
  58.     list [catch {set a(other)} msg] $msg
  59. } {1 {can't read "a(other)": no such element in array}}
  60. test set-2.6 {basic array operations} {
  61.     list [catch {set a} msg] $msg
  62. } {1 {can't read "a": variable is array}}
  63. test set-2.7 {basic array operations} {
  64.     format %s $a(44)
  65. } 3
  66. test set-2.8 {basic array operations} {
  67.     format %s $a(a long name)
  68. } test
  69. unset a(44)
  70. test set-2.9 {basic array operations} {
  71.     lsort [array names a]
  72. } {{a long name} xyz}
  73. test set-2.10 {basic array operations} {
  74.     catch {unset b}
  75.     list [catch {set b(123)} msg] $msg
  76. } {1 {can't read "b(123)": no such variable}}
  77. test set-2.11 {basic array operations} {
  78.     catch {unset b}
  79.     set b 44
  80.     list [catch {set b(123)} msg] $msg
  81. } {1 {can't read "b(123)": variable isn't array}}
  82. test set-2.12 {basic array operations} {
  83.     list [catch {set a 14} msg] $msg
  84. } {1 {can't set "a": variable is array}}
  85. unset a
  86. test set-2.13 {basic array operations} {
  87.     list [catch {set a(xyz)} msg] $msg
  88. } {1 {can't read "a(xyz)": no such variable}}
  89.  
  90. # Test the set commands, and exercise the corner cases of the code
  91. # that parses array references into two parts.
  92.  
  93. test set-3.1 {set command} {
  94.     list [catch {set} msg] $msg
  95. } {1 {wrong # args: should be "set varName ?newValue?"}}
  96. test set-3.2 {set command} {
  97.     list [catch {set x y z} msg] $msg
  98. } {1 {wrong # args: should be "set varName ?newValue?"}}
  99. test set-3.3 {set command} {
  100.     catch {unset a}
  101.     list [catch {set a} msg] $msg
  102. } {1 {can't read "a": no such variable}}
  103. test set-3.4 {set command} {
  104.     catch {unset a}
  105.     set a(14) 83
  106.     list [catch {set a 22} msg] $msg
  107. } {1 {can't set "a": variable is array}}
  108.  
  109. # Test the corner-cases of parsing array names, using set and unset.
  110.  
  111. test set-4.1 {parsing array names} {
  112.     catch {unset a}
  113.     set a(()) 44
  114.     list [catch {array names a} msg] $msg
  115. } {0 ()}
  116. test set-4.2 {parsing array names} {
  117.     catch {unset a a(abcd}
  118.     set a(abcd 33
  119.     info exists a(abcd
  120. } 1
  121. test set-4.3 {parsing array names} {
  122.     catch {unset a a(abcd}
  123.     set a(abcd 33
  124.     list [catch {array names a} msg] $msg
  125. } {0 {}}
  126. test set-4.4 {parsing array names} {
  127.     catch {unset a abcd)}
  128.     set abcd) 33
  129.     info exists abcd)
  130. } 1
  131. test set-4.5 {parsing array names} {
  132.     set a(bcd yyy
  133.     catch {unset a}
  134.     list [catch {set a(bcd} msg] $msg
  135. } {0 yyy}
  136. test set-4.6 {parsing array names} {
  137.     catch {unset a}
  138.     set a 44
  139.     list [catch {set a(bcd test} msg] $msg
  140. } {0 test}
  141.  
  142. # Errors in reading variables
  143.  
  144. test set-5.1 {errors in reading variables} {
  145.     catch {unset a}
  146.     list [catch {set a} msg] $msg
  147. } {1 {can't read "a": no such variable}}
  148. test set-5.2 {errors in reading variables} {
  149.     catch {unset a}
  150.     set a 44
  151.     list [catch {set a(18)} msg] $msg
  152. } {1 {can't read "a(18)": variable isn't array}}
  153. test set-5.3 {errors in reading variables} {
  154.     catch {unset a}
  155.     set a(6) 44
  156.     list [catch {set a(18)} msg] $msg
  157. } {1 {can't read "a(18)": no such element in array}}
  158. test set-5.4 {errors in reading variables} {
  159.     catch {unset a}
  160.     set a(6) 44
  161.     list [catch {set a} msg] $msg
  162. } {1 {can't read "a": variable is array}}
  163.  
  164. # Errors and other special cases in writing variables
  165.  
  166. test set-6.1 {creating array during write} {
  167.     catch {unset a}
  168.     trace var a rwu ignore
  169.     list [catch {set a(14) 186} msg] $msg [array names a]
  170. } {0 186 14}
  171. test set-6.2 {errors in writing variables} {
  172.     catch {unset a}
  173.     set a xxx
  174.     list [catch {set a(14) 186} msg] $msg
  175. } {1 {can't set "a(14)": variable isn't array}}
  176. test set-6.3 {errors in writing variables} {
  177.     catch {unset a}
  178.     set a(100) yyy
  179.     list [catch {set a 2} msg] $msg
  180. } {1 {can't set "a": variable is array}}
  181. test set-6.4 {expanding variable size} {
  182.     catch {unset a}
  183.     list [set a short] [set a "longer name"] [set a "even longer name"] \
  184.         [set a "a much much truly longer name"]
  185. } {short {longer name} {even longer name} {a much much truly longer name}}
  186.  
  187. # Unset command, Tcl_UnsetVar procedures
  188.  
  189. test set-7.1 {unset command} {
  190.     catch {unset a}; catch {unset b}; catch {unset c}; catch {unset d}
  191.     set a 44
  192.     set b 55
  193.     set c 66
  194.     set d 77
  195.     unset a b c
  196.     list [catch {set a(0) 0}] [catch {set b(0) 0}] [catch {set c(0) 0}] \
  197.         [catch {set d(0) 0}]
  198. } {0 0 0 1}
  199. test set-7.2 {unset command} {
  200.     list [catch {unset} msg] $msg
  201. } {1 {wrong # args: should be "unset varName ?varName ...?"}}
  202. test set-7.3 {unset command} {
  203.     catch {unset a}
  204.     list [catch {unset a} msg] $msg
  205. } {1 {can't unset "a": no such variable}}
  206. test set-7.4 {unset command} {
  207.     catch {unset a}
  208.     set a 44
  209.     list [catch {unset a(14)} msg] $msg
  210. } {1 {can't unset "a(14)": variable isn't array}}
  211. test set-7.5 {unset command} {
  212.     catch {unset a}
  213.     set a(0) xx
  214.     list [catch {unset a(14)} msg] $msg
  215. } {1 {can't unset "a(14)": no such element in array}}
  216. test set-7.6 {unset command} {
  217.     catch {unset a}; catch {unset b}; catch {unset c}
  218.     set a foo
  219.     set c gorp
  220.     list [catch {unset a a a(14)} msg] $msg [info exists c]
  221. } {1 {can't unset "a": no such variable} 1}
  222. test set-7.7 {unsetting globals from within procedures} {
  223.     set y 0
  224.     proc p1 {} {
  225.     global y
  226.     set z [p2]
  227.     return [list $z [catch {set y} msg] $msg]
  228.     }
  229.     proc p2 {} {global y; unset y; list [catch {set y} msg] $msg}
  230.     p1
  231. } {{1 {can't read "y": no such variable}} 1 {can't read "y": no such variable}}
  232. test set-7.8 {unsetting globals from within procedures} {
  233.     set y 0
  234.     proc p1 {} {
  235.     global y
  236.     p2
  237.     return [list [catch {set y 44} msg] $msg]
  238.     }
  239.     proc p2 {} {global y; unset y}
  240.     concat [p1] [list [catch {set y} msg] $msg]
  241. } {0 44 0 44}
  242. test set-7.9 {unsetting globals from within procedures} {
  243.     set y 0
  244.     proc p1 {} {
  245.     global y
  246.     unset y
  247.     return [list [catch {set y 55} msg] $msg]
  248.     }
  249.     concat [p1] [list [catch {set y} msg] $msg]
  250. } {0 55 0 55}
  251. test set-7.10 {unset command} {
  252.     catch {unset a}
  253.     set a(14) 22
  254.     unset a(14)
  255.     list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2
  256. } {1 {can't read "a(14)": no such element in array} 0 {}}
  257. test set-7.11 {unset command} {
  258.     catch {unset a}
  259.     set a(14) 22
  260.     unset a
  261.     list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2
  262. } {1 {can't read "a(14)": no such variable} 0 {}}
  263.  
  264. # Array command.
  265.  
  266. test set-8.1 {array command} {
  267.     list [catch {array} msg] $msg
  268. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  269. test set-8.2 {array command} {
  270.     list [catch {array a} msg] $msg
  271. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  272. test set-8.3 {array command} {
  273.     catch {unset a}
  274.     list [catch {array anymore a b} msg] $msg
  275. } {1 {"a" isn't an array}}
  276. test set-8.4 {array command} {
  277.     catch {unset a}
  278.     set a 44
  279.     list [catch {array anymore a b} msg] $msg
  280. } {1 {"a" isn't an array}}
  281. test set-8.5 {array command} {
  282.     proc foo {} {
  283.     set a 44
  284.     upvar 0 a x
  285.     list [catch {array anymore x b} msg] $msg
  286.     }
  287.     foo
  288. } {1 {"x" isn't an array}}
  289. test set-8.6 {array command} {
  290.     catch {unset a}
  291.     set a(22) 3
  292.     list [catch {array gorp a} msg] $msg
  293. } {1 {bad option "gorp": should be anymore, donesearch, exists, get, names, nextelement, set, size, or startsearch}}
  294. test set-8.7 {array command, anymore option} {
  295.     catch {unset a}
  296.     list [catch {array anymore a x} msg] $msg
  297. } {1 {"a" isn't an array}}
  298. test set-8.8 {array command, donesearch option} {
  299.     catch {unset a}
  300.     list [catch {array donesearch a x} msg] $msg
  301. } {1 {"a" isn't an array}}
  302. test set-8.9 {array command, exists option} {
  303.     list [catch {array exists a b} msg] $msg
  304. } {1 {wrong # args: should be "array exists arrayName"}}
  305. test set-8.10 {array command, exists option} {
  306.     catch {unset a}
  307.     array exists a
  308. } {0}
  309. test set-8.11 {array command, exists option} {
  310.     catch {unset a}
  311.     set a(0) 1
  312.     array exists a
  313. } {1}
  314. test set-8.12 {array command, get option} {
  315.     list [catch {array get} msg] $msg
  316. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  317. test set-8.13 {array command, get option} {
  318.     list [catch {array get a b c} msg] $msg
  319. } {1 {wrong # args: should be "array get arrayName ?pattern?"}}
  320. test set-8.14 {array command, get option} {
  321.     catch {unset a}
  322.     array get a
  323. } {}
  324. test set-8.15 {array command, get option} {
  325.     catch {unset a}
  326.     set a(22) 3
  327.     set {a(long name)} {}
  328.     array get a
  329. } {22 3 {long name} {}}
  330. test set-8.16 {array command, get option (unset variable)} {
  331.     catch {unset a}
  332.     set a(x) 3
  333.     trace var a(y) w ignore
  334.     array get a
  335. } {x 3}
  336. test set-8.17 {array command, get option, with pattern} {
  337.     catch {unset a}
  338.     set a(x1) 3
  339.     set a(x2) 4
  340.     set a(x3) 5
  341.     set a(b1) 24
  342.     set a(b2) 25
  343.     array get a x*
  344. } {x1 3 x2 4 x3 5}
  345. test set-8.18 {array command, names option} {
  346.     catch {unset a}
  347.     set a(22) 3
  348.     list [catch {array names a 4 5} msg] $msg
  349. } {1 {wrong # args: should be "array names arrayName ?pattern?"}}
  350. test set-8.19 {array command, names option} {
  351.     catch {unset a}
  352.     array names a
  353. } {}
  354. test set-8.20 {array command, names option} {
  355.     catch {unset a}
  356.     set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx
  357.     list [catch {lsort [array names a]} msg] $msg
  358. } {0 {22 Textual_name {name with spaces}}}
  359. test set-8.21 {array command, names option} {
  360.     catch {unset a}
  361.     set a(22) 3; set a(33) 44;
  362.     trace var a(xxx) w ignore
  363.     list [catch {lsort [array names a]} msg] $msg
  364. } {0 {22 33}}
  365. test set-8.22 {array command, names option} {
  366.     catch {unset a}
  367.     set a(22) 3; set a(33) 44;
  368.     trace var a(xxx) w ignore
  369.     set a(xxx) value
  370.     list [catch {lsort [array names a]} msg] $msg
  371. } {0 {22 33 xxx}}
  372. test set-8.23 {array command, names option} {
  373.     catch {unset a}
  374.     set a(axy) 3
  375.     set a(bxy) 44
  376.     set a(no) yes
  377.     set a(xxx) value
  378.     list [lsort [array names a *xy]] [lsort [array names a]]
  379. } {{axy bxy} {axy bxy no xxx}}
  380. test set-8.24 {array command, nextelement option} {
  381.     list [catch {array nextelement a} msg] $msg
  382. } {1 {wrong # args: should be "array nextelement arrayName searchId"}}
  383. test set-8.25 {array command, nextelement option} {
  384.     catch {unset a}
  385.     list [catch {array nextelement a b} msg] $msg
  386. } {1 {"a" isn't an array}}
  387. test set-8.26 {array command, set option} {
  388.     list [catch {array set a} msg] $msg
  389. } {1 {wrong # args: should be "array set arrayName list"}}
  390. test set-8.27 {array command, set option} {
  391.     list [catch {array set a 1 2} msg] $msg
  392. } {1 {wrong # args: should be "array set arrayName list"}}
  393. test set-8.28 {array command, set option} {
  394.     list [catch {array set a "a \{ c"} msg] $msg
  395. } {1 {unmatched open brace in list}}
  396. test set-8.29 {array command, set option} {
  397.     catch {unset a}
  398.     set a 44
  399.     list [catch {array set a {a b c d}} msg] $msg
  400. } {1 {can't set "a(a)": variable isn't array}}
  401. test set-8.30 {array command, set option} {
  402.     catch {unset a}
  403.     set a(xx) yy
  404.     array set a {b c d e}
  405.     array get a
  406. } {d e xx yy b c}
  407. test set-8.31 {array command, size option} {
  408.     list [catch {array size a 4} msg] $msg
  409. } {1 {wrong # args: should be "array size arrayName"}}
  410. test set-8.32 {array command, size option} {
  411.     catch {unset a}
  412.     array size a
  413. } {0}
  414. test set-8.33 {array command, size option} {
  415.     catch {unset a}
  416.     set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx
  417.     list [catch {array size a} msg] $msg
  418. } {0 3}
  419. test set-8.34 {array command, size option} {
  420.     catch {unset a}
  421.     set a(22) 3; set a(xx) 44; set a(y) xxx
  422.     unset a(22) a(y) a(xx)
  423.     list [catch {array size a} msg] $msg
  424. } {0 0}
  425. test set-8.35 {array command, size option} {
  426.     catch {unset a}
  427.     set a(22) 3;
  428.     trace var a(33) rwu ignore
  429.     list [catch {array size a} msg] $msg
  430. } {0 1}
  431. test set-8.36 {array command, startsearch option} {
  432.     list [catch {array startsearch a b} msg] $msg
  433. } {1 {wrong # args: should be "array startsearch arrayName"}}
  434. test set-8.37 {array command, startsearch option} {
  435.     catch {unset a}
  436.     list [catch {array startsearch a} msg] $msg
  437. } {1 {"a" isn't an array}}
  438.  
  439. test set-9.1 {ids for array enumeration} {
  440.     catch {unset a}
  441.     set a(a) 1
  442.     list [array st a] [array st a] [array done a s-1-a; array st a] \
  443.         [array done a s-2-a; array d a s-3-a; array start a]
  444. } {s-1-a s-2-a s-3-a s-1-a}
  445. test set-9.2 {array enumeration} {
  446.     catch {unset a}
  447.     set a(a) 1
  448.     set a(b) 1
  449.     set a(c) 1
  450.     set x [array startsearch a]
  451.     list [array nextelement a $x] [array ne a $x] [array next a $x] \
  452.         [array next a $x] [array next a $x]
  453. } {a b c {} {}}
  454. test set-9.3 {array enumeration} {
  455.     catch {unset a}
  456.     set a(a) 1
  457.     set a(b) 1
  458.     set a(c) 1
  459.     set x [array startsearch a]
  460.     set y [array startsearch a]
  461.     set z [array startsearch a]
  462.     list [array nextelement a $x] [array ne a $x] \
  463.         [array next a $y] [array next a $z] [array next a $y] \
  464.         [array next a $z] [array next a $y] [array next a $z] \
  465.         [array next a $y] [array next a $z] [array next a $x] \
  466.         [array next a $x]
  467. } {a b a a b b c c {} {} c {}}
  468. test set-9.4 {array enumeration: stopping searches} {
  469.     catch {unset a}
  470.     set a(a) 1
  471.     set a(b) 1
  472.     set a(c) 1
  473.     set x [array startsearch a]
  474.     set y [array startsearch a]
  475.     set z [array startsearch a]
  476.     list [array next a $x] [array next a $x] [array next a $y] \
  477.         [array done a $z; array next a $x] \
  478.         [array done a $x; array next a $y] [array next a $y]
  479. } {a b a c b c}
  480. test set-9.5 {array enumeration: stopping searches} {
  481.     catch {unset a}
  482.     set a(a) 1
  483.     set x [array startsearch a]
  484.     array done a $x
  485.     list [catch {array next a $x} msg] $msg
  486. } {1 {couldn't find search "s-1-a"}}
  487. test set-9.6 {array enumeration: searches automatically stopped} {
  488.     catch {unset a}
  489.     set a(a) 1
  490.     set x [array startsearch a]
  491.     set y [array startsearch a]
  492.     set a(b) 1
  493.     list [catch {array next a $x} msg] $msg \
  494.         [catch {array next a $y} msg2] $msg2
  495. } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}}
  496. test set-9.7 {array enumeration: searches automatically stopped} {
  497.     catch {unset a}
  498.     set a(a) 1
  499.     set x [array startsearch a]
  500.     set y [array startsearch a]
  501.     set a(a) 2
  502.     list [catch {array next a $x} msg] $msg \
  503.         [catch {array next a $y} msg2] $msg2
  504. } {0 a 0 a}
  505. test set-9.8 {array enumeration: searches automatically stopped} {
  506.     catch {unset a}
  507.     set a(a) 1
  508.     set a(c) 2
  509.     set x [array startsearch a]
  510.     set y [array startsearch a]
  511.     catch {unset a(c)}
  512.     list [catch {array next a $x} msg] $msg \
  513.         [catch {array next a $y} msg2] $msg2
  514. } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}}
  515. test set-9.9 {array enumeration: searches automatically stopped} {
  516.     catch {unset a}
  517.     set a(a) 1
  518.     set x [array startsearch a]
  519.     set y [array startsearch a]
  520.     catch {unset a(c)}
  521.     list [catch {array next a $x} msg] $msg \
  522.         [catch {array next a $y} msg2] $msg2
  523. } {0 a 0 a}
  524. test set-9.10 {array enumeration: searches automatically stopped} {
  525.     catch {unset a}
  526.     set a(a) 1
  527.     set x [array startsearch a]
  528.     set y [array startsearch a]
  529.     trace var a(b) r {}
  530.     list [catch {array next a $x} msg] $msg \
  531.         [catch {array next a $y} msg2] $msg2
  532. } {1 {couldn't find search "s-1-a"} 1 {couldn't find search "s-2-a"}}
  533. test set-9.11 {array enumeration: searches automatically stopped} {
  534.     catch {unset a}
  535.     set a(a) 1
  536.     set x [array startsearch a]
  537.     set y [array startsearch a]
  538.     trace var a(a) r {}
  539.     list [catch {array next a $x} msg] $msg \
  540.         [catch {array next a $y} msg2] $msg2
  541. } {0 a 0 a}
  542. test set-9.12 {array enumeration with traced undefined elements} {
  543.     catch {unset a}
  544.     set a(a) 1
  545.     trace var a(b) r {}
  546.     set x [array startsearch a]
  547.     list [array next a $x] [array next a $x]
  548. } {a {}}
  549.  
  550. test set-10.1 {array enumeration errors} {
  551.     list [catch {array start} msg] $msg
  552. } {1 {wrong # args: should be "array option arrayName ?arg ...?"}}
  553. test set-10.2 {array enumeration errors} {
  554.     list [catch {array start a b} msg] $msg
  555. } {1 {wrong # args: should be "array startsearch arrayName"}}
  556. test set-10.3 {array enumeration errors} {
  557.     catch {unset a}
  558.     list [catch {array start a} msg] $msg
  559. } {1 {"a" isn't an array}}
  560. test set-10.4 {array enumeration errors} {
  561.     catch {unset a}
  562.     set a(a) 1
  563.     set x [array startsearch a]
  564.     list [catch {array next a} msg] $msg
  565. } {1 {wrong # args: should be "array nextelement arrayName searchId"}}
  566. test set-10.5 {array enumeration errors} {
  567.     catch {unset a}
  568.     set a(a) 1
  569.     set x [array startsearch a]
  570.     list [catch {array next a b c} msg] $msg
  571. } {1 {wrong # args: should be "array nextelement arrayName searchId"}}
  572. test set-10.6 {array enumeration errors} {
  573.     catch {unset a}
  574.     set a(a) 1
  575.     set x [array startsearch a]
  576.     list [catch {array next a a-1-a} msg] $msg
  577. } {1 {illegal search identifier "a-1-a"}}
  578. test set-10.7 {array enumeration errors} {
  579.     catch {unset a}
  580.     set a(a) 1
  581.     set x [array startsearch a]
  582.     list [catch {array next a sx1-a} msg] $msg
  583. } {1 {illegal search identifier "sx1-a"}}
  584. test set-10.8 {array enumeration errors} {
  585.     catch {unset a}
  586.     set a(a) 1
  587.     set x [array startsearch a]
  588.     list [catch {array next a s--a} msg] $msg
  589. } {1 {illegal search identifier "s--a"}}
  590. test set-10.9 {array enumeration errors} {
  591.     catch {unset a}
  592.     set a(a) 1
  593.     set x [array startsearch a]
  594.     list [catch {array next a s-1-b} msg] $msg
  595. } {1 {search identifier "s-1-b" isn't for variable "a"}}
  596. test set-10.10 {array enumeration errors} {
  597.     catch {unset a}
  598.     set a(a) 1
  599.     set x [array startsearch a]
  600.     list [catch {array next a s-1ba} msg] $msg
  601. } {1 {illegal search identifier "s-1ba"}}
  602. test set-10.11 {array enumeration errors} {
  603.     catch {unset a}
  604.     set a(a) 1
  605.     set x [array startsearch a]
  606.     list [catch {array next a s-2-a} msg] $msg
  607. } {1 {couldn't find search "s-2-a"}}
  608. test set-10.12 {array enumeration errors} {
  609.     list [catch {array done a} msg] $msg
  610. } {1 {wrong # args: should be "array donesearch arrayName searchId"}}
  611. test set-10.13 {array enumeration errors} {
  612.     list [catch {array done a b c} msg] $msg
  613. } {1 {wrong # args: should be "array donesearch arrayName searchId"}}
  614. test set-10.14 {array enumeration errors} {
  615.     list [catch {array done a b} msg] $msg
  616. } {1 {illegal search identifier "b"}}
  617. test set-10.15 {array enumeration errors} {
  618.     list [catch {array anymore a} msg] $msg
  619. } {1 {wrong # args: should be "array anymore arrayName searchId"}}
  620. test set-10.16 {array enumeration errors} {
  621.     list [catch {array any a b c} msg] $msg
  622. } {1 {wrong # args: should be "array anymore arrayName searchId"}}
  623. test set-10.17 {array enumeration errors} {
  624.     catch {unset a}
  625.     set a(0) 44
  626.     list [catch {array any a bogus} msg] $msg
  627. } {1 {illegal search identifier "bogus"}}
  628.  
  629. # Array enumeration with "anymore" option
  630.  
  631. test set-11.1 {array anymore option} {
  632.     catch {unset a}
  633.     set a(a) 1
  634.     set a(b) 2
  635.     set a(c) 3
  636.     array startsearch a
  637.     list [array anymore a s-1-a] [array next a s-1-a] \
  638.         [array anymore a s-1-a] [array next a s-1-a] \
  639.         [array anymore a s-1-a] [array next a s-1-a] \
  640.         [array anymore a s-1-a] [array next a s-1-a] 
  641. } {1 a 1 b 1 c 0 {}}
  642. test set-11.2 {array anymore option} {
  643.     catch {unset a}
  644.     set a(a) 1
  645.     set a(b) 2
  646.     set a(c) 3
  647.     array startsearch a
  648.     list [array next a s-1-a] [array next a s-1-a] \
  649.         [array anymore a s-1-a] [array next a s-1-a] \
  650.         [array next a s-1-a] [array anymore a s-1-a] 
  651. } {a b 1 c {} 0}
  652.  
  653. # Special check to see that the value of a variable is handled correctly
  654. # if it is returned as the result of a procedure (must not free the variable
  655. # string while deleting the call frame).  Errors will only be detected if
  656. # a memory consistency checker such as Purify is being used.
  657.  
  658. test set-12.1 {cleanup on procedure return} {
  659.     proc foo {} {
  660.     set x 12345
  661.     }
  662.     foo
  663. } 12345
  664. test set-12.2 {cleanup on procedure return} {
  665.     proc foo {} {
  666.     set x(1) 23456
  667.     }
  668.     foo
  669. } 23456
  670.  
  671. # Must delete variables when done, since these arrays get used as
  672. # scalars by other tests.
  673.  
  674. catch {unset a}
  675. catch {unset b}
  676. catch {unset c}
  677. return ""
  678.