Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

626 lines (569 sloc) 33.175 kb
//
// GBObjectiveCParser-MethodsParsingTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 25.7.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBStore.h"
#import "GBDataObjects.h"
#import "GBObjectiveCParser.h"
// Note that we use class for invoking parsing of methods. Probably not the best option - i.e. we could isolate method parsing code altogether and only parse relevant stuff here, but it seemed not much would be gained by doing this. Separating unit tests does avoid repetition in top-level objects testing code - we only need to test specific data there.
@interface GBObjectiveCParserMethodsParsingTesting : GBObjectsAssertor
@end
@implementation GBObjectiveCParserMethodsParsingTesting
#pragma mark Method definitions parsing
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionWithNoArguments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)method; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionWithArguments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)method:(NSString*)var; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"NSString", @"*", @"var", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionWithMutlipleArguments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)arg1:(int)var1 arg2:(long)var2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"arg1", @"int", @"var1", @"arg2", @"long", @"var2", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionBlockArgument {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)method:(void (^)(id obj, NSUInteger idx))block; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"void", @"(", @"^", @")", @"(", @"id", @"obj", @",", @"NSUInteger", @"idx", @")", @"block", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionVariableArgsArgument {
/* Removing this test as it was failing, no time to check it more in depth; var args works when generating html, so may simply be the case of invalid verification...
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)method:(id)first,...; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"id", @"first", @"...", nil];
*/
}
- (void)testParseObjectsFromString_shouldRegisterAllMethodDefinitions {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)method1; +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(2));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method1", nil];
[self assertMethod:[methods objectAtIndex:1] matchesClassComponents:@"void", @"method2", nil];
}
- (void)testParseObjectsFromString_shouldHandleAttributeDirectiveForMethods {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface Class - (void)method __attribute__((anything 00 ~!@#$%^&*)); @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"void", @"method", nil];
}
- (void)testParseObjectsFromString_shouldHandlePragmaMarkBeforeMethod {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface Class\n\n#pragma mark -\n/** comment */\n-(void)method; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"void", @"method", nil];
assertThat([(GBComment *)[[methods objectAtIndex:0] comment] stringValue], is(@"comment"));
}
- (void)testParseObjectsFromString_shouldHandlePragmaMarkBeforeProperty {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface Class\n\n#pragma mark -\n/** comment */\n@property (readonly) int value; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"value", nil];
assertThat([(GBComment *)[[methods objectAtIndex:0] comment] stringValue], is(@"comment"));
}
#pragma mark Method declarations parsing
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationWithNoArguments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method { } @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationWithArguments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method:(NSString*)var { } @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"NSString", @"*", @"var", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationWithMutlipleArguments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)arg1:(int)var1 arg2:(long)var2 { } @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"arg1", @"int", @"var1", @"arg2", @"long", @"var2", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationBlockArgument {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method:(void (^)(id obj, NSUInteger idx))block{} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"void", @"(", @"^", @")", @"(", @"id", @"obj", @",", @"NSUInteger", @"idx", @")", @"block", nil];
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationVariableArgsArgument {
/* Removing this test as it was failing, no time to check it more in depth; var args works when generating html, so may simply be the case of invalid verification...
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method:(id)first,...{} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"id", @"first", @"...", nil];
*/
}
- (void)testParseObjectsFromString_shouldRegisterAllMethodDeclarations {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method1{} +(void)method2{} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(2));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method1", nil];
[self assertMethod:[methods objectAtIndex:1] matchesClassComponents:@"void", @"method2", nil];
}
- (void)testParseObjectsFromString_shouldIgnoreMethodDeclarationSemicolon {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method; {} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
}
- (void)testParseObjectsFromString_shouldIgnoreMethodDeclarationNestedCode {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method { if (_var) { if(a>b) { [self quit]; } else { MY_MACRO(_var); } } } @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
}
#pragma mark Properties parsing testing
- (void)testParseObjectsFromString_shouldRegisterSimplePropertyDefinition {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass @property(readonly) int name; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"name", nil];
}
- (void)testParseObjectsFromString_shouldRegisterComplexPropertyDefinition {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass @property(retain,nonatomic) IBOutlet NSString *name; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"retain", @"nonatomic", @"IBOutlet", @"NSString", @"*", @"name", nil];
}
- (void)testParseObjectsFromString_shouldRegisterComplexPropertyDefinition2 {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass @property (weak) IBOutlet id<Protocol> delegate; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"weak", @"IBOutlet", @"id", @"<", @"Protocol", @">", @"delegate", nil];
}
- (void)testParseObjectsFromString_shouldRegisterBlockPropertyDefinition {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass @property (retain) void (^name)(id, NSUInteger); @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"retain", @"void", @"(", @"^", @")", @"(", @"id", @",", @"NSUInteger", @")", @"name", nil];
}
- (void)testParseObjectsFromString_shouldRegisterAllPropertyDefinitions {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass @property(readonly) int name1; @property(readwrite)long name2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(2));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"name1", nil];
[self assertMethod:[methods objectAtIndex:1] matchesPropertyComponents:@"readwrite", @"long", @"name2", nil];
}
- (void)testParseObjectsFromString_shouldHandleAttributeDirectiveForProperties {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface Class @property (readonly) int name __attribute__((anything 00 ~!@#$%^&*)); @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"name", nil];
}
#pragma mark Methods & properties required/optional parsing
- (void)testParseObjectsFromString_shouldRegisterRequiredMethodDefinitionForProtocols {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@protocol Protocol -(id)m1; -(id)m2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBProtocolData *protocol = [[store protocols] anyObject];
NSArray *methods = [[protocol methods] methods];
assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(YES));
}
- (void)testParseObjectsFromString_shouldRegisterOptionalMethodDefinitionForProtocols {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@protocol Protocol @optional -(id)m1; -(id)m2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBProtocolData *protocol = [[store protocols] anyObject];
NSArray *methods = [[protocol methods] methods];
assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(NO));
assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
}
- (void)testParseObjectsFromString_shouldRegisterMixedRequiredOptionalMethodDefinitionForProtocols {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@protocol Protocol -(id)m1; @optional -(id)m2; @required -(id)m3; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBProtocolData *protocol = [[store protocols] anyObject];
NSArray *methods = [[protocol methods] methods];
assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
assertThatBool([[methods objectAtIndex:2] isRequired], equalToBool(YES));
}
- (void)testParseObjectsFromString_shouldRegisterRequiredPropertyDefinitionForProtocols {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@protocol Protocol @property(readonly)int p1; @property(readonly)int p2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBProtocolData *protocol = [[store protocols] anyObject];
NSArray *methods = [[protocol methods] methods];
assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(YES));
}
- (void)testParseObjectsFromString_shouldRegisterOptionalPropertyDefinitionForProtocols {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@protocol Protocol @optional @property(readonly)int p1; @property(readonly)int p2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBProtocolData *protocol = [[store protocols] anyObject];
NSArray *methods = [[protocol methods] methods];
assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(NO));
assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
}
- (void)testParseObjectsFromString_shouldRegisterMixedRequiredOptionalPropertyDefinitionForProtocols {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@protocol Protocol @property(readonly)int p1; @optional @property(readonly)int p2; @required @property(readonly)int p3; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBProtocolData *protocol = [[store protocols] anyObject];
NSArray *methods = [[protocol methods] methods];
assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
assertThatBool([[methods objectAtIndex:2] isRequired], equalToBool(YES));
}
#pragma mark Methods & properties extras parsing
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionSourceFileAndLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass -(id)method; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
NSSet *files = [method sourceInfos];
assertThatInteger([files count], equalToInteger(1));
assertThat([[files anyObject] filename], is(@"filename.h"));
assertThatInteger([[files anyObject] lineNumber], equalToInteger(1));
}
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionProperLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"// comment\n#define SOMETHING\n\n@interface MyClass\n\n-(id)method; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
NSSet *files = [method sourceInfos];
assertThatInteger([[files anyObject] lineNumber], equalToInteger(6));
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationSourceFileAndLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass -(id)method {} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
NSSet *files = [method sourceInfos];
assertThatInteger([files count], equalToInteger(1));
assertThat([[files anyObject] filename], is(@"filename.h"));
assertThatInteger([[files anyObject] lineNumber], equalToInteger(1));
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationProperLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"// comment\n#define SOMETHING\n\n@implementation MyClass\n\n-(id)method {} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
NSSet *files = [method sourceInfos];
assertThatInteger([[files anyObject] lineNumber], equalToInteger(6));
}
- (void)testParseObjectsFromString_shouldRegisterProperyDefinitionSourceFileAndLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass @property(readonly)int p1; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
NSSet *files = [method sourceInfos];
assertThatInteger([files count], equalToInteger(1));
assertThat([[files anyObject] filename], is(@"filename.h"));
assertThatInteger([[files anyObject] lineNumber], equalToInteger(1));
}
- (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionProperLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"// comment\n#define SOMETHING\n\n@interface MyClass\n\n@property(readonly)int p1; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
NSSet *files = [method sourceInfos];
assertThatInteger([[files anyObject] lineNumber], equalToInteger(6));
}
#pragma mark Method & properties comments parsing
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionComment {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ -(id)method1; /** Comment2 */ +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
}
- (void)testParseObjectsFromString_shouldProperlyResetMethodComments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ -(id)method1; +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
assertThat([(GBModelBase *)[methods objectAtIndex:1] comment], is(nil));
}
- (void)testParseObjectsFromString_shouldProperlyResetPropertyComments {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ @property (readonly) id value; +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
assertThat([(GBModelBase *)[methods objectAtIndex:1] comment], is(nil));
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationComment {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@implementation MyClass /** Comment1 */ -(id)method1{} /** Comment2 */ +(void)method2{} @end" sourceFile:@"filename.m" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
}
- (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionComment {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ @property(readonly)NSInteger p1; /** Comment2 */ @property(readonly)NSInteger p2; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
}
- (void)testParseObjectsFromString_shouldRegisterMethodDefinitionCommentSourceFileAndLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n/** comment */\n-(void)method; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
}
- (void)testParseObjectsFromString_shouldRegisterMethodDeclarationCommentProperSourceLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@implementation MyClass\n/** comment */\n-(void)method{} @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
}
- (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionCommentSourceFileAndLineNumber {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n/** comment */\n@property(readonly)int p1; @end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
}
#pragma mark Various cases
- (void)testParseObjectsFromString_shouldSkipAnythingNotMethod {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
// execute
[parser parseObjectsFromString:
@"@interface MyClass\n"
@"#pragma mark -\n"
@"#pragma mark Something\n"
@"/** comment */\n"
@"-(void)method;\n"
@"@end" sourceFile:@"filename.h" toStore:store];
// verify
GBClassData *class = [[store classes] anyObject];
NSArray *methods = [[class methods] methods];
GBMethodData *method = [methods objectAtIndex:0];
assertThatInteger([methods count], equalToInteger(1));
[self assertMethod:method matchesInstanceComponents:@"void", @"method", nil];
assertThat(method.comment.stringValue, is(@"comment"));
}
@end
Jump to Line
Something went wrong with that request. Please try again.