Permalink
Browse files

Test that delegates, section tag helpers, and variable tag helpers ar…

…e invoked when contained in an Array
  • Loading branch information...
1 parent 5fe6aa8 commit dff1359e6f538eecc18ea786f794ef4c9179e58b @groue committed Oct 1, 2012
@@ -363,4 +363,30 @@ - (void)testTemplateDelegateCallbacksAreCalledWithinSectionAlternateTemplateStri
STAssertEqualObjects(result, @"delegate", @"");
}
+- (void)testArrayOfHelpersInSectionTag
+{
+ GRMustacheStringSectionTagHelper *helper1 = [[[GRMustacheStringSectionTagHelper alloc] init] autorelease];
+ helper1.string = @"1";
+
+ GRMustacheStringSectionTagHelper *helper2 = [[[GRMustacheStringSectionTagHelper alloc] init] autorelease];
+ helper2.string = @"2";
+
+ id items = @{@"items": @[helper1, helper2] };
+ NSString *rendering = [GRMustacheTemplate renderObject:items fromString:@"{{#items}}{{.}}{{/items}}" error:NULL];
+ STAssertEqualObjects(rendering, @"12", @"");
+}
+
+- (void)testArrayOfHelpersInVariableTag
+{
+ GRMustacheStringSectionTagHelper *helper1 = [[[GRMustacheStringSectionTagHelper alloc] init] autorelease];
+ helper1.string = @"1";
+
+ GRMustacheStringSectionTagHelper *helper2 = [[[GRMustacheStringSectionTagHelper alloc] init] autorelease];
+ helper2.string = @"2";
+
+ id items = @{@"items": @[helper1, helper2] };
+ NSString *rendering = [GRMustacheTemplate renderObject:items fromString:@"{{items}}" error:NULL];
+ STAssertEqualObjects(rendering, @"12", @"");
+}
+
@end
@@ -909,4 +909,38 @@ - (void)testTemplateDelegatePlusNestedSectionsDelegate
STAssertEqualObjects(rendering, @"prefixfoosuffix prefixFOOsuffix FOOsuffix PREFIXFOOsuffix", @"");
}
+- (void)testArrayOfDelegatesInSectionTag
+{
+ __block BOOL delegate1HasBeenInvoked = NO;
+ GRMustacheTestingDelegate *delegate1 = [[[GRMustacheTestingDelegate alloc] init] autorelease];
+ delegate1.templateWillInterpretBlock = ^(GRMustacheTemplate *template, GRMustacheInvocation *invocation, GRMustacheInterpretation interpretation) { delegate1HasBeenInvoked = YES; };
+
+ __block BOOL delegate2HasBeenInvoked = NO;
+ GRMustacheTestingDelegate *delegate2 = [[[GRMustacheTestingDelegate alloc] init] autorelease];
+ delegate2.templateWillInterpretBlock = ^(GRMustacheTemplate *template, GRMustacheInvocation *invocation, GRMustacheInterpretation interpretation) { delegate2HasBeenInvoked = YES; };
+
+ id items = @{@"items": @[delegate1, delegate2] };
+ [GRMustacheTemplate renderObject:items fromString:@"{{#items}}{{.}}{{/items}}" error:NULL];
+
+ STAssertTrue(delegate1HasBeenInvoked, @"");
+ STAssertTrue(delegate2HasBeenInvoked, @"");
+}
+
+- (void)testArrayOfDelegatesInVariableTag
+{
+ __block BOOL delegate1HasBeenInvoked = NO;
+ GRMustacheTestingDelegate *delegate1 = [[[GRMustacheTestingDelegate alloc] init] autorelease];
+ delegate1.templateWillInterpretBlock = ^(GRMustacheTemplate *template, GRMustacheInvocation *invocation, GRMustacheInterpretation interpretation) { delegate1HasBeenInvoked = YES; };
+
+ __block BOOL delegate2HasBeenInvoked = NO;
+ GRMustacheTestingDelegate *delegate2 = [[[GRMustacheTestingDelegate alloc] init] autorelease];
+ delegate2.templateWillInterpretBlock = ^(GRMustacheTemplate *template, GRMustacheInvocation *invocation, GRMustacheInterpretation interpretation) { delegate2HasBeenInvoked = YES; };
+
+ id items = @{@"items": @[delegate1, delegate2] };
+ [GRMustacheTemplate renderObject:items fromString:@"{{items}}" error:NULL];
+
+ STAssertTrue(delegate1HasBeenInvoked, @"");
+ STAssertTrue(delegate2HasBeenInvoked, @"");
+}
+
@end
@@ -368,4 +368,30 @@ - (void)testHelperDoesEnterContextStack
STAssertEqualObjects(result, @"name", @"");
}
+- (void)testArrayOfHelpersInSectionTag
+{
+ GRMustacheStringVariableTagHelper *helper1 = [[[GRMustacheStringVariableTagHelper alloc] init] autorelease];
+ helper1.rendering = @"1";
+
+ GRMustacheStringVariableTagHelper *helper2 = [[[GRMustacheStringVariableTagHelper alloc] init] autorelease];
+ helper2.rendering = @"2";
+
+ id items = @{@"items": @[helper1, helper2] };
+ NSString *rendering = [GRMustacheTemplate renderObject:items fromString:@"{{#items}}{{.}}{{/items}}" error:NULL];
+ STAssertEqualObjects(rendering, @"12", @"");
+}
+
+- (void)testArrayOfHelpersInVariableTag
+{
+ GRMustacheStringVariableTagHelper *helper1 = [[[GRMustacheStringVariableTagHelper alloc] init] autorelease];
+ helper1.rendering = @"1";
+
+ GRMustacheStringVariableTagHelper *helper2 = [[[GRMustacheStringVariableTagHelper alloc] init] autorelease];
+ helper2.rendering = @"2";
+
+ id items = @{@"items": @[helper1, helper2] };
+ NSString *rendering = [GRMustacheTemplate renderObject:items fromString:@"{{items}}" error:NULL];
+ STAssertEqualObjects(rendering, @"12", @"");
+}
+
@end

0 comments on commit dff1359

Please sign in to comment.