summaryrefslogtreecommitdiff
path: root/src/unit/fstring.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-02-08 00:44:10 +0000
committerMike Buland <eichlan@xagasoft.com>2009-02-08 00:44:10 +0000
commit366a8063730aa7ae696bcb9cf56eafd13d43dfc0 (patch)
tree42e3597edfde0c183506ad0d452f045cb7726137 /src/unit/fstring.unit
parent4f59dec6bad120b72f1bc075715d79bfbe881f7e (diff)
downloadlibbu++-366a8063730aa7ae696bcb9cf56eafd13d43dfc0.tar.gz
libbu++-366a8063730aa7ae696bcb9cf56eafd13d43dfc0.tar.bz2
libbu++-366a8063730aa7ae696bcb9cf56eafd13d43dfc0.tar.xz
libbu++-366a8063730aa7ae696bcb9cf56eafd13d43dfc0.zip
So many updates. I recommend using the new FString iterators instead of direct
indexing. It is now many times faster, and requires less overhead. Also, more stuff iterator related in every class. More on that later.
Diffstat (limited to 'src/unit/fstring.unit')
-rw-r--r--src/unit/fstring.unit155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit
index 3912de2..a0d62da 100644
--- a/src/unit/fstring.unit
+++ b/src/unit/fstring.unit
@@ -138,3 +138,158 @@
138 unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); 138 unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" );
139 unitTest( a.getSubStr( -15, 4 ) == "abcd" ); 139 unitTest( a.getSubStr( -15, 4 ) == "abcd" );
140} 140}
141
142{%compareSub1}
143{
144 Bu::FString a("just a string.");
145 unitTest( a.compareSub("a ", 5, 2) == true );
146 unitTest( a.compareSub("string.aoeu", 7, 11 ) == false );
147 unitTest( a.compareSub("string.aoeu", 7, 3 ) == true );
148}
149
150{%compareSub2}
151{
152 Bu::FString a("just a string.");
153 unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true );
154 unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false );
155 unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true );
156}
157
158{%iterator1}
159{
160 Bu::FString a("This is a test.");
161 Bu::FString b;
162 for( Bu::FString::iterator i = a.begin(); i; i++ )
163 {
164 b += *i;
165 }
166 unitTest( a == b );
167}
168
169{%iterator2}
170{
171 Bu::FString a("This is a test.");
172 Bu::FString b("--This is a test.");
173 Bu::FString::iterator ai = a.begin();
174 Bu::FString::iterator bi = b.begin();
175 unitTest( ai.compare( bi ) == false );
176 unitTest( bi.compare( ai ) == false );
177 bi++; bi++;
178 unitTest( ai.compare( bi ) == true );
179 unitTest( bi.compare( ai ) == true );
180}
181
182{%iterator3}
183{
184 Bu::FString a("1234honour");
185 Bu::FString b("--1234ueje");
186 Bu::FString::iterator ai = a.begin();
187 Bu::FString::iterator bi = b.begin();
188 unitTest( ai.compare( bi, 4 ) == false );
189 unitTest( bi.compare( ai, 4 ) == false );
190 bi++; bi++;
191 unitTest( ai.compare( bi, 4 ) == true );
192 unitTest( bi.compare( ai, 4 ) == true );
193 unitTest( ai.compare( bi, 5 ) == false );
194 unitTest( bi.compare( ai, 5 ) == false );
195
196}
197
198{%iterator4}
199{
200 Bu::FString a("1234aoeu");
201 Bu::FString::iterator ai = a.begin();
202 unitTest( ai.compare("1234") == false );
203 unitTest( ai.compare("1234aoeu") == true );
204 unitTest( ai.compare("1234aoeuee") == false );
205}
206
207{%iterator5}
208{
209 Bu::FString a("1234aoeu");
210 Bu::FString::iterator ai = a.begin();
211 unitTest( ai.compare("1234", 4) == true );
212 unitTest( ai.compare("1234aoeu", 8) == true );
213 unitTest( ai.compare("1234aoeuee", 10) == false );
214}
215
216{%iterator6}
217{
218 Bu::FString a("just ->this part");
219 Bu::FString b;
220 Bu::FString::iterator s = a.begin();
221 for(; s; s++ )
222 {
223 if( *s == '>' )
224 {
225 s++;
226 b.set( s );
227 break;
228 }
229 }
230 unitTest( b == "this part" );
231
232 b.append( s );
233
234 Bu::FString c;
235 c.set( b.begin() );
236
237 // This is here because the comparison operator used to cause flattening.
238 unitTest( b == "this partthis part" );
239 unitTest( c == b );
240}
241
242{%iterator7}
243{
244 Bu::FString a("just [this] part");
245 Bu::FString b;
246 Bu::FString::iterator s = a.begin();
247 for(; s; s++ )
248 {
249 if( *s == '[' )
250 {
251 s++;
252 break;
253 }
254 }
255 Bu::FString::iterator e = s;
256 for(; e; e++ )
257 {
258 if( *e == ']' )
259 {
260 b.set( s, e );
261 break;
262 }
263 }
264 unitTest( b == "this" );
265
266 b.append( s, e );
267
268 for( Bu::FString::iterator i = b.begin(); i;)
269 {
270 Bu::FString::iterator k = i;
271 k++;
272 if( !k )
273 {
274 b.append( b.begin(), i );
275 break;
276 }
277 i = k;
278 }
279 Bu::FString l;
280 l.set( b.begin() );
281 unitTest( l == "thisthisthisthi" );
282 for( Bu::FString::iterator i = b.begin(); i;)
283 {
284 Bu::FString::iterator k = i;
285 k++;
286 if( !k )
287 {
288 b.append( b.begin(), i );
289 break;
290 }
291 i = k;
292 }
293 l.set( b.begin() );
294 unitTest( l == "thisthisthisthithisthisthisth" );
295}