Skip to content

Commit

Permalink
Fixed @name handling when followed by uncommented method. Closes toma…
Browse files Browse the repository at this point in the history
…z#76.

The problem was in the way comments were being processed. If any comment contained @name, it was always used for creating a new task section, even if followed by uncommented method. However delimited comments:

	///--------------------
	/// @name Something
	///--------------------

Were not correctly detected as @name comments. The reason was in the regex being used for matching @name: it expected the @name at the start of the comment string. By changing the regex to match in any line, this works correctly. The downside is that section names spanning multiple lines are now ignored (you can delimit @name and first word by new line though). On the other hand, I don't think anybody uses section names in such a way, so it'll probably work just fine.

Proper solution would require using two regexes: one for matching @name before stripping delimiters and one for matching afterwards. Or alternatively strip delimiters immediately after recognizing a comment (at present this is all delayed until needed to make the tool as efficient as possible).
  • Loading branch information
tomaz committed Mar 3, 2011
1 parent f5bdcab commit 90e3553
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Application/GBCommentComponentsProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (NSString *)bugSectionRegex {
#pragma mark Method specific detection

- (NSString *)methodGroupRegex {
GBRETURN_ON_DEMAND(@"(?s:^\\s*\\Sname\\s+(.*))");
GBRETURN_ON_DEMAND(@"(?m:^\\s*\\Sname\\s+(.*))");
}

- (NSString *)parameterDescriptionRegex {
Expand Down
6 changes: 3 additions & 3 deletions Testing/GBObjectiveCParser-SectionsParsingTesting.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (void)testParseObjectsFromString_shouldRegisterMethodsToLastSection {
[self assertMethod:[[section methods] objectAtIndex:1] matchesInstanceComponents:@"id", @"method2", nil];
}

- (void)testParseObjectsFromString_shouldRegisterCommentedMethodsToLastSection {
- (void)testParseObjectsFromString_shouldRegisterUncommentedMethodsToLastSection {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
Expand Down Expand Up @@ -73,7 +73,7 @@ - (void)testParseObjectsFromString_shouldDetectSectionNameOnlyIfAtStartOfComment
assertThat([[sections objectAtIndex:0] sectionName], is(nil));
}

- (void)testParseObjectsFromString_shouldIgnoreWhitespaceWithinSectionName {
- (void)testParseObjectsFromString_shouldOnlyTakeSectionNameFromTheFirstLineString {
// setup
GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
GBStore *store = [[GBStore alloc] init];
Expand All @@ -82,7 +82,7 @@ - (void)testParseObjectsFromString_shouldIgnoreWhitespaceWithinSectionName {
// verify
NSArray *sections = [[[[store classes] anyObject] methods] sections];
assertThatInteger([sections count], equalToInteger(1));
assertThat([[sections objectAtIndex:0] sectionName], is(@"Section spanning multiple lines whoa!"));
assertThat([[sections objectAtIndex:0] sectionName], is(@"Section"));
}

- (void)testParseObjectsFromString_requiresDetectsSectionEvenIfFollowedByUncommentedMethod {
Expand Down

0 comments on commit 90e3553

Please sign in to comment.