Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…e invoked when contained in an Array
  • Loading branch information...
commit dff1359e6f538eecc18ea786f794ef4c9179e58b 1 parent 5fe6aa8
@groue authored
View
26 src/tests/Public/v5.3/GRMustacheSectionTagHelperTest.m
@@ -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
View
34 src/tests/Public/v5.3/GRMustacheTemplateDelegateTest.m
@@ -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
View
26 src/tests/Public/v5.3/GRMustacheVariableTagHelperTest.m
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.