Permalink
Browse files

Fixed overview output generation in cases where comment has no text.

As template only checks whether the comment is present, empty comments resulted in overview title being added to HTML without any accompanying text. These situations are properly handled now by removing such comments while processing.
  • Loading branch information...
1 parent e115064 commit a239c10c5d4c6e5344edbf46369da242a0aa63c1 @tomaz committed Dec 23, 2010
Showing with 68 additions and 8 deletions.
  1. +13 −8 Processing/GBProcessor.m
  2. +55 −0 Testing/GBProcessor-CommentsTesting.m
View
@@ -1,3 +1,4 @@
+
//
// GBProcessor.m
// appledoc
@@ -18,7 +19,7 @@ - (void)processClasses;
- (void)processCategories;
- (void)processProtocols;
- (void)processMethodsFromProvider:(GBMethodsProvider *)provider;
-- (void)processComment:(GBComment *)comment;
+- (void)processCommentForObject:(GBModelBase *)object;
- (void)processParametersFromComment:(GBComment *)comment matchingMethod:(GBMethodData *)method;
- (void)processHtmlReferencesForObject:(GBModelBase *)object;
- (void)copyKnownDocumentationForMethod:(GBMethodData *)method;
@@ -81,7 +82,7 @@ - (void)processClasses {
GBLogInfo(@"Processing class %@...", class);
self.currentContext = class;
[self validateCommentForObject:class];
- [self processComment:class.comment];
+ [self processCommentForObject:class];
[self processMethodsFromProvider:class.methods];
[self removeUndocumentedMembersAndObject:class];
[self processHtmlReferencesForObject:class];
@@ -95,7 +96,7 @@ - (void)processCategories {
GBLogInfo(@"Processing category %@...", category);
self.currentContext = category;
[self validateCommentForObject:category];
- [self processComment:category.comment];
+ [self processCommentForObject:category];
[self processMethodsFromProvider:category.methods];
[self removeUndocumentedMembersAndObject:category];
[self processHtmlReferencesForObject:category];
@@ -109,7 +110,7 @@ - (void)processProtocols {
GBLogInfo(@"Processing protocol %@...", protocol);
self.currentContext = protocol;
[self validateCommentForObject:protocol];
- [self processComment:protocol.comment];
+ [self processCommentForObject:protocol];
[self processMethodsFromProvider:protocol.methods];
[self removeUndocumentedMembersAndObject:protocol];
[self processHtmlReferencesForObject:protocol];
@@ -124,7 +125,7 @@ - (void)processMethodsFromProvider:(GBMethodsProvider *)provider {
GBLogVerbose(@"Processing method %@...", method);
[self copyKnownDocumentationForMethod:method];
[self validateCommentForObject:method];
- [self processComment:method.comment];
+ [self processCommentForObject:method];
[self processParametersFromComment:method.comment matchingMethod:method];
[self processHtmlReferencesForObject:method];
GBLogDebug(@"Finished processing method %@.", method);
@@ -137,9 +138,13 @@ - (void)processHtmlReferencesForObject:(GBModelBase *)object {
object.htmlLocalReference = [self.settings htmlReferenceForObject:object fromSource:object];
}
-- (void)processComment:(GBComment *)comment {
- if (![self isCommentValid:comment]) return;
- [self.commentsProcessor processComment:comment withContext:self.currentContext store:self.store];
+- (void)processCommentForObject:(GBModelBase *)object {
+ // Processes the comment for the given object. If the comment is not valid, it's forced to nil to make simpler work for template engine later on. Note that comment is considered invalid if the object isn't commented or has comment, but it's string value is nil or empty string.
+ if (![self isCommentValid:object.comment]) {
+ object.comment = nil;
+ return;
+ }
+ [self.commentsProcessor processComment:object.comment withContext:self.currentContext store:self.store];
}
- (void)processParametersFromComment:(GBComment *)comment matchingMethod:(GBMethodData *)method {
@@ -12,6 +12,7 @@
@interface GBProcessorCommentsTesting : GHTestCase
+- (OCMockObject *)mockSettingsProviderKeepObject:(BOOL)objects members:(BOOL)members;
- (OCMockObject *)niceCommentMockExpectingRegisterParagraph;
@end
@@ -49,6 +50,17 @@ - (void)testProcessObjectsFromStore_shouldProcessClassMethodComments {
[comment2 verify];
}
+- (void)testProcessObjectsFromStore_shouldSetEmptyClassCommentToNil {
+ // setup
+ GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
+ GBComment *comment = [GBComment commentWithStringValue:nil];
+ GBStore *store = [GBTestObjectsRegistry storeWithClassWithComment:comment];
+ // execute
+ [processor processObjectsFromStore:store];
+ // verify
+ assertThat([[store.classes anyObject] comment], is(nil));
+}
+
#pragma mark Categories comments processing
- (void)testProcessObjectsFromStore_shouldProcessCategoryComments {
@@ -78,6 +90,17 @@ - (void)testProcessObjectsFromStore_shouldProcessCategoryMethodComments {
[comment2 verify];
}
+- (void)testProcessObjectsFromStore_shouldSetEmptyCategoryCommentToNil {
+ // setup
+ GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
+ GBComment *comment = [GBComment commentWithStringValue:nil];
+ GBStore *store = [GBTestObjectsRegistry storeWithCategoryWithComment:comment];
+ // execute
+ [processor processObjectsFromStore:store];
+ // verify
+ assertThat([[store.categories anyObject] comment], is(nil));
+}
+
#pragma mark Protocols comments processing
- (void)testProcessObjectsFromStore_shouldProcessProtocolComments {
@@ -107,6 +130,17 @@ - (void)testProcessObjectsFromStore_shouldProcessProtocolMethodComments {
[comment2 verify];
}
+- (void)testProcessObjectsFromStore_shouldSetEmptyProtocolCommentToNil {
+ // setup
+ GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
+ GBComment *comment = [GBComment commentWithStringValue:nil];
+ GBStore *store = [GBTestObjectsRegistry storeWithProtocolWithComment:comment];
+ // execute
+ [processor processObjectsFromStore:store];
+ // verify
+ assertThat([[store.protocols anyObject] comment], is(nil));
+}
+
#pragma mark Method comment processing
- (void)testProcesObjectsFromStore_shouldMatchParameterDirectivesWithActualOrder {
@@ -130,8 +164,29 @@ - (void)testProcesObjectsFromStore_shouldMatchParameterDirectivesWithActualOrder
assertThat([[[comment.parameters objectAtIndex:2] argumentDescription] stringValue], is(@"Description3"));
}
+- (void)testProcessObjectsFromStore_shouldSetEmptyMethodCommentToNil {
+ // setup
+ GBProcessor *processor = [GBProcessor processorWithSettingsProvider:[self mockSettingsProviderKeepObject:YES members:YES]];
+ GBComment *comment = [GBComment commentWithStringValue:nil];
+ GBClassData *class = [GBClassData classDataWithName:@"Class"];
+ GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"arg1", @"arg2", @"arg3", nil];
+ [method setComment:comment];
+ [class.methods registerMethod:method];
+ GBStore *store = [GBTestObjectsRegistry storeByPerformingSelector:@selector(registerClass:) withObject:class];
+ // execute
+ [processor processObjectsFromStore:store];
+ // verify
+ assertThat(method.comment, is(nil));
+}
+
#pragma mark Creation methods
+- (OCMockObject *)mockSettingsProviderKeepObject:(BOOL)objects members:(BOOL)members {
+ OCMockObject *result = [GBTestObjectsRegistry mockSettingsProvider];
+ [GBTestObjectsRegistry settingsProvider:result keepObjects:objects keepMembers:members];
+ return result;
+}
+
- (OCMockObject *)niceCommentMockExpectingRegisterParagraph {
OCMockObject *result = [OCMockObject niceMockForClass:[GBComment class]];
[[[result stub] andReturn:@"Paragraph"] stringValue];

0 comments on commit a239c10

Please sign in to comment.