Skip to content

Commit

Permalink
Merge pull request Polidea#1 from marcinkiewiczblazej/property-name-d…
Browse files Browse the repository at this point in the history
…eduction

Better property/method names deduction
  • Loading branch information
ayufan committed Jul 11, 2014
2 parents 1bded38 + 50bb930 commit ec89f17
Show file tree
Hide file tree
Showing 16 changed files with 680 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
xcuserdata
*.xcarchive/
.idea
Pods
274 changes: 274 additions & 0 deletions CDSymoblsGeneratorVisitorSpec.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
#import <Kiwi/Kiwi.h>

#import "CDSymoblsGeneratorVisitor.h"
#import "CDOCProperty.h"
#import "NSString-CDExtensions.h"
#import "CDOCMethod.h"

SPEC_BEGIN(CDSymoblsGeneratorVisitorSpec)

describe(@"CDSymoblsGeneratorVisitor", ^{
__block CDSymoblsGeneratorVisitor *visitor;

beforeEach(^{
visitor = [[CDSymoblsGeneratorVisitor alloc] init];
});

describe(@"visiting property", ^{

NSString *propertyName = @"propertyName";
CDOCProperty *aProperty = [[CDOCProperty alloc] initWithName:propertyName attributes:@""];

context(@"when obfuscating plain property", ^{
it(@"should generate symbol for default getter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:aProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define %@", propertyName]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for default setter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:aProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define set%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for iVar", ^{
[visitor willBeginVisiting];

[visitor visitProperty:aProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define _%@", propertyName]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for 'is' property getter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:aProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define is%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});


it(@"should generate symbol for 'setIs' setter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:aProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define setIs%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for 'setIs' iVar", ^{
[visitor willBeginVisiting];

[visitor visitProperty:aProperty];

[visitor didEndVisiting];

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", ^{
CDOCProperty *isProperty = [[CDOCProperty alloc] initWithName:[@"is" stringByAppendingString:[propertyName capitalizeFirstCharacter]] attributes:@""];

it(@"should generate symbol for default getter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define %@", propertyName]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for default setter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define set%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for iVar", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define _%@", propertyName]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for 'is' property getter", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define is%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});


it(@"should generate symbol for plain setter for 'is' property", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define set%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for 'setIs' setter for 'is' property", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define setIs%@", [propertyName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

it(@"should generate symbol for 'setIs' setter for 'is' property", ^{
[visitor willBeginVisiting];

[visitor visitProperty:isProperty];

[visitor didEndVisiting];

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)];
});
});
});
});

describe(@"visiting method", ^{
NSString *methodName = @"methodName";
__block CDOCMethod *method;

beforeEach(^{
method = [[CDOCMethod alloc] initWithName:methodName typeString:@""];
});

it(@"should generate symbol for method", ^{
[visitor willBeginVisiting];

[visitor visitInstanceMethod:method propertyState:nil];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define %@", methodName]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});

context(@"when method is a setter", ^{
beforeEach(^{
method = [[CDOCMethod alloc] initWithName:[@"set" stringByAppendingString:[methodName capitalizeFirstCharacter]] typeString:nil];
});

it(@"should generate symbol for getter", ^{
[visitor willBeginVisiting];

[visitor visitInstanceMethod:method propertyState:nil];

[visitor didEndVisiting];

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", ^{
beforeEach(^{
method = [[CDOCMethod alloc] initWithName:methodName typeString:nil];
});

it(@"should generate symbol for setter", ^{
[visitor willBeginVisiting];

[visitor visitInstanceMethod:method propertyState:nil];

[visitor didEndVisiting];

NSInteger location = [visitor.resultString rangeOfString:[NSString stringWithFormat:@"#define set%@", [methodName capitalizeFirstCharacter]]].location;
[[theValue(location) shouldNot] equal:theValue(NSNotFound)];
});
});
});
});

SPEC_END
3 changes: 3 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target :UnitTests do
pod 'Kiwi/XCTest'
end
14 changes: 14 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PODS:
- Kiwi/ARC (2.2.4)
- Kiwi/NonARC (2.2.4)
- Kiwi/XCTest (2.2.4):
- Kiwi/ARC
- Kiwi/NonARC

DEPENDENCIES:
- Kiwi/XCTest

SPEC CHECKSUMS:
Kiwi: c73667f2b84cbf36f1a3830267c5a4ae8dcbd8ba

COCOAPODS: 0.33.1
14 changes: 14 additions & 0 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Source/CDSymoblsGeneratorVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
@interface CDSymoblsGeneratorVisitor : CDVisitor
@property (nonatomic, copy) NSArray *classFilter;
@property (nonatomic, copy) NSArray *ignoreSymbols;
@end
@property (nonatomic, readonly) NSString *resultString;
@end
Loading

0 comments on commit ec89f17

Please sign in to comment.