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