Skip to content

Commit

Permalink
Handling property/method names all uppercase e.g. URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Blazej Marcinkiewicz committed Jul 11, 2014
1 parent 6c5eb4f commit 50bb930
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
45 changes: 45 additions & 0 deletions CDSymoblsGeneratorVisitorSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@
NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define _is%@ _is", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

context(@"when obfuscating setter for upprecase property", ^{
NSString *uppercaseName = @"URL";
CDOCProperty *upperCaseProperty = [[CDOCProperty alloc] initWithName:uppercaseName attributes:@""];
it(@"should not change first letter to lowercase", ^{
[visitor willBeginVisiting];

[visitor visitProperty:upperCaseProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"%@", [uppercaseName lowercaseFirstCharacter]]].location;
[[theValue(location) should] equal:theValue(NSNotFound)];
});
});
});

context(@"when obfuscating 'is' property", ^{
Expand Down Expand Up @@ -168,6 +183,21 @@
NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define _is%@ _is", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

context(@"when obfuscating setter for upprecase property", ^{
NSString *uppercaseName = @"URL";
CDOCProperty *upperCaseProperty = [[CDOCProperty alloc] initWithName:[@"is" stringByAppendingString:uppercaseName] attributes:@""];
it(@"should not change first letter to lowercase", ^{
[visitor willBeginVisiting];

[visitor visitProperty:upperCaseProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"%@", [uppercaseName lowercaseFirstCharacter]]].location;
[[theValue(location) should] equal:theValue(NSNotFound)];
});
});
});
});

Expand Down Expand Up @@ -205,6 +235,21 @@
NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define %@", methodName]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

context(@"for uppercase getter name", ^{
NSString *uppercaseName = @"URL";
CDOCMethod *upperCaseProperty = [[CDOCMethod alloc] initWithName:[@"set" stringByAppendingString:uppercaseName] typeString:nil];
it(@"should not change first letter to lowercase", ^{
[visitor willBeginVisiting];

[visitor visitInstanceMethod:upperCaseProperty propertyState:nil];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"%@", [uppercaseName lowercaseFirstCharacter]]].location;
[[theValue(location) should] equal:theValue(NSNotFound)];
});
});
});

context(@"when method is a getter", ^{
Expand Down
16 changes: 14 additions & 2 deletions Source/CDSymoblsGeneratorVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ - (bool)isInitMethod:(NSString *)symbolName {
- (NSString *)getterNameForMethodName:(NSString *)methodName {
NSString *setterPrefix = @"set";
if ([methodName hasPrefix:setterPrefix] && ![methodName isEqualToString:setterPrefix]) {
return [[methodName stringByReplacingCharactersInRange:NSMakeRange(0, setterPrefix.length) withString:@""] lowercaseFirstCharacter];
NSString *string = [methodName stringByReplacingCharactersInRange:NSMakeRange(0, setterPrefix.length) withString:@""];
// If getter method name is all upper case then don't change first letter to lower case e.g. URL should remain URL, not uRL
if ([string isEqualToString:[string uppercaseString]]) {
return string;
} else {
return [string lowercaseFirstCharacter];
}
} else {
return methodName;
}
Expand Down Expand Up @@ -265,7 +271,13 @@ - (NSString *)isIvarPropertyName:(NSString *)propertyName {

- (NSString *)plainGetterName:(NSString *)propertyName {
if ([propertyName hasPrefix:@"is"] && ![propertyName isEqualToString:@"is"]) {
return [[propertyName stringByReplacingCharactersInRange:NSMakeRange(0, 2) withString:@""] lowercaseFirstCharacter];
NSString *string = [propertyName stringByReplacingCharactersInRange:NSMakeRange(0, 2) withString:@""];
// If property name is all upper case then don't change first letter to lower case e.g. URL should remain URL, not uRL
if ([string isEqualToString:[string uppercaseString]]) {
return string;
} else {
return [string lowercaseFirstCharacter];
}
} else {
return propertyName;
}
Expand Down

0 comments on commit 50bb930

Please sign in to comment.