Differences From Artifact [650205073d]:
- File
tests/OFArrayTests.m
— part of check-in
[25c985fec1]
at
2020-08-25 00:11:24
on branch trunk
— OFNumber: Remove (u)int{8,16,32,64} methods
Since C guarantees minimum sizes for char, short, int, long and long
long, these can be used instead. (user: js, size: 11896) [annotate] [blame] [check-ins using] [more...]
To Artifact [578f78bc93]:
- File tests/OFArrayTests.m — part of check-in [1b82d3bf4f] at 2021-03-07 20:25:21 on branch trunk — *.m: Fold methods into one line where it fits (user: js, size: 11716) [annotate] [blame] [check-ins using] [more...]
1 | /* | < < | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * |
︙ | ︙ | |||
49 50 51 52 53 54 55 | [self release]; @throw e; } return self; } | | < | < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)object arguments: (va_list)arguments { self = [super init]; @try { _array = [[OFMutableArray alloc] initWithObject: object arguments: arguments]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _array = [[OFMutableArray alloc] initWithObjects: objects count: count]; } @catch (id e) { |
︙ | ︙ | |||
106 107 108 109 110 111 112 | @implementation SimpleMutableArray + (void)initialize { if (self == [SimpleMutableArray class]) [self inheritMethodsFromClass: [SimpleArray class]]; } | | < | < | < | < | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | @implementation SimpleMutableArray + (void)initialize { if (self == [SimpleMutableArray class]) [self inheritMethodsFromClass: [SimpleArray class]]; } - (void)insertObject: (id)object atIndex: (size_t)idx { [_array insertObject: object atIndex: idx]; } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { [_array replaceObjectAtIndex: idx withObject: object]; } - (void)removeObjectAtIndex: (size_t)idx { [_array removeObjectAtIndex: idx]; } @end |
︙ | ︙ | |||
144 145 146 147 148 149 150 | TEST(@"+[array]", (m[0] = [mutableArrayClass array])) TEST(@"+[arrayWithObjects:]", (a[0] = [arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil])) TEST(@"+[arrayWithObjects:count:]", | | < | | | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | TEST(@"+[array]", (m[0] = [mutableArrayClass array])) TEST(@"+[arrayWithObjects:]", (a[0] = [arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil])) 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]] && |
︙ | ︙ | |||
191 192 193 194 195 196 197 | [a[1] indexOfObjectIdenticalTo: c_ary[1]] == 1) TEST(@"-[objectsInRange:]", [[a[0] objectsInRange: of_range(1, 2)] isEqual: [arrayClass arrayWithObjects: c_ary[1], c_ary[2], nil]]) TEST(@"-[replaceObject:withObject:]", | | < | < | < | 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 | [a[1] indexOfObjectIdenticalTo: c_ary[1]] == 1) TEST(@"-[objectsInRange:]", [[a[0] objectsInRange: of_range(1, 2)] isEqual: [arrayClass arrayWithObjects: c_ary[1], c_ary[2], nil]]) TEST(@"-[replaceObject:withObject:]", R([m[0] replaceObject: c_ary[1] 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(@"-[replaceObject:identicalTo:]", R([m[0] replaceObjectIdenticalTo: c_ary[0] withObject: c_ary[1]]) && [[m[0] objectAtIndex: 0] isEqual: c_ary[1]] && [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] && [[m[0] objectAtIndex: 2] isEqual: c_ary[2]]) TEST(@"-[replaceObjectAtIndex:withObject:]", 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) |
︙ | ︙ | |||
280 281 282 283 284 285 286 | i = 0; TEST(@"-[objectEnumerator]", (enumerator = [m[0] objectEnumerator])) while ((obj = [enumerator nextObject]) != nil) { if (![obj isEqual: c_ary[i]]) ok = false; | | < | < | < | < | < | 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 | i = 0; TEST(@"-[objectEnumerator]", (enumerator = [m[0] objectEnumerator])) while ((obj = [enumerator nextObject]) != nil) { 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) [m[0] removeObjectAtIndex: 0]; EXPECT_EXCEPTION(@"Detection of mutation during enumeration", OFEnumerationMutationException, [enumerator nextObject]) m[0] = [[a[0] mutableCopy] autorelease]; ok = true; i = 0; for (OFString *s in m[0]) { 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 withObject: c_ary[1]]; [m[0] replaceObjectAtIndex: 2 withObject: c_ary[2]]; ok = false; i = 0; @try { for (OFString *s in m[0]) { (void)s; |
︙ | ︙ |