From b2d7faf65c77d00cdab691ce9fef51884f56095a Mon Sep 17 00:00:00 2001 From: Erik Sundin Date: Sat, 14 Dec 2013 19:18:11 +0700 Subject: [PATCH] Inject primitives in Initializer and Defintion --- .../Initializer/TyphoonInitializer.h | 115 +++++++++++++++++- .../Initializer/TyphoonInitializer.m | 80 ++++++++++++ Source/Definition/TyphoonDefinition.h | 86 +++++++++++++ Source/Definition/TyphoonDefinition.m | 80 ++++++++++++ .../TyphoonPrimitiveTypeConverter.m | 16 ++- Tests/Factory/Internal/PrimitiveMan.h | 51 ++++++++ Tests/Factory/Internal/PrimitiveMan.m | 61 ++++++++++ ...ComponentDefinition+InstanceBuilderTests.m | 99 +++++++++++++++ Tests/Tests.xcodeproj/project.pbxproj | 10 ++ 9 files changed, 594 insertions(+), 4 deletions(-) create mode 100644 Tests/Factory/Internal/PrimitiveMan.h create mode 100644 Tests/Factory/Internal/PrimitiveMan.m diff --git a/Source/Definition/Initializer/TyphoonInitializer.h b/Source/Definition/Initializer/TyphoonInitializer.h index 919ce47fe..56e500cbe 100644 --- a/Source/Definition/Initializer/TyphoonInitializer.h +++ b/Source/Definition/Initializer/TyphoonInitializer.h @@ -36,6 +36,9 @@ typedef enum SEL _selector; } +/** +* The selector used to initialize the component. +*/ @property(nonatomic) SEL selector; - (id)initWithSelector:(SEL)initializer; @@ -58,24 +61,134 @@ typedef enum /* ====================================================================================================================================== */ #pragma mark - Block assembly +/** +* Injects with the given definition. +*/ - (void)injectWithDefinition:(TyphoonDefinition*)definition; +/** +* Injects with the value represented by the given text. The text will be used to create an instance of a class matching the +* required type. +* +* @see TyphoonTypeConverterRegistry for details on declaring your own type converters. +*/ - (void)injectWithValueAsText:(NSString*)text; +/** +* Injects with the value represented by the given text. The text will be used to create an instance of the given requiredType. +*/ - (void)injectWithValueAsText:(NSString*)text requiredTypeOrNil:(id)requiredTypeOrNil; +/** +* Injects with an object instance. +*/ - (void)injectWithObject:(id)value; +/** +* Injects with a collection of the given type. +*/ - (void)injectWithCollection:(void (^)(TyphoonParameterInjectedAsCollection*))collectionValues requiredType:(id)requiredType; +/** +* Injects with an int. +*/ +- (void)injectWithInt:(int)intValue; + +/** + * Injects with an unsigned int. + */ +- (void)injectWithUnsignedInt:(unsigned int)unsignedIntValue; + +/** + * Injects with a short. + */ +- (void)injectWithShort:(short)shortValue; + +/** +* Injects with an unsigned short. +*/ +- (void)injectWithUnsignedShort:(unsigned short)unsignedShortValue; + +/** +* Injects with a long. +*/ +- (void)injectWithLong:(long)longValue; + +/** + * Injects with an unsigned long. + */ +- (void)injectWithUnsignedLong:(unsigned long)unsignedLongValue; + +/** +* Injects with a long long. +*/ +- (void)injectWithLongLong:(long long)longLongValue; + +/** + * Injects with an unsigned long long. + */ +- (void)injectWithUnsignedLongLong:(unsigned long long)unsignedLongLongValue; + +/** +* Injects with an unsigned char. +*/ +- (void)injectWithUnsignedChar:(unsigned char)unsignedCharValue; + +/** +* Injects with a float. +*/ +- (void)injectWithFloat:(float)floatValue; + +/** +* Injects with a double. +*/ +- (void)injectWithDouble:(double)doubleValue; + +/** +* Injects with a boolean. +*/ +- (void)injectWithBool:(BOOL)boolValue; + +/** + * Injects with an integer. + */ +- (void)injectWithInteger:(NSInteger)integerValue; + +/** + * Injects with an unsigned integer. + */ +- (void)injectWithUnsignedInteger:(NSUInteger)unsignedIntegerValue; + +/** +* Injects with a class. +*/ +- (void)injectWithClass:(Class)classValue; + +/** +* Injects with a selector. +*/ +- (void)injectWithSelector:(SEL)selectorValue; + +/** +* Injects the parameter matched by the given name with the given definition. +*/ - (void)injectParameterNamed:(NSString*)name withDefinition:(TyphoonDefinition*)definition; -- (void)injectParameterAtIndex:(NSUInteger)index1 withDefinition:(TyphoonDefinition*)definition; +/** +* Injects the parameter at the given index with the given definition. +*/ +- (void)injectParameterAtIndex:(NSUInteger)index withDefinition:(TyphoonDefinition*)definition; +/** +* Injects the parameter at the given index as a collection of the given requiredType. +*/ - (void)injectParameterAtIndex:(NSUInteger)index asCollection:(void (^)(TyphoonParameterInjectedAsCollection*))collectionValues requiredType:(id)requiredType; +/** +* Injects the parameter matched by the given name as a collection of the given requiredType. +*/ - (void)injectParameterNamed:(NSString*)name asCollection:(void (^)(TyphoonParameterInjectedAsCollection*))collectionValues requiredType:(id)requiredType; diff --git a/Source/Definition/Initializer/TyphoonInitializer.m b/Source/Definition/Initializer/TyphoonInitializer.m index cad709383..fd76017cc 100644 --- a/Source/Definition/Initializer/TyphoonInitializer.m +++ b/Source/Definition/Initializer/TyphoonInitializer.m @@ -132,6 +132,86 @@ - (void)injectWithCollection:(void (^)(TyphoonParameterInjectedAsCollection*))co [self injectParameterAtIndex:[_injectedParameters count] asCollection:collectionValues requiredType:requiredType]; } +- (void)injectWithInt:(int)intValue +{ + [self injectWithValueAsText:[@(intValue) stringValue]]; +} + +- (void)injectWithUnsignedInt:(unsigned int)unsignedIntValue +{ + [self injectWithValueAsText:[@(unsignedIntValue) stringValue]]; +} + +- (void)injectWithShort:(short)shortValue +{ + [self injectWithValueAsText:[@(shortValue) stringValue]]; +} + +- (void)injectWithUnsignedShort:(unsigned short)unsignedShortValue +{ + [self injectWithValueAsText:[@(unsignedShortValue) stringValue]]; +} + +- (void)injectWithLong:(long)longValue +{ + [self injectWithValueAsText:[@(longValue) stringValue]]; +} + +- (void)injectWithUnsignedLong:(unsigned long)unsignedLongValue +{ + [self injectWithValueAsText:[@(unsignedLongValue) stringValue]]; +} + +- (void)injectWithLongLong:(long long)longLongValue +{ + [self injectWithValueAsText:[@(longLongValue) stringValue]]; +} + +- (void)injectWithUnsignedLongLong:(unsigned long long)unsignedLongLongValue +{ + [self injectWithValueAsText:[@(unsignedLongLongValue) stringValue]]; +} + +- (void)injectWithUnsignedChar:(unsigned char)unsignedCharValue +{ + [self injectWithValueAsText:[@(unsignedCharValue) stringValue]]; +} + +- (void)injectWithFloat:(float)floatValue +{ + [self injectWithValueAsText:[@(floatValue) stringValue]]; +} + +- (void)injectWithDouble:(double)doubleValue +{ + [self injectWithValueAsText:[@(doubleValue) stringValue]]; +} + +- (void)injectWithBool:(BOOL)boolValue +{ + [self injectWithValueAsText:[@(boolValue) stringValue]]; +} + +- (void)injectWithInteger:(NSInteger)integerValue +{ + [self injectWithValueAsText:[@(integerValue) stringValue]]; +} + +- (void)injectWithUnsignedInteger:(NSUInteger)unsignedIntegerValue +{ + [self injectWithValueAsText:[@(unsignedIntegerValue) stringValue]]; +} + +- (void)injectWithClass:(Class)classValue +{ + [self injectWithValueAsText:NSStringFromClass(classValue)]; +} + +- (void)injectWithSelector:(SEL)selectorValue +{ + [self injectWithValueAsText:NSStringFromSelector(selectorValue)]; +} + /* ====================================================================================================================================== */ #pragma mark - Block assembly diff --git a/Source/Definition/TyphoonDefinition.h b/Source/Definition/TyphoonDefinition.h index 8d5c05a00..54c822a47 100644 --- a/Source/Definition/TyphoonDefinition.h +++ b/Source/Definition/TyphoonDefinition.h @@ -93,6 +93,9 @@ typedef void(^TyphoonDefinitionBlock)(TyphoonDefinition* definition); */ - (void)injectProperty:(SEL)selector withDefinition:(TyphoonDefinition*)definition; +/** +* Injects property with the given object instance. +*/ - (void)injectProperty:(SEL)selector withObjectInstance:(id)instance; /** @@ -103,6 +106,89 @@ typedef void(^TyphoonDefinitionBlock)(TyphoonDefinition* definition); */ - (void)injectProperty:(SEL)withSelector withValueAsText:(NSString*)textValue; +/** +* Injects property as a collection. +*/ - (void)injectProperty:(SEL)withSelector asCollection:(void (^)(TyphoonPropertyInjectedAsCollection*))collectionValues; +/** +* Injects property as int. +*/ +- (void)injectProperty:(SEL)selector withInt:(int)intValue; + +/** + * Injects property as unsigned int. + */ +- (void)injectProperty:(SEL)selector withUnsignedInt:(unsigned int)unsignedIntValue; + +/** +* Injects property as short. +*/ +- (void)injectProperty:(SEL)selector withShort:(short)shortValue; + +/** + * Injects property as unsigned short. + */ +- (void)injectProperty:(SEL)selector withUnsignedShort:(unsigned short)unsignedShortValue; + +/** +* Injects property as long. +*/ +- (void)injectProperty:(SEL)selector withLong:(long)longValue; + +/** + * Injects property as unsigned long. + */ +- (void)injectProperty:(SEL)selector withUnsignedLong:(unsigned long)unsignedLongValue; + +/** +* Injects property as long long. +*/ +- (void)injectProperty:(SEL)selector withLongLong:(long long)longLongValue; + +/** + * Injects property as unsigned long long. + */ +- (void)injectProperty:(SEL)selector withUnsignedLongLong:(unsigned long long)unsignedLongLongValue; + +/** +* Injects property as unsigned char. +*/ +- (void)injectProperty:(SEL)selector withUnsignedChar:(unsigned char)unsignedCharValue; + +/** +* Injects property as float. +*/ +- (void)injectProperty:(SEL)selector withFloat:(float)floatValue; + +/** +* Injects property as double. +*/ +- (void)injectProperty:(SEL)selector withDouble:(double)doubleValue; + +/** +* Injects property as boolean. +*/ +- (void)injectProperty:(SEL)selector withBool:(BOOL)boolValue; + +/** + * Injects property as integeger. + */ +- (void)injectProperty:(SEL)selector withInteger:(NSInteger)integerValue; + +/** + * Injects property as unsigned integer. + */ +- (void)injectProperty:(SEL)selector withUnsignedInteger:(NSUInteger)unsignedIntegerValue; + +/** +* Injects property as class. +*/ +- (void)injectProperty:(SEL)selector withClass:(Class)classValue; + +/** +* Injects property as selector. +*/ +- (void)injectProperty:(SEL)selector withSelector:(SEL)selectorValue; + @end diff --git a/Source/Definition/TyphoonDefinition.m b/Source/Definition/TyphoonDefinition.m index e1ec2b571..1766d37db 100644 --- a/Source/Definition/TyphoonDefinition.m +++ b/Source/Definition/TyphoonDefinition.m @@ -117,6 +117,86 @@ - (void)injectProperty:(SEL)withSelector asCollection:(void (^)(TyphoonPropertyI [_injectedProperties addObject:propertyInjectedAsCollection]; } +- (void)injectProperty:(SEL)selector withInt:(int)intValue +{ + [self injectProperty:selector withValueAsText:[@(intValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withUnsignedInt:(unsigned int)unsignedIntValue +{ + [self injectProperty:selector withValueAsText:[@(unsignedIntValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withShort:(short)shortValue +{ + [self injectProperty:selector withValueAsText:[@(shortValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withUnsignedShort:(unsigned short)unsignedIntShort +{ + [self injectProperty:selector withValueAsText:[@(unsignedIntShort) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withLong:(long)longValue +{ + [self injectProperty:selector withValueAsText:[@(longValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withUnsignedLong:(unsigned long)unsignedLongValue +{ + [self injectProperty:selector withValueAsText:[@(unsignedLongValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withLongLong:(long long)longLongValue +{ + [self injectProperty:selector withValueAsText:[@(longLongValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withUnsignedLongLong:(unsigned long long)unsignedLongLongValue +{ + [self injectProperty:selector withValueAsText:[@(unsignedLongLongValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withUnsignedChar:(unsigned char)unsignedCharValue +{ + [self injectProperty:selector withValueAsText:[@(unsignedCharValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withFloat:(float)floatValue +{ + [self injectProperty:selector withValueAsText:[@(floatValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withDouble:(double)doubleValue +{ + [self injectProperty:selector withValueAsText:[@(doubleValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withBool:(BOOL)boolValue +{ + [self injectProperty:selector withValueAsText:[@(boolValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withInteger:(NSInteger)integerValue +{ + [self injectProperty:selector withValueAsText:[@(integerValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withUnsignedInteger:(NSUInteger)unsignedIntegerValue +{ + [self injectProperty:selector withValueAsText:[@(unsignedIntegerValue) stringValue]]; +} + +- (void)injectProperty:(SEL)selector withClass:(Class)classValue +{ + [self injectProperty:selector withValueAsText:NSStringFromClass(classValue)]; +} + +- (void)injectProperty:(SEL)selector withSelector:(SEL)selectorValue +{ + [self injectProperty:selector withValueAsText:NSStringFromSelector(selectorValue)]; +} + - (void)setInitializer:(TyphoonInitializer*)initializer { _initializer = initializer; diff --git a/Source/TypeConversion/Converters/TyphoonPrimitiveTypeConverter.m b/Source/TypeConversion/Converters/TyphoonPrimitiveTypeConverter.m index 300ca5742..f98b882c8 100644 --- a/Source/TypeConversion/Converters/TyphoonPrimitiveTypeConverter.m +++ b/Source/TypeConversion/Converters/TyphoonPrimitiveTypeConverter.m @@ -63,9 +63,9 @@ - (unsigned char)convertToUnsignedChar:(NSString*)stringValue - (unsigned int)convertToUnsignedInt:(NSString*)stringValue { NSScanner* scanner = [[NSScanner alloc] initWithString:stringValue]; - int converted = 0; - [scanner scanInt:&converted]; - return [[NSNumber numberWithInt:converted] unsignedIntValue]; + long long converted = 0; + [scanner scanLongLong:&converted]; + return [[NSNumber numberWithLongLong:converted] unsignedIntValue]; } - (unsigned short)convertToUnsignedShort:(NSString*)stringValue @@ -157,6 +157,11 @@ - (void)setPrimitiveArgumentFor:(NSInvocation*)invocation index:(NSUInteger)inde int converted = [self convertToInt:textValue]; [invocation setArgument:&converted atIndex:index]; } + else if (requiredType.primitiveType == TyphoonPrimitiveTypeShort) + { + short converted = [self convertToShort:textValue]; + [invocation setArgument:&converted atIndex:index]; + } else if (requiredType.primitiveType == TyphoonPrimitiveTypeLong) { long converted = [self convertToLong:textValue]; @@ -187,6 +192,11 @@ - (void)setPrimitiveArgumentFor:(NSInvocation*)invocation index:(NSUInteger)inde unsigned int converted = [self convertToUnsignedInt:textValue]; [invocation setArgument:&converted atIndex:index]; } + else if (requiredType.primitiveType == TyphoonPrimitiveTypeUnsignedShort) + { + unsigned short converted = [self convertToUnsignedShort:textValue]; + [invocation setArgument:&converted atIndex:index]; + } else if (requiredType.primitiveType == TyphoonPrimitiveTypeUnsignedLong) { unsigned long converted = [self convertToUnsignedLong:textValue]; diff --git a/Tests/Factory/Internal/PrimitiveMan.h b/Tests/Factory/Internal/PrimitiveMan.h new file mode 100644 index 000000000..025889c1c --- /dev/null +++ b/Tests/Factory/Internal/PrimitiveMan.h @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// TYPHOON FRAMEWORK +// Copyright 2013, Jasper Blues & Contributors +// All Rights Reserved. +// +// NOTICE: The authors permit you to use, modify, and distribute this file +// in accordance with the terms of the license agreement accompanying it. +// +//////////////////////////////////////////////////////////////////////////////// + +#import + + +@interface PrimitiveMan : NSObject + +- (id)initWithIntValue:(int)intValue + unsignedIntValue:(unsigned int)unsignedIntValue + shortValue:(short)shortValue + unsignedShortValue:(unsigned short)unsignedShortValue + longValue:(long)longValue + unsignedLongValue:(unsigned long)unsignedLongValue + longLongValue:(long long)longLongValue + unsignedLongLongValue:(unsigned long long)unsignedLongLongValue + unsignedCharValue:(unsigned char)unsignedCharValue + floatValue:(float)floatValue + doubleValue:(double)doubleValue + boolValue:(BOOL)boolValue + integerValue:(NSInteger)integerValue + unsignedIntegerValue:(NSUInteger)unsignedIntegerValue + classValue:(Class)classValue + selectorValue:(SEL)selectorValue; + +@property (nonatomic, assign) int intValue; +@property (nonatomic, assign) short shortValue; +@property (nonatomic, assign) long longValue; +@property (nonatomic, assign) long long longLongValue; +@property (nonatomic, assign) unsigned char unsignedCharValue; +@property (nonatomic, assign) unsigned int unsignedIntValue; +@property (nonatomic, assign) unsigned short unsignedShortValue; +@property (nonatomic, assign) unsigned long unsignedLongValue; +@property (nonatomic, assign) unsigned long long unsignedLongLongValue; +@property (nonatomic, assign) float floatValue; +@property (nonatomic, assign) double doubleValue; +@property (nonatomic, assign) BOOL boolValue; +@property (nonatomic, assign) Class classValue; +@property (nonatomic, assign) SEL selectorValue; +@property (nonatomic, assign) NSInteger integerValue; +@property (nonatomic, assign) NSUInteger unsignedIntegerValue; + +@end \ No newline at end of file diff --git a/Tests/Factory/Internal/PrimitiveMan.m b/Tests/Factory/Internal/PrimitiveMan.m new file mode 100644 index 000000000..6e6d969f6 --- /dev/null +++ b/Tests/Factory/Internal/PrimitiveMan.m @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// TYPHOON FRAMEWORK +// Copyright 2013, Jasper Blues & Contributors +// All Rights Reserved. +// +// NOTICE: The authors permit you to use, modify, and distribute this file +// in accordance with the terms of the license agreement accompanying it. +// +//////////////////////////////////////////////////////////////////////////////// + +#import "PrimitiveMan.h" + + +@implementation PrimitiveMan +{ + +} + +- (id)initWithIntValue:(int)intValue + unsignedIntValue:(unsigned int)unsignedIntValue + shortValue:(short)shortValue + unsignedShortValue:(unsigned short)unsignedShortValue + longValue:(long)longValue + unsignedLongValue:(unsigned long)unsignedLongValue + longLongValue:(long long)longLongValue + unsignedLongLongValue:(unsigned long long)unsignedLongLongValue + unsignedCharValue:(unsigned char)unsignedCharValue + floatValue:(float)floatValue + doubleValue:(double)doubleValue + boolValue:(BOOL)boolValue + integerValue:(NSInteger)integerValue + unsignedIntegerValue:(NSUInteger)unsignedIntegerValue + classValue:(Class)classValue + selectorValue:(SEL)selectorValue +{ + self = [super init]; + if (self) + { + _intValue = intValue; + _unsignedIntValue = unsignedIntValue; + _shortValue = shortValue; + _unsignedShortValue = unsignedShortValue; + _longValue = longValue; + _unsignedLongValue = unsignedLongValue; + _longLongValue = longLongValue; + _unsignedLongLongValue = unsignedLongLongValue; + _unsignedCharValue = unsignedCharValue; + _floatValue = floatValue; + _doubleValue = doubleValue; + _boolValue = boolValue; + _integerValue = integerValue; + _unsignedIntegerValue = unsignedIntegerValue; + _classValue = classValue; + _selectorValue = selectorValue; + } + return self; +} + + +@end \ No newline at end of file diff --git a/Tests/Factory/Internal/TyphoonComponentDefinition+InstanceBuilderTests.m b/Tests/Factory/Internal/TyphoonComponentDefinition+InstanceBuilderTests.m index 80c4d42fc..828aac050 100644 --- a/Tests/Factory/Internal/TyphoonComponentDefinition+InstanceBuilderTests.m +++ b/Tests/Factory/Internal/TyphoonComponentDefinition+InstanceBuilderTests.m @@ -16,6 +16,7 @@ #import "TyphoonDefinition+InstanceBuilder.h" #import "TyphoonPropertyInjectedAsCollection.h" #import "TyphoonParameterInjectedAsCollection.h" +#import "PrimitiveMan.h" @interface ComponentDefinition_InstanceBuilderTests : SenTestCase @end @@ -101,6 +102,64 @@ - (void)test_injects_initializer_value_as_collection assertThatUnsignedLong([knight.favoriteDamsels count], equalToUnsignedLong(2)); } +- (void)test_inject_initializer_values_as_primitives +{ + TyphoonDefinition* definition = [[TyphoonDefinition alloc] initWithClass:[PrimitiveMan class] key:@"primitive"]; + TyphoonInitializer* initializer = [[TyphoonInitializer alloc] initWithSelector:@selector( + initWithIntValue: + unsignedIntValue: + shortValue: + unsignedShortValue: + longValue: + unsignedLongValue: + longLongValue: + unsignedLongLongValue: + unsignedCharValue: + floatValue: + doubleValue: + boolValue: + integerValue: + unsignedIntegerValue: + classValue: + selectorValue:)]; + [initializer injectWithInt:1]; + [initializer injectWithUnsignedInt:2]; + [initializer injectWithShort:3]; + [initializer injectWithUnsignedShort:4]; + [initializer injectWithLong:5]; + [initializer injectWithUnsignedLong:6]; + [initializer injectWithLongLong:7]; + [initializer injectWithUnsignedLongLong:8]; + [initializer injectWithUnsignedChar:9]; + [initializer injectWithFloat:10.0]; + [initializer injectWithDouble:11.0]; + [initializer injectWithBool:YES]; + [initializer injectWithInteger:NSIntegerMax]; + [initializer injectWithUnsignedInteger:NSUIntegerMax]; + [initializer injectWithClass:[self class]]; + [initializer injectWithSelector:@selector(selectorValue)]; + + [definition setInitializer:initializer]; + + [_componentFactory register:definition]; + PrimitiveMan* primitiveMan = [_componentFactory componentForKey:@"primitive"]; + assertThatInt(primitiveMan.intValue, equalToInt(1)); + assertThatUnsignedInt(primitiveMan.unsignedIntValue, equalToUnsignedInt(2)); + assertThatShort(primitiveMan.shortValue, equalToShort(3)); + assertThatUnsignedShort(primitiveMan.unsignedShortValue, equalToUnsignedShort(4)); + assertThatLong(primitiveMan.longValue, equalToLong(5)); + assertThatUnsignedLong(primitiveMan.unsignedLongValue, equalToUnsignedLong(6)); + assertThatLongLong(primitiveMan.longLongValue, equalToLongLong(7)); + assertThatUnsignedLongLong(primitiveMan.unsignedLongLongValue, equalToUnsignedLongLong(8)); + assertThatUnsignedChar(primitiveMan.unsignedCharValue, equalToUnsignedChar(9)); + assertThatFloat(primitiveMan.floatValue, equalToFloat(10.0)); + assertThatDouble(primitiveMan.doubleValue, equalToDouble(11.0)); + assertThatBool(primitiveMan.boolValue, equalToBool(YES)); + assertThatInteger(primitiveMan.integerValue, equalToInteger(NSIntegerMax)); + assertThatUnsignedInteger(primitiveMan.unsignedIntegerValue, equalToUnsignedInteger(NSUIntegerMax)); + assertThat(NSStringFromClass(primitiveMan.classValue), equalTo(NSStringFromClass([self class]))); + assertThat(NSStringFromSelector(primitiveMan.selectorValue), equalTo(NSStringFromSelector(@selector(selectorValue)))); +} /* ====================================================================================================================================== */ #pragma mark - Property injection @@ -151,6 +210,46 @@ - (void)test_injects_property_value_as_long assertThatLong(knight.damselsRescued, equalToLongLong(12)); } +- (void)test_inject_property_value_as_primitives +{ + TyphoonDefinition* definition = [[TyphoonDefinition alloc] initWithClass:[PrimitiveMan class] key:@"primitive"]; + [definition injectProperty:@selector(intValue) withInt:1]; + [definition injectProperty:@selector(unsignedIntValue) withUnsignedInt:2]; + [definition injectProperty:@selector(shortValue) withShort:3]; + [definition injectProperty:@selector(unsignedShortValue) withUnsignedShort:4]; + [definition injectProperty:@selector(longValue) withLong:5]; + [definition injectProperty:@selector(unsignedLongValue) withUnsignedLong:6]; + [definition injectProperty:@selector(longLongValue) withLongLong:7]; + [definition injectProperty:@selector(unsignedLongLongValue) withUnsignedLongLong:8]; + [definition injectProperty:@selector(unsignedCharValue) withUnsignedChar:9]; + [definition injectProperty:@selector(floatValue) withFloat:10.101010]; + [definition injectProperty:@selector(doubleValue) withDouble:11.111111]; + [definition injectProperty:@selector(boolValue) withBool:YES]; + [definition injectProperty:@selector(integerValue) withInteger:NSIntegerMax]; + [definition injectProperty:@selector(unsignedIntegerValue) withUnsignedInteger:NSUIntegerMax]; + [definition injectProperty:@selector(classValue) withClass:[self class]]; + [definition injectProperty:@selector(selectorValue) withSelector:@selector(selectorValue)]; + + [_componentFactory register:definition]; + PrimitiveMan* primitiveMan = [_componentFactory componentForKey:@"primitive"]; + assertThatInt(primitiveMan.intValue, equalToInt(1)); + assertThatUnsignedInt(primitiveMan.unsignedIntValue, equalToUnsignedInt(2)); + assertThatShort(primitiveMan.shortValue, equalToShort(3)); + assertThatUnsignedShort(primitiveMan.unsignedShortValue, equalToUnsignedShort(4)); + assertThatLong(primitiveMan.longValue, equalToLong(5)); + assertThatUnsignedLong(primitiveMan.unsignedLongValue, equalToUnsignedLong(6)); + assertThatLongLong(primitiveMan.longLongValue, equalToLongLong(7)); + assertThatUnsignedLongLong(primitiveMan.unsignedLongLongValue, equalToUnsignedLongLong(8)); + assertThatUnsignedChar(primitiveMan.unsignedCharValue, equalToUnsignedChar(9)); + assertThatFloat(primitiveMan.floatValue, equalToFloat(10.101010)); + assertThatDouble(primitiveMan.doubleValue, equalToDouble(11.111111)); + assertThatBool(primitiveMan.boolValue, equalToBool(YES)); + assertThatInteger(primitiveMan.integerValue, equalToInteger(NSIntegerMax)); + assertThatUnsignedInteger(primitiveMan.unsignedIntegerValue, equalToUnsignedInteger(NSUIntegerMax)); + assertThat(NSStringFromClass(primitiveMan.classValue), equalTo(NSStringFromClass([self class]))); + assertThat(NSStringFromSelector(primitiveMan.selectorValue), equalTo(NSStringFromSelector(@selector(selectorValue)))); +} + /* ====================================================================================================================================== */ #pragma mark - Property injection error handling diff --git a/Tests/Tests.xcodeproj/project.pbxproj b/Tests/Tests.xcodeproj/project.pbxproj index a4b49972e..6216e5b52 100644 --- a/Tests/Tests.xcodeproj/project.pbxproj +++ b/Tests/Tests.xcodeproj/project.pbxproj @@ -287,8 +287,11 @@ BA798EC89A23D4FC0EFB465D /* TyphoonStringUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BA79854F29FE8A327A82E8BC /* TyphoonStringUtilsTests.m */; }; BA798EE809EEDC8B00D40EB1 /* TyphoonPropertyPlaceholderConfigurerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BA798F08B41D2D34902BF572 /* TyphoonPropertyPlaceholderConfigurerTests.m */; }; CAE261437295B90C18E78C61 /* SomeOtherProperties.properties in Resources */ = {isa = PBXBuildFile; fileRef = CAE1370C5429F92760CB0390 /* SomeOtherProperties.properties */; }; + CAE6A1CBA594217C5183AA04 /* PrimitiveMan.m in Sources */ = {isa = PBXBuildFile; fileRef = CAEA8AED5BCF8660B3CF23AF /* PrimitiveMan.m */; }; CAE7F900AA9C836DFE412203 /* SomeOtherProperties.properties in Resources */ = {isa = PBXBuildFile; fileRef = CAE1370C5429F92760CB0390 /* SomeOtherProperties.properties */; }; CAEDC7A4F6804D310052F633 /* SomeOtherProperties.properties in Resources */ = {isa = PBXBuildFile; fileRef = CAE1370C5429F92760CB0390 /* SomeOtherProperties.properties */; }; + CAEE3865245D95F01C38E748 /* PrimitiveMan.m in Sources */ = {isa = PBXBuildFile; fileRef = CAEA8AED5BCF8660B3CF23AF /* PrimitiveMan.m */; }; + CAEE50BA12C347B06D7A9A77 /* PrimitiveMan.m in Sources */ = {isa = PBXBuildFile; fileRef = CAEA8AED5BCF8660B3CF23AF /* PrimitiveMan.m */; }; CD65DA1387F74352A0088704 /* libPods-iOS Tests (Cocoapods).a in Frameworks */ = {isa = PBXBuildFile; fileRef = B90D396911F743468FF96BB5 /* libPods-iOS Tests (Cocoapods).a */; }; D174EF8C2C6845E69666DC4F /* libPods-osx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AC491FA50E048988BFB5756 /* libPods-osx.a */; }; /* End PBXBuildFile section */ @@ -477,6 +480,8 @@ BA798D4E3084C51B7ACB6DC9 /* TyphoonViewControllerNibResolverTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonViewControllerNibResolverTests.m; sourceTree = ""; }; BA798F08B41D2D34902BF572 /* TyphoonPropertyPlaceholderConfigurerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonPropertyPlaceholderConfigurerTests.m; sourceTree = ""; }; CAE1370C5429F92760CB0390 /* SomeOtherProperties.properties */ = {isa = PBXFileReference; lastKnownFileType = file.properties; path = SomeOtherProperties.properties; sourceTree = ""; }; + CAEA8AED5BCF8660B3CF23AF /* PrimitiveMan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrimitiveMan.m; sourceTree = ""; }; + CAEB463B70EA0EFD7796673B /* PrimitiveMan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrimitiveMan.h; sourceTree = ""; }; F8B50DFBF255467DA9F7C30F /* libPods-ios.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ios.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -913,6 +918,8 @@ isa = PBXGroup; children = ( BA7989092E6BC5E4F610F8F6 /* TyphoonComponentDefinition+InstanceBuilderTests.m */, + CAEA8AED5BCF8660B3CF23AF /* PrimitiveMan.m */, + CAEB463B70EA0EFD7796673B /* PrimitiveMan.h */, ); path = Internal; sourceTree = ""; @@ -1324,6 +1331,7 @@ BA7981389DA42F04313E85EF /* TyphoonBundleResourceTests.m in Sources */, BA79816E8927B83FA26ECCCA /* TyphoonComponentDefinition+InstanceBuilderTests.m in Sources */, BA7984C81B7B6D8D2E33A3FE /* VATestObserver.m in Sources */, + CAE6A1CBA594217C5183AA04 /* PrimitiveMan.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1404,6 +1412,7 @@ BA798E077CA7C28EB0EB2EF4 /* TyphoonPatcherTests.m in Sources */, BA798908C8A296FD5FCD31A7 /* TyphoonBundleResourceTests.m in Sources */, BA798C878348D43289781407 /* TyphoonComponentDefinition+InstanceBuilderTests.m in Sources */, + CAEE50BA12C347B06D7A9A77 /* PrimitiveMan.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1487,6 +1496,7 @@ BA7987F78E61D362F5BA8F8E /* TyphoonBundleResourceTests.m in Sources */, BA798ADB826C820212365F2F /* TyphoonComponentDefinition+InstanceBuilderTests.m in Sources */, BA798122C0D3CF30F25BBE05 /* VATestObserver.m in Sources */, + CAEE3865245D95F01C38E748 /* PrimitiveMan.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };