aboutsummaryrefslogtreecommitdiff
path: root/src/unit/string.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/unit/string.unit
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/unit/string.unit')
-rw-r--r--src/unit/string.unit1148
1 files changed, 574 insertions, 574 deletions
diff --git a/src/unit/string.unit b/src/unit/string.unit
index 4ea878e..ddd89a6 100644
--- a/src/unit/string.unit
+++ b/src/unit/string.unit
@@ -12,580 +12,580 @@
12 12
13suite String 13suite String
14{ 14{
15 test compare1 15 test compare1
16 { 16 {
17 Bu::String b("Bob"); 17 Bu::String b("Bob");
18 unitTest( !(b == "Bobo") ); 18 unitTest( !(b == "Bobo") );
19 unitTest( b == "Bob" ); 19 unitTest( b == "Bob" );
20 } 20 }
21 21
22 test compare2 22 test compare2
23 { 23 {
24 Bu::String b("Bobo"); 24 Bu::String b("Bobo");
25 unitTest( !(b == "Bob") ); 25 unitTest( !(b == "Bob") );
26 unitTest( b == "Bobo" ); 26 unitTest( b == "Bobo" );
27 } 27 }
28 28
29 test appendSingle 29 test appendSingle
30 { 30 {
31 Bu::String b; 31 Bu::String b;
32 for( char l = 'a'; l < 'g'; l++ ) 32 for( char l = 'a'; l < 'g'; l++ )
33 b += l; 33 b += l;
34 unitTest( b == "abcdef" ); 34 unitTest( b == "abcdef" );
35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); 35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 );
36 } 36 }
37 37
38 test shared1 38 test shared1
39 { 39 {
40 Bu::String a("Hey there"); 40 Bu::String a("Hey there");
41 Bu::String b( a ); 41 Bu::String b( a );
42 unitTest( a.getConstStr() == b.getConstStr() ); 42 unitTest( a.getConstStr() == b.getConstStr() );
43 b += " guy"; 43 b += " guy";
44 unitTest( a.getConstStr() != b.getConstStr() ); 44 unitTest( a.getConstStr() != b.getConstStr() );
45 a = b; 45 a = b;
46 unitTest( a.getConstStr() == b.getConstStr() ); 46 unitTest( a.getConstStr() == b.getConstStr() );
47 } 47 }
48 48
49 test insert 49 test insert
50 { 50 {
51 Bu::String a("abcd"); 51 Bu::String a("abcd");
52 a.insert( 2, "-!-", 3 ); 52 a.insert( 2, "-!-", 3 );
53 unitTest( a == "ab-!-cd" ); 53 unitTest( a == "ab-!-cd" );
54 54
55 a.insert( 0, "!!", 2 ); 55 a.insert( 0, "!!", 2 );
56 unitTest( a == "!!ab-!-cd" ); 56 unitTest( a == "!!ab-!-cd" );
57 57
58 a.insert( -10, "789", 3 ); 58 a.insert( -10, "789", 3 );
59 unitTest( a == "789!!ab-!-cd" ); 59 unitTest( a == "789!!ab-!-cd" );
60 60
61 a.insert( 12, "89", 2 ); 61 a.insert( 12, "89", 2 );
62 unitTest( a == "789!!ab-!-cd89" ); 62 unitTest( a == "789!!ab-!-cd89" );
63 63
64 a.insert( 1203, "12", 2 ); 64 a.insert( 1203, "12", 2 );
65 unitTest( a == "789!!ab-!-cd8912" ); 65 unitTest( a == "789!!ab-!-cd8912" );
66 } 66 }
67 67
68 test remove 68 test remove
69 { 69 {
70 Bu::String a("abHEYcd"); 70 Bu::String a("abHEYcd");
71 a.remove( 2, 3 ); 71 a.remove( 2, 3 );
72 unitTest( a == "abcd" ); 72 unitTest( a == "abcd" );
73 a.remove( 2, 5 ); 73 a.remove( 2, 5 );
74 unitTest( a == "ab" ); 74 unitTest( a == "ab" );
75 a += "cdefghijklmnop"; 75 a += "cdefghijklmnop";
76 a.remove( 5, 1 ); 76 a.remove( 5, 1 );
77 unitTest( a == "abcdeghijklmnop" ); 77 unitTest( a == "abcdeghijklmnop" );
78 } 78 }
79 79
80 test add1 80 test add1
81 { 81 {
82 Bu::String a("hi there"); 82 Bu::String a("hi there");
83 Bu::String b(", yeah!"); 83 Bu::String b(", yeah!");
84 Bu::String c = a + b; 84 Bu::String c = a + b;
85 85
86 unitTest( c == "hi there, yeah!" ); 86 unitTest( c == "hi there, yeah!" );
87 } 87 }
88 88
89 test add2 89 test add2
90 { 90 {
91 Bu::String a("hi there"); 91 Bu::String a("hi there");
92 Bu::String c = a + ", yeah!"; 92 Bu::String c = a + ", yeah!";
93 93
94 unitTest( c == "hi there, yeah!" ); 94 unitTest( c == "hi there, yeah!" );
95 } 95 }
96 96
97 test add3 97 test add3
98 { 98 {
99 Bu::String a("hi there"); 99 Bu::String a("hi there");
100 Bu::String b(", yeah!"); 100 Bu::String b(", yeah!");
101 Bu::String c = a + ", Mr. Man" + b; 101 Bu::String c = a + ", Mr. Man" + b;
102 102
103 unitTest( c == "hi there, Mr. Man, yeah!" ); 103 unitTest( c == "hi there, Mr. Man, yeah!" );
104 } 104 }
105 105
106 test add4 106 test add4
107 { 107 {
108 Bu::String b(", yeah!"); 108 Bu::String b(", yeah!");
109 Bu::String c = "hi there" + b; 109 Bu::String c = "hi there" + b;
110 110
111 unitTest( c == "hi there, yeah!" ); 111 unitTest( c == "hi there, yeah!" );
112 } 112 }
113 113
114 test add5 114 test add5
115 { 115 {
116 Bu::String b; 116 Bu::String b;
117 Bu::String c = "sup?"; 117 Bu::String c = "sup?";
118 b += "hey, " + c; 118 b += "hey, " + c;
119 119
120 unitTest( b == "hey, sup?" ); 120 unitTest( b == "hey, sup?" );
121 } 121 }
122 122
123 test add6 123 test add6
124 { 124 {
125 Bu::String a("Hello"); 125 Bu::String a("Hello");
126 char b[256] = {"Dude"}; 126 char b[256] = {"Dude"};
127 Bu::String c = a + "/" + b; 127 Bu::String c = a + "/" + b;
128 128
129 unitTest( c == "Hello/Dude" ); 129 unitTest( c == "Hello/Dude" );
130 } 130 }
131 131
132 test add7 132 test add7
133 { 133 {
134 const Bu::String a("hello "); 134 const Bu::String a("hello ");
135 Bu::String b(" how "); 135 Bu::String b(" how ");
136 unitTest( a == "hello " ); 136 unitTest( a == "hello " );
137 unitTest( a + "dude" == "hello dude" ); 137 unitTest( a + "dude" == "hello dude" );
138 unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" ); 138 unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" );
139 } 139 }
140 140
141 test subStr1 141 test subStr1
142 { 142 {
143 Bu::String a("abcdefghijklmnop"); 143 Bu::String a("abcdefghijklmnop");
144 Bu::String::iterator i = a.find('f'); 144 Bu::String::iterator i = a.find('f');
145 unitTest( a.getSubStr( i, Bu::String::iterator() ) == "fghijklmnop" ); 145 unitTest( a.getSubStr( i, Bu::String::iterator() ) == "fghijklmnop" );
146 Bu::String::iterator j = i.find('l'); 146 Bu::String::iterator j = i.find('l');
147 unitTest( a.getSubStr( i, j ) == "fghijk" ); 147 unitTest( a.getSubStr( i, j ) == "fghijk" );
148 } 148 }
149 149
150 test compareSub1 150 test compareSub1
151 { 151 {
152 Bu::String a("just a string."); 152 Bu::String a("just a string.");
153 unitTest( a.compareSub("a ", 5, 2) == true ); 153 unitTest( a.compareSub("a ", 5, 2) == true );
154 unitTest( a.compareSub("string.aoeu", 7, 11 ) == false ); 154 unitTest( a.compareSub("string.aoeu", 7, 11 ) == false );
155 unitTest( a.compareSub("string.aoeu", 7, 3 ) == true ); 155 unitTest( a.compareSub("string.aoeu", 7, 3 ) == true );
156 } 156 }
157 157
158 test compareSub2 158 test compareSub2
159 { 159 {
160 Bu::String a("just a string."); 160 Bu::String a("just a string.");
161 unitTest( a.compareSub(Bu::String("a "), 5, 2) == true ); 161 unitTest( a.compareSub(Bu::String("a "), 5, 2) == true );
162 unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 11 ) == false ); 162 unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 11 ) == false );
163 unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 3 ) == true ); 163 unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 3 ) == true );
164 } 164 }
165 165
166 test iterator1 166 test iterator1
167 { 167 {
168 Bu::String a("This is a test."); 168 Bu::String a("This is a test.");
169 Bu::String b; 169 Bu::String b;
170 for( Bu::String::iterator i = a.begin(); i; i++ ) 170 for( Bu::String::iterator i = a.begin(); i; i++ )
171 { 171 {
172 b += *i; 172 b += *i;
173 } 173 }
174 unitTest( a == b ); 174 unitTest( a == b );
175 } 175 }
176 176
177 test iteratorCompare1 177 test iteratorCompare1
178 { 178 {
179 Bu::String a("This is a test."); 179 Bu::String a("This is a test.");
180 Bu::String b("--This is a test."); 180 Bu::String b("--This is a test.");
181 Bu::String::iterator ai = a.begin(); 181 Bu::String::iterator ai = a.begin();
182 Bu::String::iterator bi = b.begin(); 182 Bu::String::iterator bi = b.begin();
183 unitTest( ai.compare( bi ) == false ); 183 unitTest( ai.compare( bi ) == false );
184 unitTest( bi.compare( ai ) == false ); 184 unitTest( bi.compare( ai ) == false );
185 bi++; bi++; 185 bi++; bi++;
186 unitTest( ai.compare( bi ) == true ); 186 unitTest( ai.compare( bi ) == true );
187 unitTest( bi.compare( ai ) == true ); 187 unitTest( bi.compare( ai ) == true );
188 b += "hi"; 188 b += "hi";
189 unitTest( ai.compare( bi ) == false ); 189 unitTest( ai.compare( bi ) == false );
190 unitTest( bi.compare( ai ) == false ); 190 unitTest( bi.compare( ai ) == false );
191 } 191 }
192 192
193 test iteratorCompare2 193 test iteratorCompare2
194 { 194 {
195 Bu::String a("1234honour"); 195 Bu::String a("1234honour");
196 Bu::String b("--1234ueje"); 196 Bu::String b("--1234ueje");
197 Bu::String::iterator ai = a.begin(); 197 Bu::String::iterator ai = a.begin();
198 Bu::String::iterator bi = b.begin(); 198 Bu::String::iterator bi = b.begin();
199 unitTest( ai.compare( bi, 4 ) == false ); 199 unitTest( ai.compare( bi, 4 ) == false );
200 unitTest( bi.compare( ai, 4 ) == false ); 200 unitTest( bi.compare( ai, 4 ) == false );
201 bi++; bi++; 201 bi++; bi++;
202 unitTest( ai.compare( bi, 4 ) == true ); 202 unitTest( ai.compare( bi, 4 ) == true );
203 unitTest( bi.compare( ai, 4 ) == true ); 203 unitTest( bi.compare( ai, 4 ) == true );
204 unitTest( ai.compare( bi, 5 ) == false ); 204 unitTest( ai.compare( bi, 5 ) == false );
205 unitTest( bi.compare( ai, 5 ) == false ); 205 unitTest( bi.compare( ai, 5 ) == false );
206 206
207 a = "fell"; 207 a = "fell";
208 b = "-felloo"; 208 b = "-felloo";
209 ai = a.begin(); 209 ai = a.begin();
210 bi = b.begin()+1; 210 bi = b.begin()+1;
211 unitTest( ai.compare( bi, 4 ) == true ); 211 unitTest( ai.compare( bi, 4 ) == true );
212 ai++; 212 ai++;
213 bi++; 213 bi++;
214 unitTest( ai.compare( bi, 4 ) == false ); 214 unitTest( ai.compare( bi, 4 ) == false );
215 } 215 }
216 216
217 test iteratorCompare3 217 test iteratorCompare3
218 { 218 {
219 Bu::String a("1234aoeu"); 219 Bu::String a("1234aoeu");
220 Bu::String::iterator ai = a.begin(); 220 Bu::String::iterator ai = a.begin();
221 unitTest( ai.compare("1234") == false ); 221 unitTest( ai.compare("1234") == false );
222 unitTest( ai.compare("1234aoeu") == true ); 222 unitTest( ai.compare("1234aoeu") == true );
223 unitTest( ai.compare("1234aoeuee") == false ); 223 unitTest( ai.compare("1234aoeuee") == false );
224 ai += 4; 224 ai += 4;
225 unitTest( ai.compare("aoeu") == true ); 225 unitTest( ai.compare("aoeu") == true );
226 unitTest( ai.compare("aoeubo") == false ); 226 unitTest( ai.compare("aoeubo") == false );
227 unitTest( ai.compare("aoe") == false ); 227 unitTest( ai.compare("aoe") == false );
228 unitTest( ai.compare("wrong") == false ); 228 unitTest( ai.compare("wrong") == false );
229 unitTest( ai.compare("boeu") == false ); 229 unitTest( ai.compare("boeu") == false );
230 } 230 }
231 231
232 test iteratorCompare4 232 test iteratorCompare4
233 { 233 {
234 Bu::String a("1234aoeu"); 234 Bu::String a("1234aoeu");
235 Bu::String::iterator ai = a.begin(); 235 Bu::String::iterator ai = a.begin();
236 unitTest( ai.compare("1234", 4) == true ); 236 unitTest( ai.compare("1234", 4) == true );
237 unitTest( ai.compare("1234aoeu", 8) == true ); 237 unitTest( ai.compare("1234aoeu", 8) == true );
238 unitTest( ai.compare("1234aoeuee", 10) == false ); 238 unitTest( ai.compare("1234aoeuee", 10) == false );
239 } 239 }
240 240
241 test iteratorCompare5 241 test iteratorCompare5
242 { 242 {
243 Bu::String a("1234aoeu"); 243 Bu::String a("1234aoeu");
244 Bu::String b("34ao"); 244 Bu::String b("34ao");
245 Bu::String::iterator ai = a.begin(); 245 Bu::String::iterator ai = a.begin();
246 unitTest( ai.compare( b ) == false ); 246 unitTest( ai.compare( b ) == false );
247 ai += 2; 247 ai += 2;
248 unitTest( ai.compare( b ) == false ); 248 unitTest( ai.compare( b ) == false );
249 b = "oeu"; 249 b = "oeu";
250 ai += 3; 250 ai += 3;
251 unitTest( ai.compare( b ) == true ); 251 unitTest( ai.compare( b ) == true );
252 b += "boo"; 252 b += "boo";
253 unitTest( ai.compare( b ) == false ); 253 unitTest( ai.compare( b ) == false );
254 } 254 }
255 255
256 test iteratorCompare6 256 test iteratorCompare6
257 { 257 {
258 Bu::String a("1234aoeu"); 258 Bu::String a("1234aoeu");
259 Bu::String::iterator ai = a.begin(); 259 Bu::String::iterator ai = a.begin();
260 unitTest( ai.compare( Bu::String("1234"), 4) == true ); 260 unitTest( ai.compare( Bu::String("1234"), 4) == true );
261 unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); 261 unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true );
262 unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); 262 unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false );
263 } 263 }
264 264
265 test const_iteratorCompare1 265 test const_iteratorCompare1
266 { 266 {
267 Bu::String a("This is a test."); 267 Bu::String a("This is a test.");
268 Bu::String b("--This is a test."); 268 Bu::String b("--This is a test.");
269 Bu::String::const_iterator ai = a.begin(); 269 Bu::String::const_iterator ai = a.begin();
270 Bu::String::const_iterator bi = b.begin(); 270 Bu::String::const_iterator bi = b.begin();
271 unitTest( ai.compare( bi ) == false ); 271 unitTest( ai.compare( bi ) == false );
272 unitTest( bi.compare( ai ) == false ); 272 unitTest( bi.compare( ai ) == false );
273 bi++; bi++; 273 bi++; bi++;
274 unitTest( ai.compare( bi ) == true ); 274 unitTest( ai.compare( bi ) == true );
275 unitTest( bi.compare( ai ) == true ); 275 unitTest( bi.compare( ai ) == true );
276 b += "hi"; 276 b += "hi";
277 unitTest( ai.compare( bi ) == false ); 277 unitTest( ai.compare( bi ) == false );
278 unitTest( bi.compare( ai ) == false ); 278 unitTest( bi.compare( ai ) == false );
279 } 279 }
280 280
281 test const_iteratorCompare2 281 test const_iteratorCompare2
282 { 282 {
283 Bu::String a("1234honour"); 283 Bu::String a("1234honour");
284 Bu::String b("--1234ueje"); 284 Bu::String b("--1234ueje");
285 Bu::String::const_iterator ai = a.begin(); 285 Bu::String::const_iterator ai = a.begin();
286 Bu::String::const_iterator bi = b.begin(); 286 Bu::String::const_iterator bi = b.begin();
287 unitTest( ai.compare( bi, 4 ) == false ); 287 unitTest( ai.compare( bi, 4 ) == false );
288 unitTest( bi.compare( ai, 4 ) == false ); 288 unitTest( bi.compare( ai, 4 ) == false );
289 bi++; bi++; 289 bi++; bi++;
290 unitTest( ai.compare( bi, 4 ) == true ); 290 unitTest( ai.compare( bi, 4 ) == true );
291 unitTest( bi.compare( ai, 4 ) == true ); 291 unitTest( bi.compare( ai, 4 ) == true );
292 unitTest( ai.compare( bi, 5 ) == false ); 292 unitTest( ai.compare( bi, 5 ) == false );
293 unitTest( bi.compare( ai, 5 ) == false ); 293 unitTest( bi.compare( ai, 5 ) == false );
294 294
295 a = "fell"; 295 a = "fell";
296 b = "-felloo"; 296 b = "-felloo";
297 ai = a.begin(); 297 ai = a.begin();
298 bi = b.begin()+1; 298 bi = b.begin()+1;
299 unitTest( ai.compare( bi, 4 ) == true ); 299 unitTest( ai.compare( bi, 4 ) == true );
300 ai++; 300 ai++;
301 bi++; 301 bi++;
302 unitTest( ai.compare( bi, 4 ) == false ); 302 unitTest( ai.compare( bi, 4 ) == false );
303 } 303 }
304 304
305 test const_iteratorCompare3 305 test const_iteratorCompare3
306 { 306 {
307 Bu::String a("1234aoeu"); 307 Bu::String a("1234aoeu");
308 Bu::String::const_iterator ai = a.begin(); 308 Bu::String::const_iterator ai = a.begin();
309 unitTest( ai.compare("1234") == false ); 309 unitTest( ai.compare("1234") == false );
310 unitTest( ai.compare("1234aoeu") == true ); 310 unitTest( ai.compare("1234aoeu") == true );
311 unitTest( ai.compare("1234aoeuee") == false ); 311 unitTest( ai.compare("1234aoeuee") == false );
312 ai += 4; 312 ai += 4;
313 unitTest( ai.compare("aoeu") == true ); 313 unitTest( ai.compare("aoeu") == true );
314 unitTest( ai.compare("aoeubo") == false ); 314 unitTest( ai.compare("aoeubo") == false );
315 unitTest( ai.compare("aoe") == false ); 315 unitTest( ai.compare("aoe") == false );
316 unitTest( ai.compare("wrong") == false ); 316 unitTest( ai.compare("wrong") == false );
317 unitTest( ai.compare("boeu") == false ); 317 unitTest( ai.compare("boeu") == false );
318 } 318 }
319 319
320 test const_iteratorCompare4 320 test const_iteratorCompare4
321 { 321 {
322 Bu::String a("1234aoeu"); 322 Bu::String a("1234aoeu");
323 Bu::String::const_iterator ai = a.begin(); 323 Bu::String::const_iterator ai = a.begin();
324 unitTest( ai.compare("1234", 4) == true ); 324 unitTest( ai.compare("1234", 4) == true );
325 unitTest( ai.compare("1234aoeu", 8) == true ); 325 unitTest( ai.compare("1234aoeu", 8) == true );
326 unitTest( ai.compare("1234aoeuee", 10) == false ); 326 unitTest( ai.compare("1234aoeuee", 10) == false );
327 } 327 }
328 328
329 test const_iteratorCompare5 329 test const_iteratorCompare5
330 { 330 {
331 Bu::String a("1234aoeu"); 331 Bu::String a("1234aoeu");
332 Bu::String b("34ao"); 332 Bu::String b("34ao");
333 Bu::String::const_iterator ai = a.begin(); 333 Bu::String::const_iterator ai = a.begin();
334 unitTest( ai.compare( b ) == false ); 334 unitTest( ai.compare( b ) == false );
335 ai += 2; 335 ai += 2;
336 unitTest( ai.compare( b ) == false ); 336 unitTest( ai.compare( b ) == false );
337 b = "oeu"; 337 b = "oeu";
338 ai += 3; 338 ai += 3;
339 unitTest( ai.compare( b ) == true ); 339 unitTest( ai.compare( b ) == true );
340 b += "boo"; 340 b += "boo";
341 unitTest( ai.compare( b ) == false ); 341 unitTest( ai.compare( b ) == false );
342 } 342 }
343 343
344 test const_iteratorCompare6 344 test const_iteratorCompare6
345 { 345 {
346 Bu::String a("1234aoeu"); 346 Bu::String a("1234aoeu");
347 Bu::String::const_iterator ai = a.begin(); 347 Bu::String::const_iterator ai = a.begin();
348 unitTest( ai.compare( Bu::String("1234"), 4) == true ); 348 unitTest( ai.compare( Bu::String("1234"), 4) == true );
349 unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); 349 unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true );
350 unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); 350 unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false );
351 } 351 }
352 352
353 test iteratorAppend1 353 test iteratorAppend1
354 { 354 {
355 Bu::String a("just ->this part"); 355 Bu::String a("just ->this part");
356 Bu::String b; 356 Bu::String b;
357 Bu::String::iterator s = a.begin(); 357 Bu::String::iterator s = a.begin();
358 for(; s; s++ ) 358 for(; s; s++ )
359 { 359 {
360 if( *s == '>' ) 360 if( *s == '>' )
361 { 361 {
362 s++; 362 s++;
363 b.set( s ); 363 b.set( s );
364 break; 364 break;
365 } 365 }
366 } 366 }
367 unitTest( b == "this part" ); 367 unitTest( b == "this part" );
368 368
369 b.append( s ); 369 b.append( s );
370 370
371 Bu::String c; 371 Bu::String c;
372 c.set( b.begin() ); 372 c.set( b.begin() );
373 373
374 // This is here because the comparison operator used to cause flattening. 374 // This is here because the comparison operator used to cause flattening.
375 unitTest( b == "this partthis part" ); 375 unitTest( b == "this partthis part" );
376 unitTest( c == b ); 376 unitTest( c == b );
377 } 377 }
378 378
379 test iteratorAppend2 379 test iteratorAppend2
380 { 380 {
381 Bu::String a("just [this] part"); 381 Bu::String a("just [this] part");
382 Bu::String b; 382 Bu::String b;
383 Bu::String::iterator s = a.begin(); 383 Bu::String::iterator s = a.begin();
384 for(; s; s++ ) 384 for(; s; s++ )
385 { 385 {
386 if( *s == '[' ) 386 if( *s == '[' )
387 { 387 {
388 s++; 388 s++;
389 break; 389 break;
390 } 390 }
391 } 391 }
392 Bu::String::iterator e = s; 392 Bu::String::iterator e = s;
393 for(; e; e++ ) 393 for(; e; e++ )
394 { 394 {
395 if( *e == ']' ) 395 if( *e == ']' )
396 { 396 {
397 b.set( s, e ); 397 b.set( s, e );
398 break; 398 break;
399 } 399 }
400 } 400 }
401 unitTest( b == "this" ); 401 unitTest( b == "this" );
402 402
403 b.append( s, e ); 403 b.append( s, e );
404 404
405 for( Bu::String::iterator i = b.begin(); i;) 405 for( Bu::String::iterator i = b.begin(); i;)
406 { 406 {
407 Bu::String::iterator k = i; 407 Bu::String::iterator k = i;
408 k++; 408 k++;
409 if( !k ) 409 if( !k )
410 { 410 {
411 b.append( b.begin(), i ); 411 b.append( b.begin(), i );
412 break; 412 break;
413 } 413 }
414 i = k; 414 i = k;
415 } 415 }
416 Bu::String l; 416 Bu::String l;
417 l.set( b.begin() ); 417 l.set( b.begin() );
418 unitTest( l == "thisthisthisthi" ); 418 unitTest( l == "thisthisthisthi" );
419 for( Bu::String::iterator i = b.begin(); i;) 419 for( Bu::String::iterator i = b.begin(); i;)
420 { 420 {
421 Bu::String::iterator k = i; 421 Bu::String::iterator k = i;
422 k++; 422 k++;
423 if( !k ) 423 if( !k )
424 { 424 {
425 b.append( b.begin(), i ); 425 b.append( b.begin(), i );
426 break; 426 break;
427 } 427 }
428 i = k; 428 i = k;
429 } 429 }
430 l.set( b.begin() ); 430 l.set( b.begin() );
431 unitTest( l == "thisthisthisthithisthisthisth" ); 431 unitTest( l == "thisthisthisthithisthisthisth" );
432 } 432 }
433 433
434 test isSet1 434 test isSet1
435 { 435 {
436 Bu::String bob; 436 Bu::String bob;
437 437
438 unitTest( bob.isSet() == false ); 438 unitTest( bob.isSet() == false );
439 bob = "something"; 439 bob = "something";
440 unitTest( bob.isSet() == true ); 440 unitTest( bob.isSet() == true );
441 bob = ""; 441 bob = "";
442 unitTest( bob.isSet() == false ); 442 unitTest( bob.isSet() == false );
443 } 443 }
444 444
445 test swap1 445 test swap1
446 { 446 {
447 Bu::String a, b; 447 Bu::String a, b;
448 a = "Goodbye"; 448 a = "Goodbye";
449 b = "Hello"; 449 b = "Hello";
450 Bu::swap( a, b ); 450 Bu::swap( a, b );
451 unitTest( a == "Hello" ); 451 unitTest( a == "Hello" );
452 unitTest( b == "Goodbye" ); 452 unitTest( b == "Goodbye" );
453 } 453 }
454 454
455 test swap2 455 test swap2
456 { 456 {
457 Bu::String a, b; 457 Bu::String a, b;
458 a = "Goodbye"; 458 a = "Goodbye";
459 b = "Hello"; 459 b = "Hello";
460 std::swap( a, b ); 460 std::swap( a, b );
461 unitTest( a == "Hello" ); 461 unitTest( a == "Hello" );
462 unitTest( b == "Goodbye" ); 462 unitTest( b == "Goodbye" );
463 } 463 }
464 464
465 test replace1 465 test replace1
466 { 466 {
467 Bu::String a; 467 Bu::String a;
468 a = "This is a test."; 468 a = "This is a test.";
469 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); 469 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." );
470 } 470 }
471 471
472 test replace2 472 test replace2
473 { 473 {
474 Bu::String a; 474 Bu::String a;
475 a = "aaaboostuffb"; 475 a = "aaaboostuffb";
476 unitTest( a.replace("boo", "/") == "aaa/stuffb" ); 476 unitTest( a.replace("boo", "/") == "aaa/stuffb" );
477 } 477 }
478 478
479 test coreDerefBug1 479 test coreDerefBug1
480 { 480 {
481 Bu::String a, b; 481 Bu::String a, b;
482 a = "bob"; 482 a = "bob";
483 a.setSize( 0 ); 483 a.setSize( 0 );
484 b = a; 484 b = a;
485 b.getStr(); 485 b.getStr();
486 } 486 }
487 487
488 test padding1 488 test padding1
489 { 489 {
490 Bu::String a; 490 Bu::String a;
491 a.append('a'); 491 a.append('a');
492 a.append('b'); 492 a.append('b');
493 a.append('c'); 493 a.append('c');
494 a.append("hello"); 494 a.append("hello");
495 a.clear(); 495 a.clear();
496 } 496 }
497 497
498 test padding2 498 test padding2
499 { 499 {
500 Bu::String src("It's all sorts of things"); 500 Bu::String src("It's all sorts of things");
501 Bu::String::const_iterator i = src.find('a'); 501 Bu::String::const_iterator i = src.find('a');
502 Bu::String::const_iterator j = src.find('f'); 502 Bu::String::const_iterator j = src.find('f');
503 Bu::String a, b; 503 Bu::String a, b;
504 a.append( i ); 504 a.append( i );
505 i += 2; 505 i += 2;
506 a.append( i, j ); 506 a.append( i, j );
507 a.append('a'); 507 a.append('a');
508 a.append('b'); 508 a.append('b');
509 a.append('c'); 509 a.append('c');
510 a.append("hello"); 510 a.append("hello");
511 a.append( src ); 511 a.append( src );
512 b = a; 512 b = a;
513 a.clear(); 513 a.clear();
514 } 514 }
515 515
516 test append 516 test append
517 { 517 {
518 // This is the byte sequence that caused += to die 518 // This is the byte sequence that caused += to die
519 // 03 F0 9C A4 F5 8A C8 CA 0E 519 // 03 F0 9C A4 F5 8A C8 CA 0E
520 uint8_t b; 520 uint8_t b;
521 Bu::String m1; 521 Bu::String m1;
522 b = 0x03; m1 += (char)b; 522 b = 0x03; m1 += (char)b;
523 b = 0xF0; m1 += (char)b; 523 b = 0xF0; m1 += (char)b;
524 b = 0x9C; m1 += (char)b; 524 b = 0x9C; m1 += (char)b;
525 b = 0xA4; m1 += (char)b; 525 b = 0xA4; m1 += (char)b;
526 b = 0xF5; m1 += (char)b; 526 b = 0xF5; m1 += (char)b;
527 b = 0x8A; m1 += (char)b; 527 b = 0x8A; m1 += (char)b;
528 b = 0xC8; m1 += (char)b; 528 b = 0xC8; m1 += (char)b;
529 b = 0xCA; m1 += (char)b; 529 b = 0xCA; m1 += (char)b;
530 b = 0x0E; m1 += (char)b; 530 b = 0x0E; m1 += (char)b;
531 531
532 Bu::String m2; 532 Bu::String m2;
533 b = 0x03; m2.append( (const char *)&b, 1 ); 533 b = 0x03; m2.append( (const char *)&b, 1 );
534 b = 0xF0; m2.append( (const char *)&b, 1 ); 534 b = 0xF0; m2.append( (const char *)&b, 1 );
535 b = 0x9C; m2.append( (const char *)&b, 1 ); 535 b = 0x9C; m2.append( (const char *)&b, 1 );
536 b = 0xA4; m2.append( (const char *)&b, 1 ); 536 b = 0xA4; m2.append( (const char *)&b, 1 );
537 b = 0xF5; m2.append( (const char *)&b, 1 ); 537 b = 0xF5; m2.append( (const char *)&b, 1 );
538 b = 0x8A; m2.append( (const char *)&b, 1 ); 538 b = 0x8A; m2.append( (const char *)&b, 1 );
539 b = 0xC8; m2.append( (const char *)&b, 1 ); 539 b = 0xC8; m2.append( (const char *)&b, 1 );
540 b = 0xCA; m2.append( (const char *)&b, 1 ); 540 b = 0xCA; m2.append( (const char *)&b, 1 );
541 b = 0x0E; m2.append( (const char *)&b, 1 ); 541 b = 0x0E; m2.append( (const char *)&b, 1 );
542 542
543 unitTest( m1 == m2 ); 543 unitTest( m1 == m2 );
544 unitTest( m1 == "\x03\xF0\x9C\xA4\xF5\x8A\xC8\xCA\x0E" ); 544 unitTest( m1 == "\x03\xF0\x9C\xA4\xF5\x8A\xC8\xCA\x0E" );
545 } 545 }
546 546
547 test toUpper1 547 test toUpper1
548 { 548 {
549 Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); 549 Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?");
550 unitTest( s1.toUpper() == "HELLO THERE, HOW ARE YOU DOING?" ); 550 unitTest( s1.toUpper() == "HELLO THERE, HOW ARE YOU DOING?" );
551 unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); 551 unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" );
552 } 552 }
553 553
554 test toLower1 554 test toLower1
555 { 555 {
556 Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); 556 Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?");
557 unitTest( s1.toLower() == "hello there, how are you doing?" ); 557 unitTest( s1.toLower() == "hello there, how are you doing?" );
558 unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); 558 unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" );
559 } 559 }
560 560
561 test trimWhitespace1 561 test trimWhitespace1
562 { 562 {
563 unitTest( Bu::String("Hello there").trimWhitespace() 563 unitTest( Bu::String("Hello there").trimWhitespace()
564 == "Hello there" ); 564 == "Hello there" );
565 unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace() 565 unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace()
566 == "Hello there" ); 566 == "Hello there" );
567 unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace() 567 unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace()
568 == "Hello there" ); 568 == "Hello there" );
569 unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace() 569 unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace()
570 == "Hello there" ); 570 == "Hello there" );
571 unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" ); 571 unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" );
572 unitTest( Bu::String().trimWhitespace() == "" ); 572 unitTest( Bu::String().trimWhitespace() == "" );
573 unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace() 573 unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace()
574 == "Hello \t\t\r\nthere" ); 574 == "Hello \t\t\r\nthere" );
575 } 575 }
576 576
577 test format1 577 test format1
578 { 578 {
579 unitTest( (Bu::String)Bu::String("%1").arg( 12, Bu::Fmt().width(3) ) == " 12" ); 579 unitTest( (Bu::String)Bu::String("%1").arg( 12, Bu::Fmt().width(3) ) == " 12" );
580 unitTest( (Bu::String)Bu::String("%1 %2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ +4" ); 580 unitTest( (Bu::String)Bu::String("%1 %2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ +4" );
581 unitTest( (Bu::String)Bu::String("%1%2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ+4" ); 581 unitTest( (Bu::String)Bu::String("%1%2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ+4" );
582 unitTest( (Bu::String)Bu::String("Sup #%1-Guy!").arg( 1 ) == "Sup #1-Guy!" ); 582 unitTest( (Bu::String)Bu::String("Sup #%1-Guy!").arg( 1 ) == "Sup #1-Guy!" );
583 } 583 }
584 584
585 test format2 585 test format2
586 { 586 {
587 unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4B00" ); 587 unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4B00" );
588 } 588 }
589} 589}
590// 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3 590// 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3
591// 591//