Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

203 lines (181 sloc) 11.4 kb
//
// GBCommentsProcessor-ExamplesTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 2.9.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBComment.h"
#import "GBCommentsProcessor.h"
@interface GBCommentsProcessorExamplesTesting : GBObjectsAssertor
@end
#pragma mark -
@implementation GBCommentsProcessorExamplesTesting
#pragma mark Description processing testing
- (void)testProcessCommentWithStore_shouldAttachExampleToPreviousParagraph {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n\tDescription"];
// 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], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:1];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"Description", nil];
}
- (void)testProcessCommentWithStore_shouldDetectMultipleLinesDescriptions {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n\tLine1\n\tLine2"];
// 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], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:1];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"Line1\nLine2", nil];
}
- (void)testProcessCommentWithStore_shouldRemovePrefixTabs {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n\tLine"];
// 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], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:1];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"Line", nil];
}
- (void)testProcessCommentWithStore_shouldKeepPrefixTabsAfterFirst {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n\t\tLine1\n\t\t\t\tLine2"];
// 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], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:1];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"\tLine1\n\t\t\tLine2", nil];
}
- (void)testProcessCommentWithStore_shouldKeepEmptyLinesIfPrefixedWithTab {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\n\t\tLine1\n\t\n\tLine3"];
// 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], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:1];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"\tLine1\n\nLine3", nil];
}
- (void)testProcessCommentWithStore_shouldCreateParagraphIfNoneSpecifiedBefore {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"\tDescription"];
// execute
[processor processComment:comment withStore:[GBTestObjectsRegistry store]];
// verify
assertThatInteger([[comment paragraphs] count], equalToInteger(1));
GBCommentParagraph *paragraph = comment.firstParagraph;
[self assertParagraph:paragraph containsItems:[GBParagraphSpecialItem class], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:0];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"Description", nil];
}
#pragma mark Comments prefixed with spaces
- (void)testProcessCommentWithStore_shouldDetectIfPrefixedWithAtLeastFourSpaces {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment1 = [GBComment commentWithStringValue:@" Description"];
GBComment *comment2 = [GBComment commentWithStringValue:@" Description"];
// execute
[processor processComment:comment1 withStore:[GBTestObjectsRegistry store]];
[processor processComment:comment2 withStore:[GBTestObjectsRegistry store]];
// verify
GBCommentParagraph *paragraph1 = comment1.firstParagraph;
[self assertParagraph:paragraph1 containsItems:[GBParagraphSpecialItem class], GBNULL, nil];
GBParagraphSpecialItem *item1 = [paragraph1.paragraphItems objectAtIndex:0];
assertThatInteger(item1.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item1.specialItemDescription containsItems:[GBParagraphTextItem class], @"Description", nil];
GBCommentParagraph *paragraph2 = comment2.firstParagraph;
[self assertParagraph:paragraph2 containsItems:[GBParagraphTextItem class], @" Description", nil];
}
- (void)testProcessCommentWithStore_shouldKeepAllWhitespaceAfterInitialFourSpaces {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@" 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], GBNULL, nil];
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:0];
assertThatInteger(item.specialItemType, equalToInteger(GBSpecialItemTypeExample));
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @" Description", nil];
}
#pragma mark Special contents parsing
- (void)testProcessCommentWithStore_shouldEscapeHTMLText {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"\t<sometag>\"'&</sometag>"];
// execute
[processor processComment:comment withStore:[GBTestObjectsRegistry store]];
// verify
GBCommentParagraph *paragraph = comment.firstParagraph;
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:0];
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"&lt;sometag&gt;&quot;&apos;&amp;&lt;/sometag&gt;", nil];
}
- (void)testProcessCommentWithStore_shouldEscapeHTMLComments {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"\t<!-- .... ->"];
// execute
[processor processComment:comment withStore:[GBTestObjectsRegistry store]];
// verify
GBCommentParagraph *paragraph = comment.firstParagraph;
GBParagraphSpecialItem *item = [paragraph.paragraphItems objectAtIndex:0];
[self assertParagraph:item.specialItemDescription containsItems:[GBParagraphTextItem class], @"&lt;!-- .... -&gt;", nil];
}
#pragma mark Requirements before/after testing
- (void)testProcessCommentWithStore_requiresEmptyLineAfterPreviousParagraphItem {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment = [GBComment commentWithStringValue:@"Paragraph\n\tLine"];
// execute
[processor processComment:comment withStore:[GBTestObjectsRegistry store]];
// verify
assertThatInteger([[comment paragraphs] count], equalToInteger(1));
GBCommentParagraph *paragraph1 = [comment.paragraphs objectAtIndex:0];
[self assertParagraph:paragraph1 containsItems:[GBParagraphTextItem class], @"Paragraph\n\tLine", nil];
}
- (void)testProcessCommentWithStore_requiresEmptyLineBeforeNextParagraphItem {
// setup
GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
GBComment *comment1 = [GBComment commentWithStringValue:@"\tLine1\nLine2"];
GBComment *comment2 = [GBComment commentWithStringValue:@"\tLine1\n\nLine2"];
// execute
[processor processComment:comment1 withStore:[GBTestObjectsRegistry store]];
[processor processComment:comment2 withStore:[GBTestObjectsRegistry store]];
// verify - although comment1 uses with correct example prefix, it's not separated by empty line, so it's considered normal paragraph.
assertThatInteger([[comment1 paragraphs] count], equalToInteger(1));
[self assertParagraph:[[comment1 paragraphs] objectAtIndex:0] containsItems:[GBParagraphTextItem class], @"\tLine1\nLine2", nil];
assertThatInteger([[comment2 paragraphs] count], equalToInteger(2));
[self assertParagraph:[[comment2 paragraphs] objectAtIndex:0] containsItems:[GBParagraphSpecialItem class], @"Line1", nil];
[self assertParagraph:[[comment2 paragraphs] objectAtIndex:1] containsItems:[GBParagraphTextItem class], @"Line2", nil];
}
@end
Jump to Line
Something went wrong with that request. Please try again.