Browse files

GRMustacheTemplateDelegate now knows how the return value of invocati…

…on will be interpreted.

New type:
typedef enum {
    GRMustacheInterpretationSection,
    GRMustacheInterpretationVariable,
} GRMustacheInterpretation;

New methods:
- [GRMustacheTemplateDelegate template:willInterpretReturnValueOfInvocation:as:]
- [GRMustacheTemplateDelegate template:didInterpretReturnValueOfInvocation:as:]

Deprecated methods:
- [GRMustacheTemplateDelegate template:willRenderReturnValueOfInvocation:]
- [GRMustacheTemplateDelegate template:didRenderReturnValueOfInvocation:]
  • Loading branch information...
1 parent 331975c commit bfcf818a82af9a53dbde217b8faf70519efa7e1b @groue committed Jun 30, 2012
View
16 src/GRMustache.xcodeproj/project.pbxproj
@@ -95,6 +95,8 @@
5682B4C01528DF4A00ADD123 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5682B4BF1528DF4900ADD123 /* Foundation.framework */; };
5682B4C31528E0B300ADD123 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5682B4BF1528DF4900ADD123 /* Foundation.framework */; };
5682B4C51528E0C600ADD123 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5682B4C41528E0C500ADD123 /* CoreData.framework */; };
+ 568FB8E9159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 568FB8E8159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m */; };
+ 568FB8EA159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 568FB8E8159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m */; };
56A8D48C15279F8A00D9C718 /* GRMustacheTemplateDelegateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 56A8D48B15279F8A00D9C718 /* GRMustacheTemplateDelegateTest.m */; };
56A8D48D15279F8A00D9C718 /* GRMustacheTemplateDelegateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 56A8D48B15279F8A00D9C718 /* GRMustacheTemplateDelegateTest.m */; };
56A8D4931527A23900D9C718 /* GRMustacheTemplateDelegateTest.mustache in Resources */ = {isa = PBXBuildFile; fileRef = 56A8D4921527A23900D9C718 /* GRMustacheTemplateDelegateTest.mustache */; };
@@ -275,6 +277,8 @@
5682B4BD1528DF3D00ADD123 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
5682B4BF1528DF4900ADD123 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
5682B4C41528E0C500ADD123 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
+ 568FB8E7159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.h */ = {isa = PBXFileReference; fileEncoding = 4; path = GRMustacheTemplateDelegate_v4_1_Test.h; sourceTree = "<group>"; };
+ 568FB8E8159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GRMustacheTemplateDelegate_v4_1_Test.m; sourceTree = "<group>"; };
56A8D48A15279F8A00D9C718 /* GRMustacheTemplateDelegateTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GRMustacheTemplateDelegateTest.h; sourceTree = "<group>"; };
56A8D48B15279F8A00D9C718 /* GRMustacheTemplateDelegateTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GRMustacheTemplateDelegateTest.m; sourceTree = "<group>"; };
56A8D4921527A23900D9C718 /* GRMustacheTemplateDelegateTest.mustache */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GRMustacheTemplateDelegateTest.mustache; sourceTree = "<group>"; };
@@ -561,6 +565,15 @@
name = Frameworks;
sourceTree = "<group>";
};
+ 568FB8E6159F7C4C00241D9A /* v4.1 */ = {
+ isa = PBXGroup;
+ children = (
+ 568FB8E7159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.h */,
+ 568FB8E8159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m */,
+ );
+ path = v4.1;
+ sourceTree = "<group>";
+ };
56DEC19A15262FC80031E8DC = {
isa = PBXGroup;
children = (
@@ -715,6 +728,7 @@
56DEC3B1152638E20031E8DC /* GRMustachePublicAPITest.h */,
56DEC3B2152638E20031E8DC /* GRMustachePublicAPITest.m */,
56DEC3BD152639420031E8DC /* v4.0 */,
+ 568FB8E6159F7C4C00241D9A /* v4.1 */,
);
path = Public;
sourceTree = "<group>";
@@ -1067,6 +1081,7 @@
5682B48F1528473200ADD123 /* GRMustacheTemplateRepositoryWithBundleTest.m in Sources */,
5682B4911528473200ADD123 /* GRMustacheTemplateRepositoryWithDirectoryTest.m in Sources */,
5682B4931528473200ADD123 /* GRMustacheTemplateRepositoryWithPartialsDictionaryTest.m in Sources */,
+ 568FB8E9159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1117,6 +1132,7 @@
5682B4901528473200ADD123 /* GRMustacheTemplateRepositoryWithBundleTest.m in Sources */,
5682B4921528473200ADD123 /* GRMustacheTemplateRepositoryWithDirectoryTest.m in Sources */,
5682B4941528473200ADD123 /* GRMustacheTemplateRepositoryWithPartialsDictionaryTest.m in Sources */,
+ 568FB8EA159F7CA900241D9A /* GRMustacheTemplateDelegate_v4_1_Test.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2 src/bin/buildGRMustacheAvailabilityMacros
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
MAJOR_VERSION = 4
-MAX_MINOR_VERSION = 0
+MAX_MINOR_VERSION = 1
puts <<-LICENSE
// The MIT License
View
58 src/classes/GRMustacheAvailabilityMacros.h
@@ -29,17 +29,18 @@
* Set up standard GRMustache versions
*/
#define GRMUSTACHE_VERSION_4_0 4000
+#define GRMUSTACHE_VERSION_4_1 4010
/*
- * If max GRMustacheVersion not specified, assume 4.0
+ * If max GRMustacheVersion not specified, assume 4.1
*/
#ifndef GRMUSTACHE_VERSION_MAX_ALLOWED
-#define GRMUSTACHE_VERSION_MAX_ALLOWED GRMUSTACHE_VERSION_4_0
+#define GRMUSTACHE_VERSION_MAX_ALLOWED GRMUSTACHE_VERSION_4_1
#endif
/*
@@ -91,3 +92,56 @@
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER
+ *
+ * Used on declarations introduced in GRMustache 4.1
+ */
+#if GRMUSTACHE_VERSION_MAX_ALLOWED < GRMUSTACHE_VERSION_4_1
+#define AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif GRMUSTACHE_VERSION_MIN_REQUIRED < GRMUSTACHE_VERSION_4_1
+#define AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in GRMustache 4.1,
+ * and deprecated in GRMustache 4.1
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_4_1
+#define AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER_BUT_DEPRECATED AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_4_1
+ *
+ * Used on declarations introduced in GRMustache 4.0,
+ * but later deprecated in GRMustache 4.1
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_4_1
+#define AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_4_1 DEPRECATED_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_4_1 AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_GRMUSTACHE_VERSION_4_1_AND_LATER
+ *
+ * Used on types deprecated in GRMustache 4.1
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_4_1
+#define DEPRECATED_IN_GRMUSTACHE_VERSION_4_1_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+#define DEPRECATED_IN_GRMUSTACHE_VERSION_4_1_AND_LATER
+#endif
+
+
+
+
+
+
View
12 src/classes/GRMustacheSection.m
@@ -114,7 +114,11 @@ - (NSString *)renderContext:(GRMustacheContext *)context inRootTemplate:(GRMusta
// invoke
[_invocation invokeWithContext:context];
- if ([rootTemplate.delegate respondsToSelector:@selector(template:willRenderReturnValueOfInvocation:)]) {
+ if ([rootTemplate.delegate respondsToSelector:@selector(template:willInterpretReturnValueOfInvocation:as:)]) {
+ // 4.1 API
+ [rootTemplate.delegate template:rootTemplate willInterpretReturnValueOfInvocation:_invocation as:GRMustacheInterpretationSection];
+ } else if ([rootTemplate.delegate respondsToSelector:@selector(template:willRenderReturnValueOfInvocation:)]) {
+ // 4.0 API
[rootTemplate.delegate template:rootTemplate willRenderReturnValueOfInvocation:_invocation];
}
id value = _invocation.returnValue;
@@ -197,7 +201,11 @@ - (NSString *)renderContext:(GRMustacheContext *)context inRootTemplate:(GRMusta
// finish
- if ([rootTemplate.delegate respondsToSelector:@selector(template:didRenderReturnValueOfInvocation:)]) {
+ if ([rootTemplate.delegate respondsToSelector:@selector(template:didInterpretReturnValueOfInvocation:as:)]) {
+ // 4.1 API
+ [rootTemplate.delegate template:rootTemplate didInterpretReturnValueOfInvocation:_invocation as:GRMustacheInterpretationSection];
+ } else if ([rootTemplate.delegate respondsToSelector:@selector(template:didRenderReturnValueOfInvocation:)]) {
+ // 4.0 API
[rootTemplate.delegate template:rootTemplate didRenderReturnValueOfInvocation:_invocation];
}
}
View
11 src/classes/GRMustacheTemplateDelegate.h
@@ -26,10 +26,17 @@
@class GRMustacheTemplate;
@class GRMustacheInvocation;
+typedef enum {
+ GRMustacheInterpretationSection,
+ GRMustacheInterpretationVariable,
+} GRMustacheInterpretation;
+
@protocol GRMustacheTemplateDelegate<NSObject>
@optional
- (void)templateWillRender:(GRMustacheTemplate *)template AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
- (void)templateDidRender:(GRMustacheTemplate *)template AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
-- (void)template:(GRMustacheTemplate *)template willRenderReturnValueOfInvocation:(GRMustacheInvocation *)invocation AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
-- (void)template:(GRMustacheTemplate *)template didRenderReturnValueOfInvocation:(GRMustacheInvocation *)invocation AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
+- (void)template:(GRMustacheTemplate *)template willRenderReturnValueOfInvocation:(GRMustacheInvocation *)invocation AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_4_1;
+- (void)template:(GRMustacheTemplate *)template didRenderReturnValueOfInvocation:(GRMustacheInvocation *)invocation AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_4_1;
+- (void)template:(GRMustacheTemplate *)template willInterpretReturnValueOfInvocation:(GRMustacheInvocation *)invocation as:(GRMustacheInterpretation)interpretation AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER;
+- (void)template:(GRMustacheTemplate *)template didInterpretReturnValueOfInvocation:(GRMustacheInvocation *)invocation as:(GRMustacheInterpretation)interpretation AVAILABLE_GRMUSTACHE_VERSION_4_1_AND_LATER;
@end
View
12 src/classes/GRMustacheVariableElement.m
@@ -55,7 +55,11 @@ - (NSString *)renderContext:(GRMustacheContext *)context inRootTemplate:(GRMusta
// invoke
[_invocation invokeWithContext:context];
- if ([rootTemplate.delegate respondsToSelector:@selector(template:willRenderReturnValueOfInvocation:)]) {
+ if ([rootTemplate.delegate respondsToSelector:@selector(template:willInterpretReturnValueOfInvocation:as:)]) {
+ // 4.1 API
+ [rootTemplate.delegate template:rootTemplate willInterpretReturnValueOfInvocation:_invocation as:GRMustacheInterpretationVariable];
+ } else if ([rootTemplate.delegate respondsToSelector:@selector(template:willRenderReturnValueOfInvocation:)]) {
+ // 4.0 API
[rootTemplate.delegate template:rootTemplate willRenderReturnValueOfInvocation:_invocation];
}
id value = _invocation.returnValue;
@@ -74,7 +78,11 @@ - (NSString *)renderContext:(GRMustacheContext *)context inRootTemplate:(GRMusta
// finish
- if ([rootTemplate.delegate respondsToSelector:@selector(template:didRenderReturnValueOfInvocation:)]) {
+ if ([rootTemplate.delegate respondsToSelector:@selector(template:didInterpretReturnValueOfInvocation:as:)]) {
+ // 4.1 API
+ [rootTemplate.delegate template:rootTemplate didInterpretReturnValueOfInvocation:_invocation as:GRMustacheInterpretationVariable];
+ } else if ([rootTemplate.delegate respondsToSelector:@selector(template:didRenderReturnValueOfInvocation:)]) {
+ // 4.0 API
[rootTemplate.delegate template:rootTemplate didRenderReturnValueOfInvocation:_invocation];
}
View
27 src/tests/Public/v4.1/GRMustacheTemplateDelegate_v4_1_Test.h
@@ -0,0 +1,27 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#define GRMUSTACHE_VERSION_MAX_ALLOWED GRMUSTACHE_VERSION_4_1
+#import "GRMustachePublicAPITest.h"
+
+@interface GRMustacheTemplateDelegate_v4_1_Test : GRMustachePublicAPITest
+@end
View
212 src/tests/Public/v4.1/GRMustacheTemplateDelegate_v4_1_Test.m
@@ -0,0 +1,212 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "GRMustacheTemplateDelegate_v4_1_Test.h"
+
+@interface GRMustacheTemplateRecorder_v4_1 : NSObject<GRMustacheTemplateDelegate>
+@property (nonatomic) NSUInteger willRenderReturnValueOfInvocationCount;
+@property (nonatomic) NSUInteger didRenderReturnValueOfInvocationCount;
+@property (nonatomic) NSUInteger willInterpretReturnValueOfInvocationAsCount;
+@property (nonatomic) NSUInteger didInterpretReturnValueOfInvocationAsCount;
+@property (nonatomic) GRMustacheInterpretation lastInterpretation;
+@end
+
+@implementation GRMustacheTemplateRecorder_v4_1
+@synthesize willRenderReturnValueOfInvocationCount=_willRenderReturnValueOfInvocationCount;
+@synthesize didRenderReturnValueOfInvocationCount=_didRenderReturnValueOfInvocationCount;
+@synthesize willInterpretReturnValueOfInvocationAsCount=_willInterpretReturnValueOfInvocationAsCount;
+@synthesize didInterpretReturnValueOfInvocationAsCount=_didInterpretReturnValueOfInvocationAsCount;
+@synthesize lastInterpretation=_lastInterpretation;
+
+- (void)template:(GRMustacheTemplate *)template willRenderReturnValueOfInvocation:(GRMustacheInvocation *)invocation
+{
+ self.willRenderReturnValueOfInvocationCount += 1;
+}
+
+- (void)template:(GRMustacheTemplate *)template didRenderReturnValueOfInvocation:(GRMustacheInvocation *)invocation
+{
+ self.didRenderReturnValueOfInvocationCount += 1;
+}
+
+- (void)template:(GRMustacheTemplate *)template willInterpretReturnValueOfInvocation:(GRMustacheInvocation *)invocation as:(GRMustacheInterpretation)interpretation
+{
+ self.willInterpretReturnValueOfInvocationAsCount += 1;
+ self.lastInterpretation = interpretation;
+}
+
+- (void)template:(GRMustacheTemplate *)template didInterpretReturnValueOfInvocation:(GRMustacheInvocation *)invocation as:(GRMustacheInterpretation)interpretation
+{
+ self.didInterpretReturnValueOfInvocationAsCount += 1;
+}
+
+@end
+
+@implementation GRMustacheTemplateDelegate_v4_1_Test
+
+- (void)testWillRenderReturnValueOfInvocationWithText
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"---" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testWillInterpretReturnValueOfInvocationAsWithText
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"---" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willInterpretReturnValueOfInvocationAsCount, (NSUInteger)0, @"");
+}
+
+- (void)testDidRenderReturnValueOfInvocationWithText
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"---" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testDidInterpretReturnValueOfInvocationAsWithText
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"---" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didInterpretReturnValueOfInvocationAsCount, (NSUInteger)0, @"");
+}
+
+- (void)testWillRenderReturnValueOfInvocationWithVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{foo}}{{bar}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testWillInterpretReturnValueOfInvocationAsWithVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{foo}}{{bar}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willInterpretReturnValueOfInvocationAsCount, (NSUInteger)2, @"");
+ STAssertEquals(recorder.lastInterpretation, GRMustacheInterpretationVariable, @"");
+}
+
+- (void)testDidRenderReturnValueOfInvocationWithVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{foo}}{{bar}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testDidInterpretReturnValueOfInvocationAsWithVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{foo}}{{bar}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didInterpretReturnValueOfInvocationAsCount, (NSUInteger)2, @"");
+}
+
+- (void)testWillRenderReturnValueOfInvocationWithUnrenderedSection
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{#foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testWillInterpretReturnValueOfInvocationAsWithUnrenderedSection
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{#foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willInterpretReturnValueOfInvocationAsCount, (NSUInteger)1, @"");
+ STAssertEquals(recorder.lastInterpretation, GRMustacheInterpretationSection, @"");
+}
+
+- (void)testDidRenderReturnValueOfInvocationWithUnrenderedSection
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{#foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testDidInterpretReturnValueOfInvocationAsWithUnrenderedSection
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{#foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didInterpretReturnValueOfInvocationAsCount, (NSUInteger)1, @"");
+}
+
+- (void)testWillRenderReturnValueOfInvocationWithRenderedSectionAndVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{^foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testWillInterpretReturnValueOfInvocationAsWithRenderedSectionAndVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{^foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.willInterpretReturnValueOfInvocationAsCount, (NSUInteger)2, @"");
+ STAssertEquals(recorder.lastInterpretation, GRMustacheInterpretationVariable, @"");
+}
+
+- (void)testDidRenderReturnValueOfInvocationWithRenderedSectionAndVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{^foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didRenderReturnValueOfInvocationCount, (NSUInteger)0, @"");
+}
+
+- (void)testDidInterpretReturnValueOfInvocationAsWithRenderedSectionAndVariable
+{
+ GRMustacheTemplateRecorder_v4_1 *recorder = [[[GRMustacheTemplateRecorder_v4_1 alloc] init] autorelease];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{^foo}}{{bar}}{{/foo}}" error:NULL];
+ template.delegate = recorder;
+ [template render];
+ STAssertEquals(recorder.didInterpretReturnValueOfInvocationAsCount, (NSUInteger)2, @"");
+}
+
+@end

0 comments on commit bfcf818

Please sign in to comment.