Permalink
Browse files

Fixed property formatting when no attribute is given.

  • Loading branch information...
1 parent c05364a commit a4c88d75fdee894c67907ba65c2e0b24e1a4b1cb @tomaz committed Dec 16, 2010
Showing with 39 additions and 19 deletions.
  1. +21 −19 Model/GBMethodData.m
  2. +18 −0 Testing/GBMethodDataTesting.m
View
@@ -64,25 +64,27 @@ - (NSArray *)formattedComponents {
[result addObject:[self formattedComponentWithValue:@" "]];
// Add the list of attributes.
- __block BOOL isSetterOrGetter = NO;
- [result addObject:[self formattedComponentWithValue:@"("]];
- [self.methodAttributes enumerateObjectsUsingBlock:^(NSString *attribute, NSUInteger idx, BOOL *stop) {
- [result addObject:[self formattedComponentWithValue:attribute]];
- if ([attribute isEqualToString:@"setter"] || [attribute isEqualToString:@"getter"]) {
- isSetterOrGetter = YES;
- return;
- }
- if (isSetterOrGetter) {
- if ([attribute isEqualToString:@"="]) return;
- isSetterOrGetter = NO;
- }
- if (idx < [self.methodAttributes count]-1) {
- [result addObject:[self formattedComponentWithValue:@","]];
- [result addObject:[self formattedComponentWithValue:@" "]];
- }
- }];
- [result addObject:[self formattedComponentWithValue:@")"]];
- [result addObject:[self formattedComponentWithValue:@" "]];
+ if ([self.methodAttributes count] > 0) {
+ __block BOOL isSetterOrGetter = NO;
+ [result addObject:[self formattedComponentWithValue:@"("]];
+ [self.methodAttributes enumerateObjectsUsingBlock:^(NSString *attribute, NSUInteger idx, BOOL *stop) {
+ [result addObject:[self formattedComponentWithValue:attribute]];
+ if ([attribute isEqualToString:@"setter"] || [attribute isEqualToString:@"getter"]) {
+ isSetterOrGetter = YES;
+ return;
+ }
+ if (isSetterOrGetter) {
+ if ([attribute isEqualToString:@"="]) return;
+ isSetterOrGetter = NO;
+ }
+ if (idx < [self.methodAttributes count]-1) {
+ [result addObject:[self formattedComponentWithValue:@","]];
+ [result addObject:[self formattedComponentWithValue:@" "]];
+ }
+ }];
+ [result addObject:[self formattedComponentWithValue:@")"]];
+ [result addObject:[self formattedComponentWithValue:@" "]];
+ }
// Add the list of resulting types, append space unless last component was * and property name.
if (![self formatTypesFromArray:self.methodResultTypes toArray:result prefix:nil suffix:nil]) {
@@ -138,6 +138,24 @@ - (void)testFormattedComponents_shouldReturnComplexPropertyComponents {
nil];
}
+- (void)testFormattedComponents_shouldProperlyHandlePropertyWithNoAttributes {
+ // setup
+ NSArray *attributes = [NSArray array];
+ NSArray *components = [NSArray arrayWithObjects:@"NSString", @"*", @"name", nil];
+ GBMethodData *method = [GBMethodData propertyDataWithAttributes:attributes components:components];
+ // execute
+ NSArray *result = [method formattedComponents];
+ // verify: {@property}-{ }-{NSString}-{ }-{*}-{name}
+ [self assertFormattedComponents:result match:
+ @"@property", 0, GBNULL,
+ @" ", 0, GBNULL,
+ @"NSString", 0, GBNULL,
+ @" ", 0, GBNULL,
+ @"*", 0, GBNULL,
+ @"name", 0, GBNULL,
+ nil];
+}
+
- (void)testFormattedComponents_shouldReturnPointerPropertyComponents {
// setup
NSArray *attributes = [NSArray arrayWithObjects:@"readonly", nil];

0 comments on commit a4c88d7

Please sign in to comment.