Skip to content

Commit

Permalink
use literals and subscripting
Browse files Browse the repository at this point in the history
  • Loading branch information
madsolar8582 committed Aug 10, 2014
1 parent c026ab2 commit 81631dd
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
28 changes: 14 additions & 14 deletions Source/OCMock/NSInvocation+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,73 +59,73 @@ - (id)getArgumentAtIndexAsObject:(int)argIndex
{
int value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithInt:value];
return @(value);
}
case 's':
{
short value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithShort:value];
return @(value);
}
case 'l':
{
long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithLong:value];
return @(value);
}
case 'q':
{
long long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithLongLong:value];
return @(value);
}
case 'c':
{
char value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithChar:value];
return @(value);
}
case 'C':
{
unsigned char value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedChar:value];
return @(value);
}
case 'I':
{
unsigned int value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedInt:value];
return @(value);
}
case 'S':
{
unsigned short value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedShort:value];
return @(value);
}
case 'L':
{
unsigned long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedLong:value];
return @(value);
}
case 'Q':
{
unsigned long long value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithUnsignedLongLong:value];
return @(value);
}
case 'f':
{
float value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithFloat:value];
return @(value);
}
case 'd':
{
double value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithDouble:value];
return @(value);
}
case 'D':
{
Expand All @@ -137,7 +137,7 @@ - (id)getArgumentAtIndexAsObject:(int)argIndex
{
bool value;
[self getArgument:&value atIndex:argIndex];
return [NSNumber numberWithBool:value];
return @(value);
}
case '^':
case '*':
Expand Down Expand Up @@ -175,7 +175,7 @@ - (NSString *)invocationDescription
unsigned int i;
for(i = 2; i < numberOfArgs; i++)
{
[description appendFormat:@"%@%@:", (i > 2 ? @" " : @""), [selectorParts objectAtIndex:(i - 2)]];
[description appendFormat:@"%@%@:", (i > 2 ? @" " : @""), selectorParts[(i - 2)]];
[description appendString:[self argumentDescriptionAtIndex:i]];
}

Expand Down
4 changes: 2 additions & 2 deletions Source/OCMock/NSObject+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ + (IMP)instanceMethodForwarderForSelector:(SEL)aSelector
BOOL needsStructureReturn;
void *rawCacheKey[2] = { (void *)self, aSelector };
NSData *cacheKey = [NSData dataWithBytes:rawCacheKey length:sizeof(rawCacheKey)];
NSNumber *cachedValue = [_OCMReturnTypeCache objectForKey:cacheKey];
NSNumber *cachedValue = _OCMReturnTypeCache[cacheKey];

if(cachedValue == nil)
{
NSMethodSignature *sig = [self instanceMethodSignatureForSelector:aSelector];
needsStructureReturn = [sig usesSpecialStructureReturn];
[_OCMReturnTypeCache setObject:[NSNumber numberWithBool:needsStructureReturn] forKey:cacheKey];
_OCMReturnTypeCache[cacheKey] = @(needsStructureReturn);
}
else
{
Expand Down
28 changes: 14 additions & 14 deletions Source/OCMock/NSValue+OCMAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ static CFNumberType OCMNumberTypeForObjCType(const char *objcType)

static NSNumber *OCMNumberForValue(NSValue *value)
{
#define CREATE_NUM(_type, _meth) ({ _type _v; [value getValue:&_v]; [NSNumber _meth _v]; })
#define CREATE_NUM(_type) ({ _type _v; [value getValue:&_v]; @(_v); })
switch([value objCType][0])
{
case 'c': return CREATE_NUM(char, numberWithChar:);
case 'C': return CREATE_NUM(unsigned char, numberWithUnsignedChar:);
case 'B': return CREATE_NUM(bool, numberWithBool:);
case 's': return CREATE_NUM(short, numberWithShort:);
case 'S': return CREATE_NUM(unsigned short, numberWithUnsignedShort:);
case 'i': return CREATE_NUM(int, numberWithInt:);
case 'I': return CREATE_NUM(unsigned int, numberWithUnsignedInt:);
case 'l': return CREATE_NUM(long, numberWithLong:);
case 'L': return CREATE_NUM(unsigned long, numberWithUnsignedLong:);
case 'q': return CREATE_NUM(long long, numberWithLongLong:);
case 'Q': return CREATE_NUM(unsigned long long, numberWithUnsignedLongLong:);
case 'f': return CREATE_NUM(float, numberWithFloat:);
case 'd': return CREATE_NUM(double, numberWithDouble:);
case 'c': return CREATE_NUM(char);
case 'C': return CREATE_NUM(unsigned char);
case 'B': return CREATE_NUM(bool);
case 's': return CREATE_NUM(short);
case 'S': return CREATE_NUM(unsigned short);
case 'i': return CREATE_NUM(int);
case 'I': return CREATE_NUM(unsigned int);
case 'l': return CREATE_NUM(long);
case 'L': return CREATE_NUM(unsigned long);
case 'q': return CREATE_NUM(long long);
case 'Q': return CREATE_NUM(unsigned long long);
case 'f': return CREATE_NUM(float);
case 'd': return CREATE_NUM(double);
default: return nil;
}
}
Expand Down
10 changes: 5 additions & 5 deletions Source/OCMock/OCMockObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ - (id)verifyAtLocation:(OCMLocation *)location
if([unsatisfiedExpectations count] == 1)
{
NSString *description = [NSString stringWithFormat:@"%@: expected method was not invoked: %@",
[self description], [[unsatisfiedExpectations objectAtIndex:0] description]];
[self description], [unsatisfiedExpectations[0] description]];
OCMReportFailure(location, description);
}
else if([unsatisfiedExpectations count] > 0)
Expand All @@ -180,7 +180,7 @@ - (id)verifyAtLocation:(OCMLocation *)location
if([exceptions count] > 0)
{
NSString *description = [NSString stringWithFormat:@"%@: %@ (This is a strict mock failure that was ignored when it actually occured.)",
[self description], [[exceptions objectAtIndex:0] description]];
[self description], [exceptions[0] description]];
OCMReportFailure(location, description);
}

Expand Down Expand Up @@ -275,14 +275,14 @@ - (BOOL)handleInvocation:(NSInvocation *)anInvocation
}];
if(idx == NSNotFound)
return NO;
OCMInvocationStub *stub = [stubs objectAtIndex:idx];
OCMInvocationStub *stub = stubs[idx];

if([expectations containsObject:stub])
{
if(expectationOrderMatters && ([expectations objectAtIndex:0] != stub))
if(expectationOrderMatters && (expectations[0] != stub))
{
[NSException raise:NSInternalInconsistencyException format:@"%@: unexpected method invoked: %@\n\texpected:\t%@",
[self description], [stub description], [[expectations objectAtIndex:0] description]];
[self description], [stub description], [expectations[0] description]];

}
if([(OCMInvocationExpectation *)stub isSatisfied])
Expand Down
2 changes: 1 addition & 1 deletion Source/OCMock/OCObserverMockObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (void)handleNotification:(NSNotification *)aNotification
limit = expectationOrderMatters ? 1 : [recorders count];
for(i = 0; i < limit; i++)
{
if([[recorders objectAtIndex:i] matchesNotification:aNotification])
if([recorders[i] matchesNotification:aNotification])
{
[recorders removeObjectAtIndex:i];
return;
Expand Down
6 changes: 3 additions & 3 deletions Source/OCMockTests/NSInvocationOCMAdditionsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)testInvocationDescriptionWithObjectArgument
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
// Give it one argument (starts at index 2)
NSNumber *argument = [NSNumber numberWithInt:1];
NSNumber *argument = @1;
[invocation setArgument:&argument atIndex:2];

NSString *expected = [NSString stringWithFormat:@"isEqualToNumber:%d", 1];
Expand Down Expand Up @@ -80,7 +80,7 @@ - (void)testInvocationDescriptionWithObjectArguments
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
// Give it two arguments
NSNumber *argumentOne = [NSNumber numberWithInt:1];
NSNumber *argumentOne = @1;
NSString *argumentTwo = @"TEST_STRING";
[invocation setArgument:&argumentOne atIndex:2];
[invocation setArgument:&argumentTwo atIndex:3];
Expand All @@ -96,7 +96,7 @@ - (void)testInvocationDescriptionWithArrayArgument
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
// Give it one argument (starts at index 2)
NSArray *argument = [NSArray arrayWithObject:@"TEST_STRING"];
NSArray *argument = @[@"TEST_STRING"];
[invocation setArgument:&argument atIndex:2];

NSString *expected = [NSString stringWithFormat:@"addObjectsFromArray:%@", [argument description]];
Expand Down
4 changes: 2 additions & 2 deletions Source/OCMockTests/OCMStubRecorderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)testAddsReturnValueProvider
NSArray *actionList = [(OCMInvocationStub *)[recorder invocationMatcher] invocationActions];

XCTAssertEqual((NSUInteger)1, [actionList count], @"Should have added one action.");
XCTAssertEqualObjects([OCMReturnValueProvider class], [[actionList objectAtIndex:0] class], @"Should have added correct action.");
XCTAssertEqualObjects([OCMReturnValueProvider class], [actionList[0] class], @"Should have added correct action.");
}

- (void)testAddsExceptionReturnValueProvider
Expand All @@ -63,7 +63,7 @@ - (void)testAddsExceptionReturnValueProvider
NSArray *actionList = [(OCMInvocationStub *)[recorder invocationMatcher] invocationActions];

XCTAssertEqual((NSUInteger)1, [actionList count], @"Should have added one action.");
XCTAssertEqualObjects([OCMExceptionReturnValueProvider class], [[actionList objectAtIndex:0] class], @"Should have added correct action.");
XCTAssertEqualObjects([OCMExceptionReturnValueProvider class], [actionList[0] class], @"Should have added correct action.");

}

Expand Down
6 changes: 3 additions & 3 deletions Source/OCMockTests/OCObserverMockObjectTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)testAcceptsExpectedNotification
- (void)testAcceptsExpectedNotificationWithSpecifiedObjectAndUserInfo
{
[center addMockObserver:mock name:TestNotificationOne object:nil];
NSDictionary *info = [NSDictionary dictionaryWithObject:@"foo" forKey:@"key"];
NSDictionary *info = @{@"key": @"foo"};
[[mock expect] notificationWithName:TestNotificationOne object:self userInfo:info];

[center postNotificationName:TestNotificationOne object:self userInfo:info];
Expand Down Expand Up @@ -121,9 +121,9 @@ - (void)testRaisesWhenNotificationWithWrongUserInfoIsReceived
{
[center addMockObserver:mock name:TestNotificationOne object:nil];
[[mock expect] notificationWithName:TestNotificationOne object:self
userInfo:[NSDictionary dictionaryWithObject:@"foo" forKey:@"key"]];
userInfo:@{@"key": @"foo"}];
XCTAssertThrows([center postNotificationName:TestNotificationOne object:[NSString string]
userInfo:[NSDictionary dictionaryWithObject:@"bar" forKey:@"key"]]);
userInfo:@{@"key": @"bar"}]);
}

- (void)testRaisesOnVerifyWhenExpectedNotificationIsNotSent
Expand Down

0 comments on commit 81631dd

Please sign in to comment.