3 # Copyright (C) 2006-2008, The Perl Foundation.
6 # the following lines re-execute this as a tcl script
7 # the \ at the end of these lines makes them a comment in tcl \
8 use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
12 source lib/test_more.tcl
17 {wrong # args: should be "string subcommand ?argument ...?"} {no args}
20 is [string first a abcdefa] 0 {first, initial}
21 is [string first a federala] 5 {first, middle}
22 is [string first c green] -1 {first, failure}
23 is [string first c green 0] -1 {first, index, failure}
24 is [string first c abcdc end-4] 2 {first, index, end}
25 is [string first c abcd 20] -1 {first, index, overshot}
26 is [string first c abcdc 1] 2 {first, index}
28 eval_is {string first c abcd joe} \
29 {bad index "joe": must be integer?[+-]integer? or end?[+-]integer?} \
30 {first, index, invalid index}
32 eval_is {string first} \
33 {wrong # args: should be "string first needleString haystackString ?startIndex?"} \
34 {first, not enough args}
36 eval_is {string first a b c d} \
37 {wrong # args: should be "string first needleString haystackString ?startIndex?"} \
38 {first, too many args}
41 is [string last a abcdefa] 6 {last, initial}
42 is [string last a federala] 7 {last, middle}
43 is [string last c green] -1 {last, failure}
44 is [string last c green 0] -1 {last, index, failure}
45 is [string last c abcdc end-2] 2 {last, index, end}
47 ### Overshot is ignored in this case as the maximum between the string
48 ### of the offset is considered
49 is [string last c abcd 20] 2 {last, index, overshot}
50 is [string last c abcdc 1] -1 {last, index}
52 eval_is {string last c abcdc joe} \
53 {bad index "joe": must be integer?[+-]integer? or end?[+-]integer?} \
54 {last, index, invalid index}
55 eval_is {string last} \
56 {wrong # args: should be "string last needleString haystackString ?startIndex?"}
57 eval_is {string last a b c d} \
58 {wrong # args: should be "string last needleString haystackString ?startIndex?"}
61 is [string index abcde 0] a {index, initial}
62 is [string index abcde end] e {index, end}
63 is [string index abcde 10] {} {index, overshot}
64 is [string index abcde -1] {} {index, undershot, neg.}
65 is [string index abcde end--1] {} {index, overshot, neg.}
66 eval_is {string index abcde 1.2} \
67 {bad index "1.2": must be integer?[+-]integer? or end?[+-]integer?} \
69 eval_is {string index abcde end-1.2} \
70 {bad index "end-1.2": must be integer?[+-]integer? or end?[+-]integer?} \
72 eval_is {string index abcde bogus} \
73 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?} \
75 eval_is {string index abcde end-bogus} \
76 {bad index "end-bogus": must be integer?[+-]integer? or end?[+-]integer?} \
78 eval_is {string index} \
79 {wrong # args: should be "string index string charIndex"} \
80 {string index, no args}
81 eval_is {string index a b c} \
82 {wrong # args: should be "string index string charIndex"} \
83 {string index, too many args}
86 eval_is {string length} \
87 {wrong # args: should be "string length string"} \
88 {length, too few args}
90 eval_is {string length a b} \
91 {wrong # args: should be "string length string"} \
92 {length, too many args}
94 is [string length 10] 2 "length, ascii"
95 is [string length \u6666] 1 "length, unicode"
96 is [string length ""] 0 "length, empty"
99 eval_is {string range} \
100 {wrong # args: should be "string range string first last"} \
101 {range, too few args}
102 eval_is {string range a b c d} \
103 {wrong # args: should be "string range string first last"} \
104 {range, too many args}
106 is [string range abcde 0 end] abcde {range, total}
107 is [string range abcde 1 end-1] bcd {range, partial}
108 is [string range abcde end-20 20] abcde {range, overextended}
109 is [string range abcde end-1 1] {} {range, reversed}
113 is [string match * foo] 1 {string match * only}
114 is [string match a?c abc] 1 {string match ?}
115 is [string match {a[bc]c} abc] 1 {string match charset}
116 is [string match {a[ac]c} abc] 0 {string match charset, fail}
117 is [string match {\*} *] 1 {string match \*}
118 is [string match {\?} ?] 1 {string match \?}
119 is [string match ABC abc] 0 {string match case failure}
120 is [string match {\[} {[}] 1 {string match \[}
121 is [string match {\]} {]}] 1 {string match \]}
124 eval_is {string repeat} \
125 {wrong # args: should be "string repeat string count"} \
127 eval_is {string repeat a} \
128 {wrong # args: should be "string repeat string count"} \
129 {repeat too few args}
130 eval_is {string repeat a b c} \
131 {wrong # args: should be "string repeat string count"} \
132 {repeat too many args}
134 is [string repeat a 5] aaaaa {string repeat: simple}
136 # [string bytelength]
137 eval_is {string bytelength} \
138 {wrong # args: should be "string bytelength string"} \
140 eval_is {string bytelength a b} \
141 {wrong # args: should be "string bytelength string"} \
142 {bytelength too many args}
144 is [string bytelength hi] 2 {bytelength ascii}
145 is [string bytelength \u6666] 3 {bytelength unicode}
146 is [string bytelength \u666] 2 {bytelength unicode 2}
150 eval_is {string equal banana} \
151 {wrong # args: should be "string equal ?-nocase? ?-length int? string1 string2"} \
154 is [string equal oranges apples] 0 {equal, ne}
155 is [string equal oranges orANGes] 0 {equal, ne by case only}
156 is [string equal banana banana] 1 {sting equal, equal}
157 is [string equal -length 5 ferry ferrous] 0 {equal, length, ne}
158 is [string equal -length 4 ferry ferrous] 1 {equal, length, eq}
159 is [string equal -length -1 banana bananarum] 0 {equal, neg length, ne}
160 is [string equal -length -1 banana banana] 1 {equal, neg length, eq}
163 eval_is {string tolower} \
164 {wrong # args: should be "string tolower string ?first? ?last?"} \
165 {tolower, too few args}
167 is [string tolower "AabcD ABC"] {aabcd abc} {tolower, simple}
168 is [string tolower PARROT end-4 4] ParroT {tolower, both limits}
169 is [string tolower PARROT 4] PARRoT {tolower, single index}
170 is [string tolower PARROT 40] PARROT {tolower, single index, out of range}
174 eval_is {string toupper} \
175 {wrong # args: should be "string toupper string ?first? ?last?"} \
176 {toupper, too few args}
178 is [string toupper "AabcD ABC"] {AABCD ABC} {toupper}
179 is [string toupper parrot end-4 4] {pARROt} {toupper, both limits}
180 is [string toupper parrot 4] parrOt {toupper, single index}
181 is [string tolower parrot 40] parrot {toupper, single index out of range}
185 is [string totitle "AabcD ABC"] {Aabcd abc} {totitle}
186 is [string totitle PARROT end-4 4] PArroT {totitle, both limits}
187 is [string totitle parrot 4] parrOt {totitle, single index}
188 is [string totitle PARROT 40] PARROT {totitle, single index, out of string}
190 eval_is {string totitle} \
191 {wrong # args: should be "string totitle string ?first? ?last?"} \
195 is [string replace parrcamelot 4 8] parrot {replace}
196 is [string replace junkparrot -10 3] parrot {replace, negative index}
197 is [string replace parrotjunk 6 20] parrot {replace, index > string len}
198 is [string replace perl 1 3 arrot] parrot {replace with something}
199 is [string replace perl 3 1 arrot] perl {replace, swapped indices}
201 eval_is {string replace} \
202 {wrong # args: should be "string replace string first last ?string?"} \
203 {replace, too few args}
207 is [string trimleft " \nfoo"] foo {trimleft, default}
208 is [string trimleft "abcfaoo" abc] faoo {trimleft, charset}
209 is [string trimleft "abcfaoo" z] abcfaoo {trimleft, charset, nomatch}
211 eval_is {string trimleft} \
212 {wrong # args: should be "string trimleft string ?chars?"} \
213 {trimleft, too few args}
216 is [string trimright " foo "] { foo} {trimright, default}
217 is [string trimright "abcfaoo" ao] abcf {trimright, charset}
218 is [string trimright "abcfaoo" z] abcfaoo {trimright, charset, no match}
220 eval_is {string trimright} \
221 {wrong # args: should be "string trimright string ?chars?"} \
222 {trimleft, too few args}
225 is [string trim " \n foo "] foo {trim, default}
226 is [string trim "ooabacfaoo" ao] bacf {trim, charset}
227 is [string trim "abcfaoo" z] abcfaoo {trim, charset, nomatch}
229 eval_is {string trim} \
230 {wrong # args: should be "string trim string ?chars?"} \
234 is [string compare aaa aaa] 0 {compare, same}
235 is [string compare aaa aab] -1 {compare, "lower" string}
236 is [string compare aab aaa] 1 {compare, "higher" string}
237 is [string compare aaaa aaa] 1 {compare, bigger string}
238 is [string compare aaa aaaa] -1 {compare, smaller string}
239 is [string compare -length 3 aaa aaaa] 0 {compare, different sizes, length}
240 is [string compare -length 4 aaabc aaabb] 0 {compare, diff strings, length}
241 is [string compare -nocase AAA aaa] 0 {compare, -nocase, eq}
242 is [string compare -nocase aaa AAB] -1 {compare, "lower", -nocase}
243 is [string compare -nocase AAB aaa] 1 {compare, "higher", -nocase}
244 is [string compare -nocase AAAA aaa] 1 {compare, bigger string, -nocase}
245 is [string compare -nocase AAA aaaa] -1 {compare, smaller, -nocase}
246 is [string compare -length 3 -nocase aaa AAAA] 0 \
247 {compare, different lengths, -len -nocase}
248 is [string compare -length 4 -nocase AAABC aaabb] 0 \
249 {compare, different strings, len specified, different cases}
250 is [string compare AAAA aaaa] -1 {compare, same string, different case}
251 is [string compare -length -10 aaabc aaabb] 1 {compare, negative length}
253 eval_is {string compare} \
254 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"} \
257 eval_is {string compare -length aaa bbb} \
258 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"} \
259 {compare, bad option to length}
261 eval_is {string compare -length 4 -length 8 aaa bbb} \
262 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"} \
263 {compare multiple lengths}
265 eval_is {string compare -length four aaabc aaabb} \
266 {expected integer but got "four"} \
269 eval_is {string compare -length 4.2 aaabc aaabb} \
270 {expected integer but got "4.2"} \
271 {compare, float length}
274 is [string wordend "foo bar baz" 0] 3 {wordend, from beginning}
276 is [string wordend "foo bar99_baz" 5] 13 {wordend, numerics and underscores}
278 is [string wordend "foo bar" 3] 4 {wordend, space}
280 eval_is {string wordend} \
281 {wrong # args: should be "string wordend string index"} \
282 {wordend too few args}
285 # # RT#40629: - many of the classes are NOT tested here, and we rely
286 # on the cvs tests from tcl for that.
287 is [string is double 2.1] 1 {string is double}
288 is [string is double 7.0] 1 {string is double}
289 is [string is double 7] 1 {string is double}
290 is [string is double 1e1] 1 {string is double}
291 is [string is double .1] 1 {string is double}
292 is [string is double no] 0 {string is double}
293 is [string is double .] 0 {string is double}
294 is [string is double +2.] 1 {string is double}
295 is [string is double -2.] 1 {string is double}
296 is [string is double {}] 1 {empty string always works...}
297 is [string is double -strict {}] 0 {except in strict mode}
298 eval_is {string is double -monkeys uncle} {bad option "-monkeys": must be -strict or -failindex} {bad [string is] option}