home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / dstring.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  7.4 KB  |  248 lines

  1. # Commands covered:  none
  2. #
  3. # This file contains a collection of tests for Tcl's dynamic string
  4. # library procedures.  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) 1993 The Regents of the University of California.
  8. # Copyright (c) 1994 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. # @(#) dstring.test 1.7 94/12/17 16:19:49
  14.  
  15. if {[info commands testdstring] == {}} {
  16.     puts "This application hasn't been compiled with the \"testdstring\""
  17.     puts "command, so I can't test Tcl_DStringAppend et al."
  18.     return
  19. }
  20.  
  21. if {[string compare test [info procs test]] == 1} then {source defs}
  22.  
  23. test dstring-1.1 {appending and retrieving} {
  24.     testdstring free
  25.     testdstring append "abc" -1
  26.     list [testdstring get] [testdstring length]
  27. } {abc 3}
  28. test dstring-1.2 {appending and retrieving} {
  29.     testdstring free
  30.     testdstring append "abc" -1
  31.     testdstring append " xyzzy" 3
  32.     testdstring append " 12345" -1
  33.     list [testdstring get] [testdstring length]
  34. } {{abc xy 12345} 12}
  35. test dstring-1.3 {appending and retrieving} {
  36.     testdstring free
  37.     foreach l {a b c d e f g h i j k l m n o p} {
  38.     testdstring append $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l\n -1
  39.     }
  40.     list [testdstring get] [testdstring length]
  41. } {{aaaaaaaaaaaaaaaaaaaaa
  42. bbbbbbbbbbbbbbbbbbbbb
  43. ccccccccccccccccccccc
  44. ddddddddddddddddddddd
  45. eeeeeeeeeeeeeeeeeeeee
  46. fffffffffffffffffffff
  47. ggggggggggggggggggggg
  48. hhhhhhhhhhhhhhhhhhhhh
  49. iiiiiiiiiiiiiiiiiiiii
  50. jjjjjjjjjjjjjjjjjjjjj
  51. kkkkkkkkkkkkkkkkkkkkk
  52. lllllllllllllllllllll
  53. mmmmmmmmmmmmmmmmmmmmm
  54. nnnnnnnnnnnnnnnnnnnnn
  55. ooooooooooooooooooooo
  56. ppppppppppppppppppppp
  57. } 352}
  58.  
  59. test dstring-2.1 {appending list elements} {
  60.     testdstring free
  61.     testdstring element "abc"
  62.     testdstring element "d e f"
  63.     list [testdstring get] [testdstring length]
  64. } {{abc {d e f}} 11}
  65. test dstring-2.2 {appending list elements} {
  66.     testdstring free
  67.     testdstring element "x"
  68.     testdstring element "\{"
  69.     testdstring element "ab\}"
  70.     testdstring get
  71. } {x \{ ab\}}
  72. test dstring-2.3 {appending list elements} {
  73.     testdstring free
  74.     foreach l {a b c d e f g h i j k l m n o p} {
  75.     testdstring element $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l
  76.     }
  77.     testdstring get
  78. } {aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc ddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeee fffffffffffffffffffff ggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiii jjjjjjjjjjjjjjjjjjjjj kkkkkkkkkkkkkkkkkkkkk lllllllllllllllllllll mmmmmmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnnnnnn ooooooooooooooooooooo ppppppppppppppppppppp}
  79. test dstring-2.4 {appending list elements} {
  80.     testdstring free
  81.     testdstring append "a\{" -1
  82.     testdstring element abc
  83.     testdstring append "    \{" -1
  84.     testdstring element xyzzy
  85.     testdstring get
  86. } "a{ abc    {xyzzy"
  87. test dstring-2.5 {appending list elements} {
  88.     testdstring free
  89.     testdstring append " \{" -1
  90.     testdstring element abc
  91.     testdstring get
  92. } " {abc"
  93. test dstring-2.6 {appending list elements} {
  94.     testdstring free
  95.     testdstring append " " -1
  96.     testdstring element abc
  97.     testdstring get
  98. } { abc}
  99. test dstring-2.7 {appending list elements} {
  100.     testdstring free
  101.     testdstring append "\\ " -1
  102.     testdstring element abc
  103.     testdstring get
  104. } "\\  abc"
  105. test dstring-2.8 {appending list elements} {
  106.     testdstring free
  107.     testdstring append "x " -1
  108.     testdstring element abc
  109.     testdstring get
  110. } {x abc}
  111.  
  112. test dstring-3.1 {nested sublists} {
  113.     testdstring free
  114.     testdstring start
  115.     testdstring element foo
  116.     testdstring element bar
  117.     testdstring end
  118.     testdstring element another
  119.     testdstring get
  120. } {{foo bar} another}
  121. test dstring-3.2 {nested sublists} {
  122.     testdstring free
  123.     testdstring start
  124.     testdstring start
  125.     testdstring element abc
  126.     testdstring element def
  127.     testdstring end
  128.     testdstring end
  129.     testdstring element ghi
  130.     testdstring get
  131. } {{{abc def}} ghi}
  132. test dstring-3.3 {nested sublists} {
  133.     testdstring free
  134.     testdstring start
  135.     testdstring start
  136.     testdstring start
  137.     testdstring element foo
  138.     testdstring element foo2
  139.     testdstring end
  140.     testdstring end
  141.     testdstring element foo3
  142.     testdstring end
  143.     testdstring element foo4
  144.     testdstring get
  145. } {{{{foo foo2}} foo3} foo4}
  146. test dstring-3.4 {nested sublists} {
  147.     testdstring free
  148.     testdstring element before
  149.     testdstring start
  150.     testdstring element during
  151.     testdstring element more
  152.     testdstring end
  153.     testdstring element last
  154.     testdstring get
  155. } {before {during more} last}
  156. test dstring-3.4 {nested sublists} {
  157.     testdstring free
  158.     testdstring element "\{"
  159.     testdstring start
  160.     testdstring element first
  161.     testdstring element second
  162.     testdstring end
  163.     testdstring get
  164. } {\{ {first second}}
  165.  
  166. test dstring-4.1 {truncation} {
  167.     testdstring free
  168.     testdstring append "abcdefg" -1
  169.     testdstring trunc 3
  170.     list [testdstring get] [testdstring length]
  171. } {abc 3}
  172. test dstring-4.2 {truncation} {
  173.     testdstring free
  174.     testdstring append "xyzzy" -1
  175.     testdstring trunc 0
  176.     list [testdstring get] [testdstring length]
  177. } {{} 0}
  178.  
  179. test dstring-5.1 {copying to result} {
  180.     testdstring free
  181.     testdstring append xyz -1
  182.     testdstring result
  183. } xyz
  184. test dstring-5.2 {copying to result} {
  185.     testdstring free
  186.     foreach l {a b c d e f g h i j k l m n o p} {
  187.     testdstring append $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l\n -1
  188.     }
  189.     set a [testdstring result]
  190.     testdstring append abc -1
  191.     list $a [testdstring get]
  192. } {{aaaaaaaaaaaaaaaaaaaaa
  193. bbbbbbbbbbbbbbbbbbbbb
  194. ccccccccccccccccccccc
  195. ddddddddddddddddddddd
  196. eeeeeeeeeeeeeeeeeeeee
  197. fffffffffffffffffffff
  198. ggggggggggggggggggggg
  199. hhhhhhhhhhhhhhhhhhhhh
  200. iiiiiiiiiiiiiiiiiiiii
  201. jjjjjjjjjjjjjjjjjjjjj
  202. kkkkkkkkkkkkkkkkkkkkk
  203. lllllllllllllllllllll
  204. mmmmmmmmmmmmmmmmmmmmm
  205. nnnnnnnnnnnnnnnnnnnnn
  206. ooooooooooooooooooooo
  207. ppppppppppppppppppppp
  208. } abc}
  209.  
  210. test dstring-6.1 {Tcl_DStringGetResult} {
  211.     testdstring free
  212.     list [testdstring gresult staticsmall] [testdstring get]
  213. } {{} short}
  214. test dstring-6.2 {Tcl_DStringGetResult} {
  215.     testdstring free
  216.     foreach l {a b c d e f g h i j k l m n o p} {
  217.     testdstring append $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l\n -1
  218.     }
  219.     list [testdstring gresult staticsmall] [testdstring get]
  220. } {{} short}
  221. test dstring-6.3 {Tcl_DStringGetResult} {
  222.     set result {}
  223.     lappend result [testdstring gresult staticlarge]
  224.     testdstring append x 1
  225.     lappend result [testdstring get]
  226. } {{} {first0 first1 first2 first3 first4 first5 first6 first7 first8 first9
  227. second0 second1 second2 second3 second4 second5 second6 second7 second8 second9
  228. third0 third1 third2 third3 third4 third5 third6 third7 third8 third9
  229. fourth0 fourth1 fourth2 fourth3 fourth4 fourth5 fourth6 fourth7 fourth8 fourth9
  230. fifth0 fifth1 fifth2 fifth3 fifth4 fifth5 fifth6 fifth7 fifth8 fifth9
  231. sixth0 sixth1 sixth2 sixth3 sixth4 sixth5 sixth6 sixth7 sixth8 sixth9
  232. seventh0 seventh1 seventh2 seventh3 seventh4 seventh5 seventh6 seventh7 seventh8 seventh9
  233. x}}
  234. test dstring-6.4 {Tcl_DStringGetResult} {
  235.     set result {}
  236.     lappend result [testdstring gresult free]
  237.     testdstring append y 1
  238.     lappend result [testdstring get]
  239. } {{} {This is a malloc-ed stringy}}
  240. test dstring-6.5 {Tcl_DStringGetResult} {
  241.     set result {}
  242.     lappend result [testdstring gresult special]
  243.     testdstring append z 1
  244.     lappend result [testdstring get]
  245. } {{} {This is a specially-allocated stringz}}
  246.  
  247. testdstring free
  248.