home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / tests / dstring.test < prev    next >
Text File  |  1993-10-11  |  6KB  |  193 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. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/dstring.test,v 1.3 93/10/11 09:06:01 ouster Exp $ (Berkeley)
  28.  
  29. if {[info commands testdstring] == {}} {
  30.     puts "This application hasn't been compiled with the \"testdstring\""
  31.     puts "command, so I can't test Tcl_DStringAppend et al."
  32.     return
  33. }
  34.  
  35. if {[string compare test [info procs test]] == 1} then {source defs}
  36.  
  37. test dstring-1.1 {appending and retrieving} {
  38.     testdstring free
  39.     testdstring append "abc" -1
  40.     list [testdstring get] [testdstring length]
  41. } {abc 3}
  42. test dstring-1.2 {appending and retrieving} {
  43.     testdstring free
  44.     testdstring append "abc" -1
  45.     testdstring append " xyzzy" 3
  46.     testdstring append " 12345" -1
  47.     list [testdstring get] [testdstring length]
  48. } {{abc xy 12345} 12}
  49. test dstring-1.3 {appending and retrieving} {
  50.     testdstring free
  51.     foreach l {a b c d e f g h i j k l m n o p} {
  52.     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
  53.     }
  54.     list [testdstring get] [testdstring length]
  55. } {{aaaaaaaaaaaaaaaaaaaaa
  56. bbbbbbbbbbbbbbbbbbbbb
  57. ccccccccccccccccccccc
  58. ddddddddddddddddddddd
  59. eeeeeeeeeeeeeeeeeeeee
  60. fffffffffffffffffffff
  61. ggggggggggggggggggggg
  62. hhhhhhhhhhhhhhhhhhhhh
  63. iiiiiiiiiiiiiiiiiiiii
  64. jjjjjjjjjjjjjjjjjjjjj
  65. kkkkkkkkkkkkkkkkkkkkk
  66. lllllllllllllllllllll
  67. mmmmmmmmmmmmmmmmmmmmm
  68. nnnnnnnnnnnnnnnnnnnnn
  69. ooooooooooooooooooooo
  70. ppppppppppppppppppppp
  71. } 352}
  72.  
  73. test dstring-2.1 {appending list elements} {
  74.     testdstring free
  75.     testdstring element "abc"
  76.     testdstring element "d e f"
  77.     list [testdstring get] [testdstring length]
  78. } {{abc {d e f}} 11}
  79. test dstring-2.2 {appending list elements} {
  80.     testdstring free
  81.     testdstring element "x"
  82.     testdstring element "\{"
  83.     testdstring element "ab\}"
  84.     testdstring get
  85. } {x \{ ab\}}
  86. test dstring-2.3 {appending list elements} {
  87.     testdstring free
  88.     foreach l {a b c d e f g h i j k l m n o p} {
  89.     testdstring element $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l
  90.     }
  91.     testdstring get
  92. } {aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc ddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeee fffffffffffffffffffff ggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiii jjjjjjjjjjjjjjjjjjjjj kkkkkkkkkkkkkkkkkkkkk lllllllllllllllllllll mmmmmmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnnnnnn ooooooooooooooooooooo ppppppppppppppppppppp}
  93.  
  94. test dstring-3.1 {nested sublists} {
  95.     testdstring free
  96.     testdstring start
  97.     testdstring element foo
  98.     testdstring element bar
  99.     testdstring end
  100.     testdstring element another
  101.     testdstring get
  102. } {{foo bar} another}
  103. test dstring-3.2 {nested sublists} {
  104.     testdstring free
  105.     testdstring start
  106.     testdstring start
  107.     testdstring element abc
  108.     testdstring element def
  109.     testdstring end
  110.     testdstring end
  111.     testdstring element ghi
  112.     testdstring get
  113. } {{{abc def}} ghi}
  114. test dstring-3.3 {nested sublists} {
  115.     testdstring free
  116.     testdstring start
  117.     testdstring start
  118.     testdstring start
  119.     testdstring element foo
  120.     testdstring element foo2
  121.     testdstring end
  122.     testdstring end
  123.     testdstring element foo3
  124.     testdstring end
  125.     testdstring element foo4
  126.     testdstring get
  127. } {{{{foo foo2}} foo3} foo4}
  128. test dstring-3.4 {nested sublists} {
  129.     testdstring free
  130.     testdstring element before
  131.     testdstring start
  132.     testdstring element during
  133.     testdstring element more
  134.     testdstring end
  135.     testdstring element last
  136.     testdstring get
  137. } {before {during more} last}
  138. test dstring-3.4 {nested sublists} {
  139.     testdstring free
  140.     testdstring element "\{"
  141.     testdstring start
  142.     testdstring element first
  143.     testdstring element second
  144.     testdstring end
  145.     testdstring get
  146. } {\{ {first second}}
  147.  
  148. test dstring-4.1 {truncation} {
  149.     testdstring free
  150.     testdstring append "abcdefg" -1
  151.     testdstring trunc 3
  152.     list [testdstring get] [testdstring length]
  153. } {abc 3}
  154. test dstring-4.2 {truncation} {
  155.     testdstring free
  156.     testdstring append "xyzzy" -1
  157.     testdstring trunc 0
  158.     list [testdstring get] [testdstring length]
  159. } {{} 0}
  160.  
  161. test dstring-5.1 {copying to result} {
  162.     testdstring free
  163.     testdstring append xyz -1
  164.     testdstring result
  165. } xyz
  166. test dstring-5.2 {copying to result} {
  167.     testdstring free
  168.     foreach l {a b c d e f g h i j k l m n o p} {
  169.     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
  170.     }
  171.     set a [testdstring result]
  172.     testdstring append abc -1
  173.     list $a [testdstring get]
  174. } {{aaaaaaaaaaaaaaaaaaaaa
  175. bbbbbbbbbbbbbbbbbbbbb
  176. ccccccccccccccccccccc
  177. ddddddddddddddddddddd
  178. eeeeeeeeeeeeeeeeeeeee
  179. fffffffffffffffffffff
  180. ggggggggggggggggggggg
  181. hhhhhhhhhhhhhhhhhhhhh
  182. iiiiiiiiiiiiiiiiiiiii
  183. jjjjjjjjjjjjjjjjjjjjj
  184. kkkkkkkkkkkkkkkkkkkkk
  185. lllllllllllllllllllll
  186. mmmmmmmmmmmmmmmmmmmmm
  187. nnnnnnnnnnnnnnnnnnnnn
  188. ooooooooooooooooooooo
  189. ppppppppppppppppppppp
  190. } abc}
  191.  
  192. testdstring free
  193.