Differences From Artifact [d070876349]:
- File
tests/OFArrayTests.m
— part of check-in
[dc0c6c34ab]
at
2019-02-17 22:44:23
on branch trunk
— tests: Only import ObjFW.h
This prevents forgetting to add an import to ObjFW.h, as the tests would
then not compile. (user: js, size: 11954) [annotate] [blame] [check-ins using]
To Artifact [e635773d52]:
- File tests/OFArrayTests.m — part of check-in [b045cbb9c7] at 2019-03-25 00:21:30 on branch trunk — tests: Use dot syntax (user: js, size: 11920) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
149 150 151 152 153 154 155 | TEST(@"+[arrayWithObjects:count:]", (a[1] = [arrayClass arrayWithObjects: c_ary count: 3]) && [a[1] isEqual: a[0]]) TEST(@"-[description]", | | | < | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | TEST(@"+[arrayWithObjects:count:]", (a[1] = [arrayClass arrayWithObjects: c_ary count: 3]) && [a[1] isEqual: a[0]]) TEST(@"-[description]", [a[0].description isEqual: @"(\n\tFoo,\n\tBar,\n\tBaz\n)"]) TEST(@"-[addObject:]", R([m[0] addObject: c_ary[0]]) && R([m[0] addObject: c_ary[2]])) TEST(@"-[insertObject:atIndex:]", R([m[0] insertObject: c_ary[1] atIndex: 1])) TEST(@"-[count]", m[0].count == 3 && a[0].count == 3 && a[1].count == 3) TEST(@"-[isEqual:]", [m[0] isEqual: a[0]] && [a[0] isEqual: a[1]]) TEST(@"-[objectAtIndex:]", [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[1]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]] && |
︙ | ︙ | |||
213 214 215 216 217 218 219 | R([m[0] replaceObjectAtIndex: 0 withObject: c_ary[0]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[removeObject:]", | | | | | | 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 | R([m[0] replaceObjectAtIndex: 0 withObject: c_ary[0]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[removeObject:]", R([m[0] removeObject: c_ary[0]]) && m[0].count == 2) TEST(@"-[removeObjectIdenticalTo:]", R([m[0] removeObjectIdenticalTo: c_ary[2]]) && m[0].count == 1) m[1] = [[a[0] mutableCopy] autorelease]; TEST(@"-[removeObjectAtIndex:]", R([m[1] removeObjectAtIndex: 1]) && m[1].count == 2 && [[m[1] objectAtIndex: 1] isEqual: c_ary[2]]) m[1] = [[a[0] mutableCopy] autorelease]; TEST(@"-[removeObjectsInRange:]", R([m[1] removeObjectsInRange: of_range(0, 2)]) && m[1].count == 1 && [[m[1] objectAtIndex: 0] isEqual: c_ary[2]]) m[1] = [[a[0] mutableCopy] autorelease]; [m[1] addObject: @"qux"]; [m[1] addObject: @"last"]; TEST(@"-[reverse]", R([m[1] reverse]) && [m[1] isEqual: [arrayClass arrayWithObjects: @"last", @"qux", @"Baz", @"Bar", @"Foo", nil]]) |
︙ | ︙ | |||
253 254 255 256 257 258 259 | @"0", @"Bar", @"Baz", @"Foo", @"z", nil]] && [[m[1] sortedArrayUsingSelector: @selector(compare:) options: OF_ARRAY_SORT_DESCENDING] isEqual: [arrayClass arrayWithObjects: @"z", @"Foo", @"Baz", @"Bar", @"0", nil]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", | | | | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | @"0", @"Bar", @"Baz", @"Foo", @"z", nil]] && [[m[1] sortedArrayUsingSelector: @selector(compare:) options: OF_ARRAY_SORT_DESCENDING] isEqual: [arrayClass arrayWithObjects: @"z", @"Foo", @"Baz", @"Bar", @"0", nil]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [a[0] objectAtIndex: a[0].count]) EXPECT_EXCEPTION(@"Detect out of range in -[removeObjectsInRange:]", OFOutOfRangeException, [m[0] removeObjectsInRange: of_range(0, m[0].count + 1)]) TEST(@"-[componentsJoinedByString:]", (a[1] = [arrayClass arrayWithObjects: @"", @"a", @"b", @"c", nil]) && [[a[1] componentsJoinedByString: @" "] isEqual: @" a b c"] && (a[1] = [arrayClass arrayWithObject: @"foo"]) && [[a[1] componentsJoinedByString: @" "] isEqual: @"foo"]) |
︙ | ︙ | |||
286 287 288 289 290 291 292 | if (![obj isEqual: c_ary[i]]) ok = false; [m[0] replaceObjectAtIndex: i withObject: @""]; i++; } | | | 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | if (![obj isEqual: c_ary[i]]) ok = false; [m[0] replaceObjectAtIndex: i withObject: @""]; i++; } if (m[0].count != i) ok = false; TEST(@"OFEnumerator's -[nextObject]", ok) [enumerator reset]; [m[0] removeObjectAtIndex: 0]; |
︙ | ︙ | |||
309 310 311 312 313 314 315 | if (![s isEqual: c_ary[i]]) ok = false; [m[0] replaceObjectAtIndex: i withObject: @""]; i++; } | | | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | if (![s isEqual: c_ary[i]]) ok = false; [m[0] replaceObjectAtIndex: i withObject: @""]; i++; } if (m[0].count != i) ok = false; TEST(@"Fast Enumeration", ok) [m[0] replaceObjectAtIndex: 0 withObject: c_ary[0]]; [m[0] replaceObjectAtIndex: 1 |
︙ | ︙ | |||
355 356 357 358 359 360 361 | [m[0] enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { count++; if (![object isEqual: [cmp objectAtIndex: idx]]) blockOk = false; }]; | | | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | [m[0] enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { count++; if (![object isEqual: [cmp objectAtIndex: idx]]) blockOk = false; }]; if (count != cmp.count) blockOk = false; TEST(@"Enumeration using blocks", blockOk) blockOk = false; a2 = m[0]; @try { |
︙ | ︙ | |||
390 391 392 393 394 395 396 | case 0: return @"foo"; case 1: return @"bar"; } return nil; | | | | | | | 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | case 0: return @"foo"; case 1: return @"bar"; } return nil; }]) && [m[0].description isEqual: @"(\n\tfoo,\n\tbar\n)"]) TEST(@"-[mappedArrayUsingBlock:]", [[m[0] mappedArrayUsingBlock: ^ id (id object, size_t idx) { switch (idx) { case 0: return @"foobar"; case 1: return @"qux"; } return nil; }].description isEqual: @"(\n\tfoobar,\n\tqux\n)"]) TEST(@"-[filteredArrayUsingBlock:]", [[m[0] filteredArrayUsingBlock: ^ bool (id object, size_t idx) { return [object isEqual: @"foo"]; }].description isEqual: @"(\n\tfoo\n)"]) TEST(@"-[foldUsingBlock:]", [[arrayClass arrayWithObjects: [OFMutableString string], @"foo", @"bar", @"baz", nil] foldUsingBlock: ^ id (id left, id right) { [left appendString: right]; return left; }]) |
︙ | ︙ |