Overview
Comment: | OFDictionaryTests: Clean up variable names |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f8d89b56f2695003864d32c3f998a83e |
User & Date: | js on 2017-06-25 17:08:17 |
Other Links: | manifest | tags |
Context
2017-06-25
| ||
17:13 | Add -[OFDictionary stringByURLEncoding] check-in: 2fafde4058 user: js tags: trunk | |
17:08 | OFDictionaryTests: Clean up variable names check-in: f8d89b56f2 user: js tags: trunk | |
16:53 | OFString: Tiny documentation fix check-in: de836a5f2b user: js tags: trunk | |
Changes
Modified tests/OFDictionaryTests.m from [b05d0d80fb] to [37eb73f85e].
︙ | ︙ | |||
158 159 160 161 162 163 164 | @end @implementation TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTestsWithClass: (Class)dictionaryClass mutableClass: (Class)mutableDictionaryClass { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; | | | | | | | | | | | | | | | | | | | | | | | > | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | @end @implementation TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTestsWithClass: (Class)dictionaryClass mutableClass: (Class)mutableDictionaryClass { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableDictionary *mutDict = [mutableDictionaryClass dictionary]; OFDictionary *dict; OFEnumerator *keyEnumerator, *objectEnumerator; OFArray *keysArray, *valuesArray; [mutDict setObject: values[0] forKey: keys[0]]; [mutDict setValue: values[1] forKey: keys[1]]; TEST(@"-[objectForKey:]", [[mutDict objectForKey: keys[0]] isEqual: values[0]] && [[mutDict objectForKey: keys[1]] isEqual: values[1]] && [mutDict objectForKey: @"key3"] == nil) TEST(@"-[valueForKey:]", [[mutDict valueForKey: keys[0]] isEqual: values[0]] && [[mutDict valueForKey: @"@count"] isEqual: [OFNumber numberWithSize: 2]]) EXPECT_EXCEPTION(@"Catching -[setValue:forKey:] on immutable " @"dictionary", OFUndefinedKeyException, [[dictionaryClass dictionary] setValue: @"x" forKey: @"x"]) TEST(@"-[containsObject:]", [mutDict containsObject: values[0]] && ![mutDict containsObject: @"nonexistant"]) TEST(@"-[containsObjectIdenticalTo:]", [mutDict containsObjectIdenticalTo: values[0]] && ![mutDict containsObjectIdenticalTo: [OFString stringWithString: values[0]]]) TEST(@"-[description]", [[mutDict description] isEqual: @"{\n\tkey1 = value1;\n\tkey2 = value2;\n}"]) TEST(@"-[allKeys]", [[mutDict allKeys] isEqual: [OFArray arrayWithObjects: keys[0], keys[1], nil]]) TEST(@"-[allObjects]", [[mutDict allObjects] isEqual: [OFArray arrayWithObjects: values[0], values[1], nil]]) TEST(@"-[keyEnumerator]", (keyEnumerator = [mutDict keyEnumerator])) TEST(@"-[objectEnumerator]", (objectEnumerator = [mutDict objectEnumerator])) TEST(@"OFEnumerator's -[nextObject]", [[keyEnumerator nextObject] isEqual: keys[0]] && [[objectEnumerator nextObject] isEqual: values[0]] && [[keyEnumerator nextObject] isEqual: keys[1]] && [[objectEnumerator nextObject] isEqual: values[1]] && [keyEnumerator nextObject] == nil && [objectEnumerator nextObject] == nil) [keyEnumerator reset]; [mutDict removeObjectForKey: keys[0]]; EXPECT_EXCEPTION(@"Detection of mutation during enumeration", OFEnumerationMutationException, [keyEnumerator nextObject]); [mutDict setObject: values[0] forKey: keys[0]]; size_t i = 0; bool ok = true; for (OFString *key in mutDict) { if (i > 1 || ![key isEqual: keys[i]]) { ok = false; break; } [mutDict setObject: [mutDict objectForKey: key] forKey: key]; i++; } TEST(@"Fast Enumeration", ok) ok = false; @try { for (OFString *key in mutDict) { (void)key; [mutDict setObject: @"" forKey: @""]; } } @catch (OFEnumerationMutationException *e) { ok = true; } TEST(@"Detection of mutation during Fast Enumeration", ok) [mutDict removeObjectForKey: @""]; #ifdef OF_HAVE_BLOCKS { __block size_t i = 0; __block bool ok = true; [mutDict enumerateKeysAndObjectsUsingBlock: ^ (id key, id obj, bool *stop) { if (i > 1 || ![key isEqual: keys[i]]) { ok = false; *stop = true; return; } [mutDict setObject: [mutDict objectForKey: key] forKey: key]; i++; }]; TEST(@"Enumeration using blocks", ok) ok = false; @try { [mutDict enumerateKeysAndObjectsUsingBlock: ^ (id key, id obj, bool *stop) { [mutDict setObject: @"" forKey: @""]; }]; } @catch (OFEnumerationMutationException *e) { ok = true; } TEST(@"Detection of mutation during enumeration using blocks", ok) [mutDict removeObjectForKey: @""]; } TEST(@"-[replaceObjectsUsingBlock:]", R([mutDict replaceObjectsUsingBlock: ^ id (id key, id obj) { if ([key isEqual: keys[0]]) return @"value_1"; if ([key isEqual: keys[1]]) return @"value_2"; return nil; }]) && [[mutDict objectForKey: keys[0]] isEqual: @"value_1"] && [[mutDict objectForKey: keys[1]] isEqual: @"value_2"]) TEST(@"-[mappedDictionaryUsingBlock:]", [[[mutDict mappedDictionaryUsingBlock: ^ id (id key, id obj) { if ([key isEqual: keys[0]]) return @"val1"; if ([key isEqual: keys[1]]) return @"val2"; return nil; }] description] isEqual: @"{\n\tkey1 = val1;\n\tkey2 = val2;\n}"]) TEST(@"-[filteredDictionaryUsingBlock:]", [[[mutDict filteredDictionaryUsingBlock: ^ bool (id key, id obj) { return [key isEqual: keys[0]]; }] description] isEqual: @"{\n\tkey1 = value_1;\n}"]) #endif TEST(@"-[count]", [mutDict count] == 2) TEST(@"+[dictionaryWithKeysAndObjects:]", (dict = [dictionaryClass dictionaryWithKeysAndObjects: @"foo", @"bar", @"baz", @"qux", nil]) && [[dict objectForKey: @"foo"] isEqual: @"bar"] && [[dict objectForKey: @"baz"] isEqual: @"qux"]) TEST(@"+[dictionaryWithObject:forKey:]", (dict = [dictionaryClass dictionaryWithObject: @"bar" forKey: @"foo"]) && [[dict objectForKey: @"foo"] isEqual: @"bar"]) keysArray = [OFArray arrayWithObjects: keys[0], keys[1], nil]; valuesArray = [OFArray arrayWithObjects: values[0], values[1], nil]; TEST(@"+[dictionaryWithObjects:forKeys:]", (dict = [dictionaryClass dictionaryWithObjects: valuesArray forKeys: keysArray]) && [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]]) TEST(@"-[copy]", (dict = [[dict copy] autorelease]) && [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]]) TEST(@"-[mutableCopy]", (mutDict = [[dict mutableCopy] autorelease]) && [mutDict count] == [dict count] && [[mutDict objectForKey: keys[0]] isEqual: values[0]] && [[mutDict objectForKey: keys[1]] isEqual: values[1]] && R([mutDict setObject: @"value3" forKey: @"key3"]) && [[mutDict objectForKey: @"key3"] isEqual: @"value3"] && [[mutDict objectForKey: keys[0]] isEqual: values[0]] && R([mutDict setObject: @"foo" forKey: keys[0]]) && [[mutDict objectForKey: keys[0]] isEqual: @"foo"]) TEST(@"-[removeObjectForKey:]", R([mutDict removeObjectForKey: keys[0]]) && [mutDict objectForKey: keys[0]] == nil) [mutDict setObject: @"foo" forKey: keys[0]]; TEST(@"-[isEqual:]", ![mutDict isEqual: dict] && R([mutDict removeObjectForKey: @"key3"]) && ![mutDict isEqual: dict] && R([mutDict setObject: values[0] forKey: keys[0]]) && [mutDict isEqual: dict]) [pool drain]; } - (void)dictionaryTests { module = @"OFDictionary"; |
︙ | ︙ |