sl@0: # Commands covered: none sl@0: # sl@0: # This file contains a collection of tests for Tcl's dynamic string sl@0: # library procedures. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1993 The Regents of the University of California. sl@0: # Copyright (c) 1994 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: dstring.test,v 1.5 2000/04/10 17:18:58 ericm Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: if {[info commands testdstring] == {}} { sl@0: puts "This application hasn't been compiled with the \"testdstring\"" sl@0: puts "command, so I can't test Tcl_DStringAppend et al." sl@0: ::tcltest::cleanupTests sl@0: return sl@0: } sl@0: sl@0: test dstring-1.1 {appending and retrieving} { sl@0: testdstring free sl@0: testdstring append "abc" -1 sl@0: list [testdstring get] [testdstring length] sl@0: } {abc 3} sl@0: test dstring-1.2 {appending and retrieving} { sl@0: testdstring free sl@0: testdstring append "abc" -1 sl@0: testdstring append " xyzzy" 3 sl@0: testdstring append " 12345" -1 sl@0: list [testdstring get] [testdstring length] sl@0: } {{abc xy 12345} 12} sl@0: test dstring-1.3 {appending and retrieving} { sl@0: testdstring free sl@0: foreach l {a b c d e f g h i j k l m n o p} { sl@0: 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 sl@0: } sl@0: list [testdstring get] [testdstring length] sl@0: } {{aaaaaaaaaaaaaaaaaaaaa sl@0: bbbbbbbbbbbbbbbbbbbbb sl@0: ccccccccccccccccccccc sl@0: ddddddddddddddddddddd sl@0: eeeeeeeeeeeeeeeeeeeee sl@0: fffffffffffffffffffff sl@0: ggggggggggggggggggggg sl@0: hhhhhhhhhhhhhhhhhhhhh sl@0: iiiiiiiiiiiiiiiiiiiii sl@0: jjjjjjjjjjjjjjjjjjjjj sl@0: kkkkkkkkkkkkkkkkkkkkk sl@0: lllllllllllllllllllll sl@0: mmmmmmmmmmmmmmmmmmmmm sl@0: nnnnnnnnnnnnnnnnnnnnn sl@0: ooooooooooooooooooooo sl@0: ppppppppppppppppppppp sl@0: } 352} sl@0: sl@0: test dstring-2.1 {appending list elements} { sl@0: testdstring free sl@0: testdstring element "abc" sl@0: testdstring element "d e f" sl@0: list [testdstring get] [testdstring length] sl@0: } {{abc {d e f}} 11} sl@0: test dstring-2.2 {appending list elements} { sl@0: testdstring free sl@0: testdstring element "x" sl@0: testdstring element "\{" sl@0: testdstring element "ab\}" sl@0: testdstring get sl@0: } {x \{ ab\}} sl@0: test dstring-2.3 {appending list elements} { sl@0: testdstring free sl@0: foreach l {a b c d e f g h i j k l m n o p} { sl@0: testdstring element $l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l$l sl@0: } sl@0: testdstring get sl@0: } {aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc ddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeee fffffffffffffffffffff ggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiii jjjjjjjjjjjjjjjjjjjjj kkkkkkkkkkkkkkkkkkkkk lllllllllllllllllllll mmmmmmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnnnnnn ooooooooooooooooooooo ppppppppppppppppppppp} sl@0: test dstring-2.4 {appending list elements} { sl@0: testdstring free sl@0: testdstring append "a\{" -1 sl@0: testdstring element abc sl@0: testdstring append " \{" -1 sl@0: testdstring element xyzzy sl@0: testdstring get sl@0: } "a{ abc {xyzzy" sl@0: test dstring-2.5 {appending list elements} { sl@0: testdstring free sl@0: testdstring append " \{" -1 sl@0: testdstring element abc sl@0: testdstring get sl@0: } " {abc" sl@0: test dstring-2.6 {appending list elements} { sl@0: testdstring free sl@0: testdstring append " " -1 sl@0: testdstring element abc sl@0: testdstring get sl@0: } { abc} sl@0: test dstring-2.7 {appending list elements} { sl@0: testdstring free sl@0: testdstring append "\\ " -1 sl@0: testdstring element abc sl@0: testdstring get sl@0: } "\\ abc" sl@0: test dstring-2.8 {appending list elements} { sl@0: testdstring free sl@0: testdstring append "x " -1 sl@0: testdstring element abc sl@0: testdstring get sl@0: } {x abc} sl@0: sl@0: test dstring-3.1 {nested sublists} { sl@0: testdstring free sl@0: testdstring start sl@0: testdstring element foo sl@0: testdstring element bar sl@0: testdstring end sl@0: testdstring element another sl@0: testdstring get sl@0: } {{foo bar} another} sl@0: test dstring-3.2 {nested sublists} { sl@0: testdstring free sl@0: testdstring start sl@0: testdstring start sl@0: testdstring element abc sl@0: testdstring element def sl@0: testdstring end sl@0: testdstring end sl@0: testdstring element ghi sl@0: testdstring get sl@0: } {{{abc def}} ghi} sl@0: test dstring-3.3 {nested sublists} { sl@0: testdstring free sl@0: testdstring start sl@0: testdstring start sl@0: testdstring start sl@0: testdstring element foo sl@0: testdstring element foo2 sl@0: testdstring end sl@0: testdstring end sl@0: testdstring element foo3 sl@0: testdstring end sl@0: testdstring element foo4 sl@0: testdstring get sl@0: } {{{{foo foo2}} foo3} foo4} sl@0: test dstring-3.4 {nested sublists} { sl@0: testdstring free sl@0: testdstring element before sl@0: testdstring start sl@0: testdstring element during sl@0: testdstring element more sl@0: testdstring end sl@0: testdstring element last sl@0: testdstring get sl@0: } {before {during more} last} sl@0: test dstring-3.5 {nested sublists} { sl@0: testdstring free sl@0: testdstring element "\{" sl@0: testdstring start sl@0: testdstring element first sl@0: testdstring element second sl@0: testdstring end sl@0: testdstring get sl@0: } {\{ {first second}} sl@0: sl@0: test dstring-4.1 {truncation} { sl@0: testdstring free sl@0: testdstring append "abcdefg" -1 sl@0: testdstring trunc 3 sl@0: list [testdstring get] [testdstring length] sl@0: } {abc 3} sl@0: test dstring-4.2 {truncation} { sl@0: testdstring free sl@0: testdstring append "xyzzy" -1 sl@0: testdstring trunc 0 sl@0: list [testdstring get] [testdstring length] sl@0: } {{} 0} sl@0: sl@0: test dstring-5.1 {copying to result} { sl@0: testdstring free sl@0: testdstring append xyz -1 sl@0: testdstring result sl@0: } xyz sl@0: test dstring-5.2 {copying to result} { sl@0: testdstring free sl@0: catch {unset a} sl@0: foreach l {a b c d e f g h i j k l m n o p} { sl@0: 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 sl@0: } sl@0: set a [testdstring result] sl@0: testdstring append abc -1 sl@0: list $a [testdstring get] sl@0: } {{aaaaaaaaaaaaaaaaaaaaa sl@0: bbbbbbbbbbbbbbbbbbbbb sl@0: ccccccccccccccccccccc sl@0: ddddddddddddddddddddd sl@0: eeeeeeeeeeeeeeeeeeeee sl@0: fffffffffffffffffffff sl@0: ggggggggggggggggggggg sl@0: hhhhhhhhhhhhhhhhhhhhh sl@0: iiiiiiiiiiiiiiiiiiiii sl@0: jjjjjjjjjjjjjjjjjjjjj sl@0: kkkkkkkkkkkkkkkkkkkkk sl@0: lllllllllllllllllllll sl@0: mmmmmmmmmmmmmmmmmmmmm sl@0: nnnnnnnnnnnnnnnnnnnnn sl@0: ooooooooooooooooooooo sl@0: ppppppppppppppppppppp sl@0: } abc} sl@0: sl@0: test dstring-6.1 {Tcl_DStringGetResult} { sl@0: testdstring free sl@0: list [testdstring gresult staticsmall] [testdstring get] sl@0: } {{} short} sl@0: test dstring-6.2 {Tcl_DStringGetResult} { sl@0: testdstring free sl@0: foreach l {a b c d e f g h i j k l m n o p} { sl@0: 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 sl@0: } sl@0: list [testdstring gresult staticsmall] [testdstring get] sl@0: } {{} short} sl@0: test dstring-6.3 {Tcl_DStringGetResult} { sl@0: set result {} sl@0: lappend result [testdstring gresult staticlarge] sl@0: testdstring append x 1 sl@0: lappend result [testdstring get] sl@0: } {{} {first0 first1 first2 first3 first4 first5 first6 first7 first8 first9 sl@0: second0 second1 second2 second3 second4 second5 second6 second7 second8 second9 sl@0: third0 third1 third2 third3 third4 third5 third6 third7 third8 third9 sl@0: fourth0 fourth1 fourth2 fourth3 fourth4 fourth5 fourth6 fourth7 fourth8 fourth9 sl@0: fifth0 fifth1 fifth2 fifth3 fifth4 fifth5 fifth6 fifth7 fifth8 fifth9 sl@0: sixth0 sixth1 sixth2 sixth3 sixth4 sixth5 sixth6 sixth7 sixth8 sixth9 sl@0: seventh0 seventh1 seventh2 seventh3 seventh4 seventh5 seventh6 seventh7 seventh8 seventh9 sl@0: x}} sl@0: test dstring-6.4 {Tcl_DStringGetResult} { sl@0: set result {} sl@0: lappend result [testdstring gresult free] sl@0: testdstring append y 1 sl@0: lappend result [testdstring get] sl@0: } {{} {This is a malloc-ed stringy}} sl@0: test dstring-6.5 {Tcl_DStringGetResult} { sl@0: set result {} sl@0: lappend result [testdstring gresult special] sl@0: testdstring append z 1 sl@0: lappend result [testdstring get] sl@0: } {{} {This is a specially-allocated stringz}} sl@0: sl@0: # cleanup sl@0: testdstring free sl@0: ::tcltest::cleanupTests sl@0: return sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: