Skip to content

Commit

Permalink
Tests and implementation for links with references to [Class method] …
Browse files Browse the repository at this point in the history
…with custom title. Refs tomaz#237
  • Loading branch information
kenji21 committed Aug 13, 2012
1 parent 7c302cd commit 15817ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Application/GBCommentComponentsProvider.m
Expand Up @@ -99,7 +99,8 @@ - (NSString *)remoteMemberCrossReferenceRegex:(BOOL)templated {
if (templated) {
GBRETURN_ON_DEMAND([self crossReferenceRegexForRegex:[self remoteMemberCrossReferenceRegex:NO]]);
} else {
GBRETURN_ON_DEMAND(@"([+-]?)\\[(\\S+)\\s+(\\S+)\\]");
//GBRETURN_ON_DEMAND(@"([+-]?)\\[([^]\\s]+)\\s+(\\S+)\\]");
GBRETURN_ON_DEMAND(@"\\[?(\\w*)\\]?\\(?[+-]?\\[([^]\\s]+)\\s+(\\S+)\\]\\)?");
}
}

Expand Down
18 changes: 14 additions & 4 deletions Processing/GBCommentsProcessor.m
Expand Up @@ -661,7 +661,7 @@ - (NSString *)stringByConvertingSimpleCrossReferencesInString:(NSString *)string
if (searchRange.length == 0) break;
continue;
}
// Handle all the links starting at the lowest one, adding proper Markdown syntax for each.
while ([links count] > 0) {
// Find the lowest index.
Expand All @@ -679,6 +679,7 @@ - (NSString *)stringByConvertingSimpleCrossReferencesInString:(NSString *)string
if (linkData->range.location > lastUsedLocation) {
NSRange skippedRange = NSMakeRange(lastUsedLocation, linkData->range.location - lastUsedLocation);
NSString *skippedText = [string substringWithRange:skippedRange];
//NSLog(@"adding skipped text to result : %@", skippedText);
[result appendString:skippedText];
}

Expand All @@ -697,13 +698,14 @@ - (NSString *)stringByConvertingSimpleCrossReferencesInString:(NSString *)string
// Exit if there's nothing more to process.
if (searchRange.location >= searchEndLocation) break;
}

// If there's some text remaining after all links, append it.
if (!isInsideMarkdown && lastUsedLocation < searchEndLocation) {
NSRange remainingRange = NSMakeRange(lastUsedLocation, searchEndLocation - lastUsedLocation);
NSString *remainingText = [string substringWithRange:remainingRange];
[result appendString:remainingText];
}
NSLog(@"result : %@", result);
return result;
}

Expand Down Expand Up @@ -859,6 +861,7 @@ - (GBCrossRefData)dataForRemoteMemberLinkInString:(NSString *)string searchRange

// Get link components. Index 0 contains full text, including optional template prefix/suffix, index 1 optional prefix, index 2 object name, index 3 selector.
NSString *linkText = [components objectAtIndex:0];
NSString *linkDisplayText = [components objectAtIndex:1];
NSString *objectName = [components objectAtIndex:2];
NSString *selector = [components objectAtIndex:3];

Expand All @@ -869,7 +872,7 @@ - (GBCrossRefData)dataForRemoteMemberLinkInString:(NSString *)string searchRange
if (!referencedObject) {
referencedObject = [self.store protocolWithName:objectName];
if (!referencedObject) {
if (self.settings.warnOnInvalidCrossReference) GBLogXWarn(self.currentSourceInfo, @"Invalid %@ reference found near %@, unknown object!", linkText, self.currentSourceInfo);
if (self.settings.warnOnInvalidCrossReference) GBLogXWarn(self.currentSourceInfo, @"Invalid %@ reference found near %@, unknown object : %@ !", linkText, self.currentSourceInfo, objectName);
result.range = [string rangeOfString:linkText options:0 range:searchRange];
result.markdown = [NSString stringWithFormat:@"[%@ %@]", objectName, selector];
return result;
Expand All @@ -890,7 +893,14 @@ - (GBCrossRefData)dataForRemoteMemberLinkInString:(NSString *)string searchRange
// Create link data and return.
result.range = [string rangeOfString:linkText options:0 range:searchRange];
result.address = [self.settings htmlReferenceForObject:referencedMember fromSource:self.currentContext];
result.description = [NSString stringWithFormat:@"[%@ %@]", objectName, selector];
if( [linkDisplayText length] > 0 )
{
result.description = linkDisplayText;
}
else
{
result.description = [NSString stringWithFormat:@"[%@ %@]", objectName, selector];
}
result.markdown = [self markdownLinkWithDescription:result.description address:result.address flags:flags];
return result;
}
Expand Down
26 changes: 26 additions & 0 deletions Testing/GBCommentsProcessor-PreprocessingTesting.m
Expand Up @@ -589,6 +589,32 @@ - (void)testStringByConvertingCrossReferencesInString_shouldKeepManualObjectLink
assertThat(result4, is(@"[text](docs/document.html)"));
}

- (void)testStringByConvertingCrossReferencesInString_shouldKeepManualObjectMethodLinksAndUpdateAddress {
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBDocumentData *document = [GBDocumentData documentDataWithContents:@"c" path:@"document.ext"];

GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil];
GBMethodData *property = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
[class.methods registerMethod:method1];
[class.methods registerMethod:method2];
[class.methods registerMethod:property];

GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, category, protocol, document, nil];
GBCommentsProcessor *processor = [self processorWithStore:store];

NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[text](+[Class method])" withFlags:0];
NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"[text]([Class doSomething:withVars:])" withFlags:0];
NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"[text](-[Class value])" withFlags:0];

assertThat(result1, is(@"[text](Classes/Class.html#//api/name/method)"));
assertThat(result2, is(@"[text](Classes/Class.html#//api/name/doSomething:withVars:)"));
assertThat(result3, is(@"[text](Classes/Class.html#//api/name/value)"));
}

- (void)testStringByConvertingCrossReferencesInString_shouldIgnoreKnownObjectsInManualLinkDescriptionOrTitle {
// setup
GBClassData *class = [GBClassData classDataWithName:@"Class"];
Expand Down

0 comments on commit 15817ad

Please sign in to comment.