diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-05-15 07:44:10 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-05-15 07:44:10 +0000 |
commit | 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 (patch) | |
tree | 32c35f8507edb4ea403f4ebc4b625c1096f6f384 /src/unit/fstring.unit | |
parent | 11413d228bae2919fe69c83b74c7ff49209dd65a (diff) | |
download | libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.gz libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.bz2 libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.xz libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.zip |
mkunit.sh was a little dumb, it didn't handle a number of things correctly.
I've written a new program that basically does the same thing, only it's much
more clever, and does many more of the translations and conversions better,
including the #line directives. Also, I dropped nids, we don't need it anymore.
But now I'm ready to write some serious tests for myriad.
Diffstat (limited to 'src/unit/fstring.unit')
-rw-r--r-- | src/unit/fstring.unit | 550 |
1 files changed, 275 insertions, 275 deletions
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit index 8aaae93..00b6eed 100644 --- a/src/unit/fstring.unit +++ b/src/unit/fstring.unit | |||
@@ -10,333 +10,333 @@ | |||
10 | 10 | ||
11 | #include <dirent.h> | 11 | #include <dirent.h> |
12 | 12 | ||
13 | {=Init} | 13 | suite FString |
14 | |||
15 | {%compare1} | ||
16 | { | 14 | { |
17 | Bu::FString b("Bob"); | 15 | test compare1 |
18 | unitTest( !(b == "Bobo") ); | 16 | { |
19 | unitTest( b == "Bob" ); | 17 | Bu::FString b("Bob"); |
20 | } | 18 | unitTest( !(b == "Bobo") ); |
19 | unitTest( b == "Bob" ); | ||
20 | } | ||
21 | 21 | ||
22 | {%compare2} | 22 | test compare2 |
23 | { | 23 | { |
24 | Bu::FString b("Bobo"); | 24 | Bu::FString b("Bobo"); |
25 | unitTest( !(b == "Bob") ); | 25 | unitTest( !(b == "Bob") ); |
26 | unitTest( b == "Bobo" ); | 26 | unitTest( b == "Bobo" ); |
27 | } | 27 | } |
28 | 28 | ||
29 | {%appendSingle} | 29 | test appendSingle |
30 | { | 30 | { |
31 | Bu::FString b; | 31 | Bu::FString 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 | {%shared1} | 38 | test shared1 |
39 | { | 39 | { |
40 | Bu::FString a("Hey there"); | 40 | Bu::FString a("Hey there"); |
41 | Bu::FString b( a ); | 41 | Bu::FString 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 | {%insert} | 49 | test insert |
50 | { | 50 | { |
51 | Bu::FString a("abcd"); | 51 | Bu::FString 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 | {%remove} | 68 | test remove |
69 | { | 69 | { |
70 | Bu::FString a("abHEYcd"); | 70 | Bu::FString 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 | {%add1} | 80 | test add1 |
81 | { | 81 | { |
82 | Bu::FString a("hi there"); | 82 | Bu::FString a("hi there"); |
83 | Bu::FString b(", yeah!"); | 83 | Bu::FString b(", yeah!"); |
84 | Bu::FString c = a + b; | 84 | Bu::FString c = a + b; |
85 | 85 | ||
86 | unitTest( c == "hi there, yeah!" ); | 86 | unitTest( c == "hi there, yeah!" ); |
87 | } | 87 | } |
88 | 88 | ||
89 | {%add2} | 89 | test add2 |
90 | { | 90 | { |
91 | Bu::FString a("hi there"); | 91 | Bu::FString a("hi there"); |
92 | Bu::FString c = a + ", yeah!"; | 92 | Bu::FString c = a + ", yeah!"; |
93 | 93 | ||
94 | unitTest( c == "hi there, yeah!" ); | 94 | unitTest( c == "hi there, yeah!" ); |
95 | } | 95 | } |
96 | 96 | ||
97 | {%add3} | 97 | test add3 |
98 | { | 98 | { |
99 | Bu::FString a("hi there"); | 99 | Bu::FString a("hi there"); |
100 | Bu::FString b(", yeah!"); | 100 | Bu::FString b(", yeah!"); |
101 | Bu::FString c = a + ", Mr. Man" + b; | 101 | Bu::FString 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 | {%add4} | 106 | test add4 |
107 | { | 107 | { |
108 | Bu::FString b(", yeah!"); | 108 | Bu::FString b(", yeah!"); |
109 | Bu::FString c = "hi there" + b; | 109 | Bu::FString c = "hi there" + b; |
110 | 110 | ||
111 | unitTest( c == "hi there, yeah!" ); | 111 | unitTest( c == "hi there, yeah!" ); |
112 | } | 112 | } |
113 | 113 | ||
114 | {%add5} | 114 | test add5 |
115 | { | 115 | { |
116 | Bu::FString b; | 116 | Bu::FString b; |
117 | Bu::FString c = "sup?"; | 117 | Bu::FString 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 | {%add6} | 123 | test add6 |
124 | { | 124 | { |
125 | Bu::FString a("Hello"); | 125 | Bu::FString a("Hello"); |
126 | char b[256] = {"Dude"}; | 126 | char b[256] = {"Dude"}; |
127 | Bu::FString c = a + "/" + b; | 127 | Bu::FString c = a + "/" + b; |
128 | 128 | ||
129 | unitTest( c == "Hello/Dude" ); | 129 | unitTest( c == "Hello/Dude" ); |
130 | } | 130 | } |
131 | 131 | ||
132 | {%add7} | 132 | test add7 |
133 | { | 133 | { |
134 | const Bu::FString a("hello "); | 134 | const Bu::FString a("hello "); |
135 | Bu::FString b(" how "); | 135 | Bu::FString 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 | {%subStr1} | 141 | test subStr1 |
142 | { | 142 | { |
143 | Bu::FString a("abcdefghijklmnop"); | 143 | Bu::FString a("abcdefghijklmnop"); |
144 | Bu::FString::iterator i = a.find('f'); | 144 | Bu::FString::iterator i = a.find('f'); |
145 | unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" ); | 145 | unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" ); |
146 | Bu::FString::iterator j = i.find('l'); | 146 | Bu::FString::iterator j = i.find('l'); |
147 | unitTest( a.getSubStr( i, j ) == "fghijk" ); | 147 | unitTest( a.getSubStr( i, j ) == "fghijk" ); |
148 | } | 148 | } |
149 | 149 | ||
150 | {%compareSub1} | 150 | test compareSub1 |
151 | { | 151 | { |
152 | Bu::FString a("just a string."); | 152 | Bu::FString 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 | {%compareSub2} | 158 | test compareSub2 |
159 | { | 159 | { |
160 | Bu::FString a("just a string."); | 160 | Bu::FString a("just a string."); |
161 | unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true ); | 161 | unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true ); |
162 | unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false ); | 162 | unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false ); |
163 | unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true ); | 163 | unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true ); |
164 | } | 164 | } |
165 | 165 | ||
166 | {%iterator1} | 166 | test iterator1 |
167 | { | ||
168 | Bu::FString a("This is a test."); | ||
169 | Bu::FString b; | ||
170 | for( Bu::FString::iterator i = a.begin(); i; i++ ) | ||
171 | { | 167 | { |
172 | b += *i; | 168 | Bu::FString a("This is a test."); |
169 | Bu::FString b; | ||
170 | for( Bu::FString::iterator i = a.begin(); i; i++ ) | ||
171 | { | ||
172 | b += *i; | ||
173 | } | ||
174 | unitTest( a == b ); | ||
173 | } | 175 | } |
174 | unitTest( a == b ); | ||
175 | } | ||
176 | 176 | ||
177 | {%iterator2} | 177 | test iterator2 |
178 | { | 178 | { |
179 | Bu::FString a("This is a test."); | 179 | Bu::FString a("This is a test."); |
180 | Bu::FString b("--This is a test."); | 180 | Bu::FString b("--This is a test."); |
181 | Bu::FString::iterator ai = a.begin(); | 181 | Bu::FString::iterator ai = a.begin(); |
182 | Bu::FString::iterator bi = b.begin(); | 182 | Bu::FString::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 | } | 188 | } |
189 | 189 | ||
190 | {%iterator3} | 190 | test iterator3 |
191 | { | 191 | { |
192 | Bu::FString a("1234honour"); | 192 | Bu::FString a("1234honour"); |
193 | Bu::FString b("--1234ueje"); | 193 | Bu::FString b("--1234ueje"); |
194 | Bu::FString::iterator ai = a.begin(); | 194 | Bu::FString::iterator ai = a.begin(); |
195 | Bu::FString::iterator bi = b.begin(); | 195 | Bu::FString::iterator bi = b.begin(); |
196 | unitTest( ai.compare( bi, 4 ) == false ); | 196 | unitTest( ai.compare( bi, 4 ) == false ); |
197 | unitTest( bi.compare( ai, 4 ) == false ); | 197 | unitTest( bi.compare( ai, 4 ) == false ); |
198 | bi++; bi++; | 198 | bi++; bi++; |
199 | unitTest( ai.compare( bi, 4 ) == true ); | 199 | unitTest( ai.compare( bi, 4 ) == true ); |
200 | unitTest( bi.compare( ai, 4 ) == true ); | 200 | unitTest( bi.compare( ai, 4 ) == true ); |
201 | unitTest( ai.compare( bi, 5 ) == false ); | 201 | unitTest( ai.compare( bi, 5 ) == false ); |
202 | unitTest( bi.compare( ai, 5 ) == false ); | 202 | unitTest( bi.compare( ai, 5 ) == false ); |
203 | 203 | ||
204 | } | 204 | } |
205 | 205 | ||
206 | {%iterator4} | 206 | test iterator4 |
207 | { | 207 | { |
208 | Bu::FString a("1234aoeu"); | 208 | Bu::FString a("1234aoeu"); |
209 | Bu::FString::iterator ai = a.begin(); | 209 | Bu::FString::iterator ai = a.begin(); |
210 | unitTest( ai.compare("1234") == false ); | 210 | unitTest( ai.compare("1234") == false ); |
211 | unitTest( ai.compare("1234aoeu") == true ); | 211 | unitTest( ai.compare("1234aoeu") == true ); |
212 | unitTest( ai.compare("1234aoeuee") == false ); | 212 | unitTest( ai.compare("1234aoeuee") == false ); |
213 | } | 213 | } |
214 | 214 | ||
215 | {%iterator5} | 215 | test iterator5 |
216 | { | 216 | { |
217 | Bu::FString a("1234aoeu"); | 217 | Bu::FString a("1234aoeu"); |
218 | Bu::FString::iterator ai = a.begin(); | 218 | Bu::FString::iterator ai = a.begin(); |
219 | unitTest( ai.compare("1234", 4) == true ); | 219 | unitTest( ai.compare("1234", 4) == true ); |
220 | unitTest( ai.compare("1234aoeu", 8) == true ); | 220 | unitTest( ai.compare("1234aoeu", 8) == true ); |
221 | unitTest( ai.compare("1234aoeuee", 10) == false ); | 221 | unitTest( ai.compare("1234aoeuee", 10) == false ); |
222 | } | 222 | } |
223 | 223 | ||
224 | {%iterator6} | 224 | test iterator6 |
225 | { | ||
226 | Bu::FString a("just ->this part"); | ||
227 | Bu::FString b; | ||
228 | Bu::FString::iterator s = a.begin(); | ||
229 | for(; s; s++ ) | ||
230 | { | 225 | { |
231 | if( *s == '>' ) | 226 | Bu::FString a("just ->this part"); |
227 | Bu::FString b; | ||
228 | Bu::FString::iterator s = a.begin(); | ||
229 | for(; s; s++ ) | ||
232 | { | 230 | { |
233 | s++; | 231 | if( *s == '>' ) |
234 | b.set( s ); | 232 | { |
235 | break; | 233 | s++; |
234 | b.set( s ); | ||
235 | break; | ||
236 | } | ||
236 | } | 237 | } |
237 | } | 238 | unitTest( b == "this part" ); |
238 | unitTest( b == "this part" ); | ||
239 | 239 | ||
240 | b.append( s ); | 240 | b.append( s ); |
241 | 241 | ||
242 | Bu::FString c; | 242 | Bu::FString c; |
243 | c.set( b.begin() ); | 243 | c.set( b.begin() ); |
244 | 244 | ||
245 | // This is here because the comparison operator used to cause flattening. | 245 | // This is here because the comparison operator used to cause flattening. |
246 | unitTest( b == "this partthis part" ); | 246 | unitTest( b == "this partthis part" ); |
247 | unitTest( c == b ); | 247 | unitTest( c == b ); |
248 | } | 248 | } |
249 | 249 | ||
250 | {%iterator7} | 250 | test iterator7 |
251 | { | ||
252 | Bu::FString a("just [this] part"); | ||
253 | Bu::FString b; | ||
254 | Bu::FString::iterator s = a.begin(); | ||
255 | for(; s; s++ ) | ||
256 | { | 251 | { |
257 | if( *s == '[' ) | 252 | Bu::FString a("just [this] part"); |
253 | Bu::FString b; | ||
254 | Bu::FString::iterator s = a.begin(); | ||
255 | for(; s; s++ ) | ||
258 | { | 256 | { |
259 | s++; | 257 | if( *s == '[' ) |
260 | break; | 258 | { |
259 | s++; | ||
260 | break; | ||
261 | } | ||
261 | } | 262 | } |
262 | } | 263 | Bu::FString::iterator e = s; |
263 | Bu::FString::iterator e = s; | 264 | for(; e; e++ ) |
264 | for(; e; e++ ) | ||
265 | { | ||
266 | if( *e == ']' ) | ||
267 | { | 265 | { |
268 | b.set( s, e ); | 266 | if( *e == ']' ) |
269 | break; | 267 | { |
268 | b.set( s, e ); | ||
269 | break; | ||
270 | } | ||
270 | } | 271 | } |
271 | } | 272 | unitTest( b == "this" ); |
272 | unitTest( b == "this" ); | ||
273 | 273 | ||
274 | b.append( s, e ); | 274 | b.append( s, e ); |
275 | 275 | ||
276 | for( Bu::FString::iterator i = b.begin(); i;) | 276 | for( Bu::FString::iterator i = b.begin(); i;) |
277 | { | ||
278 | Bu::FString::iterator k = i; | ||
279 | k++; | ||
280 | if( !k ) | ||
281 | { | 277 | { |
282 | b.append( b.begin(), i ); | 278 | Bu::FString::iterator k = i; |
283 | break; | 279 | k++; |
280 | if( !k ) | ||
281 | { | ||
282 | b.append( b.begin(), i ); | ||
283 | break; | ||
284 | } | ||
285 | i = k; | ||
284 | } | 286 | } |
285 | i = k; | 287 | Bu::FString l; |
286 | } | 288 | l.set( b.begin() ); |
287 | Bu::FString l; | 289 | unitTest( l == "thisthisthisthi" ); |
288 | l.set( b.begin() ); | 290 | for( Bu::FString::iterator i = b.begin(); i;) |
289 | unitTest( l == "thisthisthisthi" ); | ||
290 | for( Bu::FString::iterator i = b.begin(); i;) | ||
291 | { | ||
292 | Bu::FString::iterator k = i; | ||
293 | k++; | ||
294 | if( !k ) | ||
295 | { | 291 | { |
296 | b.append( b.begin(), i ); | 292 | Bu::FString::iterator k = i; |
297 | break; | 293 | k++; |
294 | if( !k ) | ||
295 | { | ||
296 | b.append( b.begin(), i ); | ||
297 | break; | ||
298 | } | ||
299 | i = k; | ||
298 | } | 300 | } |
299 | i = k; | 301 | l.set( b.begin() ); |
302 | unitTest( l == "thisthisthisthithisthisthisth" ); | ||
300 | } | 303 | } |
301 | l.set( b.begin() ); | ||
302 | unitTest( l == "thisthisthisthithisthisthisth" ); | ||
303 | } | ||
304 | 304 | ||
305 | {%isSet1} | 305 | test isSet1 |
306 | { | 306 | { |
307 | Bu::FString bob; | 307 | Bu::FString bob; |
308 | 308 | ||
309 | unitTest( bob.isSet() == false ); | 309 | unitTest( bob.isSet() == false ); |
310 | bob = "something"; | 310 | bob = "something"; |
311 | unitTest( bob.isSet() == true ); | 311 | unitTest( bob.isSet() == true ); |
312 | bob = ""; | 312 | bob = ""; |
313 | unitTest( bob.isSet() == false ); | 313 | unitTest( bob.isSet() == false ); |
314 | } | 314 | } |
315 | 315 | ||
316 | {%swap1} | 316 | test swap1 |
317 | { | 317 | { |
318 | Bu::FString a, b; | 318 | Bu::FString a, b; |
319 | a = "Goodbye"; | 319 | a = "Goodbye"; |
320 | b = "Hello"; | 320 | b = "Hello"; |
321 | Bu::swap( a, b ); | 321 | Bu::swap( a, b ); |
322 | unitTest( a == "Hello" ); | 322 | unitTest( a == "Hello" ); |
323 | unitTest( b == "Goodbye" ); | 323 | unitTest( b == "Goodbye" ); |
324 | } | 324 | } |
325 | 325 | ||
326 | {%swap2} | 326 | test swap2 |
327 | { | 327 | { |
328 | Bu::FString a, b; | 328 | Bu::FString a, b; |
329 | a = "Goodbye"; | 329 | a = "Goodbye"; |
330 | b = "Hello"; | 330 | b = "Hello"; |
331 | std::swap( a, b ); | 331 | std::swap( a, b ); |
332 | unitTest( a == "Hello" ); | 332 | unitTest( a == "Hello" ); |
333 | unitTest( b == "Goodbye" ); | 333 | unitTest( b == "Goodbye" ); |
334 | } | 334 | } |
335 | 335 | ||
336 | {%replace1} | 336 | test replace1 |
337 | { | 337 | { |
338 | Bu::FString a; | 338 | Bu::FString a; |
339 | a = "This is a test."; | 339 | a = "This is a test."; |
340 | unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); | 340 | unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); |
341 | } | ||
341 | } | 342 | } |
342 | |||