Skip to content

Commit

Permalink
Store now registers all currently available top level objects to its …
Browse files Browse the repository at this point in the history
…arrays.
  • Loading branch information
tomaz committed Apr 20, 2012
1 parent b3e1aaa commit 0bfc786
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 15 deletions.
93 changes: 78 additions & 15 deletions AppledocTests/Store/StoreTests.m
Expand Up @@ -29,6 +29,11 @@ @implementation StoreTests
- (void)testLazyInitializationWorks {
[self runWithStore:^(Store *store) {
// execute & verify
assertThat(store.storeClasses, instanceOf([NSMutableArray class]));
assertThat(store.storeExtensions, instanceOf([NSMutableArray class]));
assertThat(store.storeCategories, instanceOf([NSMutableArray class]));
assertThat(store.storeProtocols, instanceOf([NSMutableArray class]));
assertThat(store.storeEnumerations, instanceOf([NSMutableArray class]));
assertThat(store.registrationStack, instanceOf([NSMutableArray class]));
}];
}
Expand All @@ -37,51 +42,99 @@ - (void)testLazyInitializationWorks {

- (void)testBeginClassWithNameDerivedFromClassWithNameShouldRegisterClassInfo {
[self runWithStore:^(Store *store) {
// setup & execute
[store beginClassWithName:@"Name" derivedFromClassWithName:@"Derived"];
// execute
[store beginClassWithName:@"name" derivedFromClassWithName:@"derived"];
// verify
assertThat(store.currentRegistrationObject, instanceOf([ClassInfo class]));
assertThat([store.currentRegistrationObject nameOfClass], equalTo(@"Name"));
assertThat([store.currentRegistrationObject nameOfSuperClass], equalTo(@"Derived"));
assertThat([store.currentRegistrationObject nameOfClass], equalTo(@"name"));
assertThat([store.currentRegistrationObject nameOfSuperClass], equalTo(@"derived"));
assertThat([store.currentRegistrationObject objectRegistrar], equalTo(store));
}];
}

- (void)testBeginClassWithNameDerivedFromClassWithNameShouldAddClassInfoToClassesArray {
[self runWithStore:^(Store *store) {
// execute
[store beginClassWithName:@"name" derivedFromClassWithName:@"derived"];
// verify
assertThatInt(store.storeClasses.count, equalToInt(1));
assertThat([store.storeClasses lastObject], equalTo(store.currentRegistrationObject));
}];
}

#pragma mark - Verify handling of extensions

- (void)testBeginExtensionForClassWithNameShouldRegisterCategoryInfo {
[self runWithStore:^(Store *store) {
// setup & execute
[store beginExtensionForClassWithName:@"Name"];
// execute
[store beginExtensionForClassWithName:@"name"];
// verify
assertThat(store.currentRegistrationObject, instanceOf([CategoryInfo class]));
assertThat([store.currentRegistrationObject nameOfClass], equalTo(@"Name"));
assertThat([store.currentRegistrationObject nameOfClass], equalTo(@"name"));
assertThat([store.currentRegistrationObject nameOfCategory], equalTo(nil));
assertThat([store.currentRegistrationObject objectRegistrar], equalTo(store));
}];
}

- (void)testBeginExtensionForClassWithNameShouldAddCategoryInfoToCategoriesArray {
[self runWithStore:^(Store *store) {
// execute
[store beginExtensionForClassWithName:@"name"];
// verify
assertThatInt(store.storeExtensions.count, equalToInt(1));
assertThat([store.storeExtensions lastObject], equalTo(store.currentRegistrationObject));
}];
}

#pragma mark - Verify handling of categories

- (void)testBeginCategoryWithNameForClassWithNameShouldRegisterCategoryInfo {
[self runWithStore:^(Store *store) {
// setup & execute
[store beginCategoryWithName:@"Category" forClassWithName:@"Name"];
// execute
[store beginCategoryWithName:@"category" forClassWithName:@"name"];
// verify
assertThat(store.currentRegistrationObject, instanceOf([CategoryInfo class]));
assertThat([store.currentRegistrationObject nameOfClass], equalTo(@"Name"));
assertThat([store.currentRegistrationObject nameOfCategory], equalTo(@"Category"));
assertThat([store.currentRegistrationObject nameOfClass], equalTo(@"name"));
assertThat([store.currentRegistrationObject nameOfCategory], equalTo(@"category"));
assertThat([store.currentRegistrationObject objectRegistrar], equalTo(store));
}];
}

- (void)testBeginCategoryWithNameForClassWithNameShouldAddCategoryInfoToCategoriesArray {
[self runWithStore:^(Store *store) {
// execute
[store beginCategoryWithName:@"category" forClassWithName:@"name"];
// verify
assertThatInt(store.storeCategories.count, equalToInt(1));
assertThat([store.storeCategories lastObject], equalTo(store.currentRegistrationObject));
}];
}

#pragma mark - Verify handling of protocols

- (void)testBeginProtocolWithNameShouldRegisterProtocolInfo {
[self runWithStore:^(Store *store) {
// setup & execute
[store beginProtocolWithName:@"Name"];
// execute
[store beginProtocolWithName:@"name"];
// verify
assertThat(store.currentRegistrationObject, instanceOf([ProtocolInfo class]));
assertThat([store.currentRegistrationObject nameOfProtocol], equalTo(@"Name"));
assertThat([store.currentRegistrationObject nameOfProtocol], equalTo(@"name"));
assertThat([store.currentRegistrationObject objectRegistrar], equalTo(store));
}];
}

- (void)testBeginProtocolWithNameShouldAddProtocolInfoToProtocolsArray {
[self runWithStore:^(Store *store) {
// execute
[store beginProtocolWithName:@"name"];
// verify
assertThatInt(store.storeProtocols.count, equalToInt(1));
assertThat([store.storeProtocols lastObject], equalTo(store.currentRegistrationObject));
}];
}

#pragma mark - Verify handling of interface related methods

- (void)testAppendAdoptedProtocolShouldForwardToCurrentObject {
[self runWithStore:^(Store *store) {
// setup
Expand Down Expand Up @@ -248,14 +301,24 @@ - (void)testAppendMethodArgumentVariableShouldForwardToCurrentObject {

- (void)testBeginEnumerationShouldRegisterEnumInfo {
[self runWithStore:^(Store *store) {
// setup & execute
// execute
[store beginEnumeration];
// verify
assertThat(store.currentRegistrationObject, instanceOf([EnumInfo class]));
assertThat([store.currentRegistrationObject objectRegistrar], equalTo(store));
}];
}

- (void)testBeginEnumerationShouldAddEnumInfoToEnumerationsArray {
[self runWithStore:^(Store *store) {
// execute
[store beginEnumeration];
// verify
assertThatInt(store.storeEnumerations.count, equalToInt(1));
assertThat([store.storeEnumerations lastObject], equalTo(store.currentRegistrationObject));
}];
}

- (void)testAppendEnumerationItemShouldForwardToCurrentObject {
[self runWithStore:^(Store *store) {
// setup
Expand Down
7 changes: 7 additions & 0 deletions appledoc/Store/Store.h
Expand Up @@ -32,4 +32,11 @@
@warning **Implementation detail:** Store is implemented in the way to make registration of various objects as easy as possible. Therefore it let's you build up the objects as data is parsed in. For each object there's corresponding begin method which you need to call prior to registering various data. After all data is collected, you should send `endCurrentObject` to actually register the object with the store. If you detect any inconsistency, you should send `cancelCurrentObject` to cancel further registrations. You can nest begin/end/cancel calls, but they need to be balanced: each begin must be followed by an end or cancel! Internally, Store uses a stack on which objects are added when they are started and removed once they are done or cancelled.
*/
@interface Store : NSObject <StoreRegistrar>

@property (nonatomic, strong) NSMutableArray *storeClasses;
@property (nonatomic, strong) NSMutableArray *storeExtensions;
@property (nonatomic, strong) NSMutableArray *storeCategories;
@property (nonatomic, strong) NSMutableArray *storeProtocols;
@property (nonatomic, strong) NSMutableArray *storeEnumerations;

@end
47 changes: 47 additions & 0 deletions appledoc/Store/Store.m
Expand Up @@ -18,6 +18,11 @@ @interface Store ()

@implementation Store

@synthesize storeClasses = _storeClasses;
@synthesize storeExtensions = _storeExtensions;
@synthesize storeCategories = _storeCategories;
@synthesize storeProtocols = _storeProtocols;
@synthesize storeEnumerations = _storeEnumerations;
@synthesize currentSourceInfo = _currentSourceInfo;
@synthesize registrationStack = _registrationStack;

Expand Down Expand Up @@ -63,6 +68,43 @@ - (NSMutableArray *)registrationStack {
return _registrationStack;
}

#pragma mark - Properties

- (NSMutableArray *)storeClasses {
if (_storeClasses) return _storeClasses;
LogStoDebug(@"Initializing store classes array due to first access...");
_storeClasses = [[NSMutableArray alloc] init];
return _storeClasses;
}

- (NSMutableArray *)storeExtensions {
if (_storeExtensions) return _storeExtensions;
LogStoDebug(@"Initializing store extensions array due to first access...");
_storeExtensions = [[NSMutableArray alloc] init];
return _storeExtensions;
}

- (NSMutableArray *)storeCategories {
if (_storeCategories) return _storeCategories;
LogStoDebug(@"Initializing store categories array due to first access...");
_storeCategories = [[NSMutableArray alloc] init];
return _storeCategories;
}

- (NSMutableArray *)storeProtocols {
if (_storeProtocols) return _storeProtocols;
LogStoDebug(@"Initializing store protocols array due to first access...");
_storeProtocols = [[NSMutableArray alloc] init];
return _storeProtocols;
}

- (NSMutableArray *)storeEnumerations {
if (_storeEnumerations) return _storeEnumerations;
LogStoDebug(@"Initializing store enumerations array due to first access...");
_storeEnumerations = [[NSMutableArray alloc] init];
return _storeEnumerations;
}

@end

#pragma mark -
Expand All @@ -76,6 +118,7 @@ - (void)beginClassWithName:(NSString *)name derivedFromClassWithName:(NSString *
ClassInfo *info = [[ClassInfo alloc] initWithRegistrar:self];
info.nameOfClass = name;
info.nameOfSuperClass = derived;
[self.storeClasses addObject:info];
[self pushRegistrationObject:info];
}

Expand All @@ -84,6 +127,7 @@ - (void)beginExtensionForClassWithName:(NSString *)name {
CategoryInfo *info = [[CategoryInfo alloc] initWithRegistrar:self];
info.nameOfClass = name;
info.nameOfCategory = nil;
[self.storeExtensions addObject:info];
[self pushRegistrationObject:info];
}

Expand All @@ -92,13 +136,15 @@ - (void)beginCategoryWithName:(NSString *)category forClassWithName:(NSString *)
CategoryInfo *info = [[CategoryInfo alloc] initWithRegistrar:self];
info.nameOfClass = name;
info.nameOfCategory = category;
[self.storeCategories addObject:info];
[self pushRegistrationObject:info];
}

- (void)beginProtocolWithName:(NSString *)name {
LogStoInfo(@"Starting protocol %@...", name);
ProtocolInfo *info = [[ProtocolInfo alloc] initWithRegistrar:self];
info.nameOfProtocol = name;
[self.storeProtocols addObject:info];
[self pushRegistrationObject:info];
}

Expand Down Expand Up @@ -185,6 +231,7 @@ - (void)appendMethodArgumentVariable:(NSString *)name {
- (void)beginEnumeration {
LogStoInfo(@"Starting enumeration...");
EnumInfo *info = [[EnumInfo alloc] initWithRegistrar:self];
[self.storeEnumerations addObject:info];
[self pushRegistrationObject:info];
}

Expand Down

0 comments on commit 0bfc786

Please sign in to comment.