diff --git a/GBCommentsProcessor.m b/GBCommentsProcessor.m index 57f424f1..983fe427 100644 --- a/GBCommentsProcessor.m +++ b/GBCommentsProcessor.m @@ -18,6 +18,8 @@ - (void)registerUnorderedListFromString:(NSString *)string toParagraph:(GBCommen - (void)registerOrderedListFromString:(NSString *)string toParagraph:(GBCommentParagraph *)paragraph; - (void)registerListFromString:(NSString *)string ordered:(BOOL)ordered usingRegex:(NSString *)regex toParagraph:(GBCommentParagraph *)paragraph; - (void)registerWarningFromString:(NSString *)string toParagraph:(GBCommentParagraph *)paragraph; +- (void)registerBugFromString:(NSString *)string toParagraph:(GBCommentParagraph *)paragraph; +- (void)registerSpecialFromString:(NSString *)string type:(GBSpecialItemType)type usingRegex:(NSString *)regex toParagraph:(GBCommentParagraph *)paragraph; - (void)registerTextFromString:(NSString *)string toParagraph:(GBCommentParagraph *)paragraph; - (NSArray *)componentsSeparatedByEmptyLinesFromString:(NSString *)string; - (NSArray *)componentsSeparatedByNewLinesFromString:(NSString *)string; @@ -81,6 +83,10 @@ - (void)processComment:(GBComment *)comment withStore:(id)store { GBRegister([self registerWarningFromString:component toParagraph:currentParagraph]); return; } + if ([component isMatchedByRegex:componizer.bugSectionRegex]) { + GBRegister([self registerBugFromString:component toParagraph:currentParagraph]); + return; + } // If no other match was found, this is simple text, so start new paragraph. currentParagraph = [GBCommentParagraph paragraph]; @@ -124,16 +130,24 @@ - (void)registerListFromString:(NSString *)string ordered:(BOOL)ordered usingReg #pragma mark Processing special items - (void)registerWarningFromString:(NSString *)string toParagraph:(GBCommentParagraph *)paragraph { + [self registerSpecialFromString:string type:GBSpecialItemTypeWarning usingRegex:self.settings.commentComponents.warningSectionRegex toParagraph:paragraph]; +} + +- (void)registerBugFromString:(NSString *)string toParagraph:(GBCommentParagraph *)paragraph { + [self registerSpecialFromString:string type:GBSpecialItemTypeBug usingRegex:self.settings.commentComponents.bugSectionRegex toParagraph:paragraph]; +} + +- (void)registerSpecialFromString:(NSString *)string type:(GBSpecialItemType)type usingRegex:(NSString *)regex toParagraph:(GBCommentParagraph *)paragraph { // Get the description from the string. If empty, warn and exit. NSString *trimmed = [string stringByReplacingOccurrencesOfRegex:self.spaceAndNewLineTrimRegex withString:@""]; - NSString *description = [trimmed stringByMatching:self.settings.commentComponents.warningSectionRegex capture:1]; + NSString *description = [trimmed stringByMatching:regex capture:1]; if ([description length] == 0) { - GBLogWarn(@"Empty warning section found!"); + GBLogWarn(@"Empty special section of type %ld found!", type); return; } // Prepare paragraph item and process the text. - GBParagraphSpecialItem *item = [GBParagraphSpecialItem specialItemWithType:GBSpecialItemTypeWarning stringValue:trimmed]; + GBParagraphSpecialItem *item = [GBParagraphSpecialItem specialItemWithType:type stringValue:trimmed]; GBCommentParagraph *para = [GBCommentParagraph paragraph]; [self registerTextFromString:description toParagraph:para]; [item registerParagraph:para]; diff --git a/Testing/GBCommentsProcessor-BugsTesting.m b/Testing/GBCommentsProcessor-BugsTesting.m new file mode 100644 index 00000000..fa28a83a --- /dev/null +++ b/Testing/GBCommentsProcessor-BugsTesting.m @@ -0,0 +1,64 @@ +// +// GBCommentsProcessor-BugsTesting.m +// appledoc +// +// Created by Tomaz Kragelj on 1.9.10. +// Copyright (C) 2010 Gentle Bytes. All rights reserved. +// + +#import "GBComment.h" +#import "GBCommentsProcessor.h" + +@interface GBCommentsProcessorBugsTesting : GBObjectsAssertor +@end + +#pragma mark - + +@implementation GBCommentsProcessorBugsTesting + +- (void)testProcessCommentWithStore_bugs_shouldAttachBugToPreviousParagraph { + // setup + GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]]; + GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n@bug Description"]; + // execute + [processor processComment:comment withStore:[GBTestObjectsRegistry store]]; + // verify + assertThatInteger([comment.paragraphs count], equalToInteger(1)); + GBCommentParagraph *paragraph = comment.firstParagraph; + [self assertParagraph:paragraph containsItems:[GBParagraphTextItem class], @"Paragraph", [GBParagraphSpecialItem class], [NSNull null], nil]; + GBParagraphSpecialItem *item = [paragraph.items objectAtIndex:1]; + assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeBug)); + [self assertParagraph:item.description containsItems:[GBParagraphTextItem class], @"Description", nil]; +} + +- (void)testProcessCommentWithStore_bugs_shouldDetectMultipleLinesDescriptions { + // setup + GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]]; + GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n@bug Line1\nLine2"]; + // execute + [processor processComment:comment withStore:[GBTestObjectsRegistry store]]; + // verify + assertThatInteger([[comment paragraphs] count], equalToInteger(1)); + GBCommentParagraph *paragraph = comment.firstParagraph; + [self assertParagraph:paragraph containsItems:[GBParagraphTextItem class], @"Paragraph", [GBParagraphSpecialItem class], [NSNull null], nil]; + GBParagraphSpecialItem *item = [paragraph.items objectAtIndex:1]; + assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeBug)); + [self assertParagraph:item.description containsItems:[GBParagraphTextItem class], @"Line1 Line2", nil]; +} + +- (void)testProcessCommentWithStore_bugs_shouldCreateParagraphIfNoneSpecifiedBefore { + // setup + GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]]; + GBComment *comment = [GBComment commentWithStringValue:@"@bug Description"]; + // execute + [processor processComment:comment withStore:[GBTestObjectsRegistry store]]; + // verify + assertThatInteger([[comment paragraphs] count], equalToInteger(1)); + GBCommentParagraph *paragraph = comment.firstParagraph; + [self assertParagraph:paragraph containsItems:[GBParagraphSpecialItem class], [NSNull null], nil]; + GBParagraphSpecialItem *item = [paragraph.items objectAtIndex:0]; + assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeBug)); + [self assertParagraph:item.description containsItems:[GBParagraphTextItem class], @"Description", nil]; +} + +@end diff --git a/appledoc.xcodeproj/project.pbxproj b/appledoc.xcodeproj/project.pbxproj index 3c96b062..e318d46e 100644 --- a/appledoc.xcodeproj/project.pbxproj +++ b/appledoc.xcodeproj/project.pbxproj @@ -82,6 +82,7 @@ 7340F02911FCC63100E712A4 /* NSObject+GBObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 7340F02711FCC63100E712A4 /* NSObject+GBObject.m */; }; 7367B84E11FEF496005ED6CD /* GBCategoryData.m in Sources */ = {isa = PBXBuildFile; fileRef = 7367B84D11FEF496005ED6CD /* GBCategoryData.m */; }; 7367BB3612003CAB005ED6CD /* GBModelBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 7367BB3512003CAB005ED6CD /* GBModelBase.m */; }; + 73AAACD2122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m in Sources */ = {isa = PBXBuildFile; fileRef = 73AAACD1122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m */; }; 73CF8131122D3824005B7E26 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF8130122D3824005B7E26 /* RegexKitLite.m */; }; 73CF8132122D3824005B7E26 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF8130122D3824005B7E26 /* RegexKitLite.m */; }; 73CF81D3122D72ED005B7E26 /* GBParagraphTextItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF81D2122D72ED005B7E26 /* GBParagraphTextItem.m */; }; @@ -164,6 +165,7 @@ 7367BB5112004058005ED6CD /* GBModelBaseTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBModelBaseTesting.m; sourceTree = ""; }; 7367BBB612004928005ED6CD /* GBCategoryDataTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBCategoryDataTesting.m; sourceTree = ""; }; 7367BC4212005888005ED6CD /* GBDataObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBDataObjects.h; sourceTree = ""; }; + 73AAACD1122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GBCommentsProcessor-BugsTesting.m"; sourceTree = ""; }; 73CF8130122D3824005B7E26 /* RegexKitLite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegexKitLite.m; sourceTree = ""; }; 73CF81D1122D72ED005B7E26 /* GBParagraphTextItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBParagraphTextItem.h; sourceTree = ""; }; 73CF81D2122D72ED005B7E26 /* GBParagraphTextItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBParagraphTextItem.m; sourceTree = ""; }; @@ -579,6 +581,7 @@ 73329895122E4DFC00AEBA2B /* GBCommentsProcessor-UnorderedListsTesting.m */, 73329AA5122E8AA800AEBA2B /* GBCommentsProcessor-OrderedListsTesting.m */, 73329B2F122EE14900AEBA2B /* GBCommentsProcessor-WarningsTesting.m */, + 73AAACD1122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m */, ); name = Processing; sourceTree = ""; @@ -841,6 +844,7 @@ 73329AA6122E8AA800AEBA2B /* GBCommentsProcessor-OrderedListsTesting.m in Sources */, 73329B30122EE14900AEBA2B /* GBCommentsProcessor-WarningsTesting.m in Sources */, 73329B33122EE18C00AEBA2B /* GBParagraphSpecialItem.m in Sources */, + 73AAACD2122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };