Skip to content

Commit

Permalink
Implemented bug section processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz committed Sep 2, 2010
1 parent 5ac13ea commit e6c6782
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
20 changes: 17 additions & 3 deletions GBCommentsProcessor.m
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
64 changes: 64 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions appledoc.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -164,6 +165,7 @@
7367BB5112004058005ED6CD /* GBModelBaseTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBModelBaseTesting.m; sourceTree = "<group>"; };
7367BBB612004928005ED6CD /* GBCategoryDataTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBCategoryDataTesting.m; sourceTree = "<group>"; };
7367BC4212005888005ED6CD /* GBDataObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBDataObjects.h; sourceTree = "<group>"; };
73AAACD1122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GBCommentsProcessor-BugsTesting.m"; sourceTree = "<group>"; };
73CF8130122D3824005B7E26 /* RegexKitLite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegexKitLite.m; sourceTree = "<group>"; };
73CF81D1122D72ED005B7E26 /* GBParagraphTextItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBParagraphTextItem.h; sourceTree = "<group>"; };
73CF81D2122D72ED005B7E26 /* GBParagraphTextItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBParagraphTextItem.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -579,6 +581,7 @@
73329895122E4DFC00AEBA2B /* GBCommentsProcessor-UnorderedListsTesting.m */,
73329AA5122E8AA800AEBA2B /* GBCommentsProcessor-OrderedListsTesting.m */,
73329B2F122EE14900AEBA2B /* GBCommentsProcessor-WarningsTesting.m */,
73AAACD1122F8E8B00EAF358 /* GBCommentsProcessor-BugsTesting.m */,
);
name = Processing;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit e6c6782

Please sign in to comment.