diff --git a/src/tests/Public/v6.9/GRMustacheKeyedSubscriptingTest.m b/src/tests/Public/v6.9/GRMustacheKeyedSubscriptingTest.m index 8e4b7274..16101d49 100644 --- a/src/tests/Public/v6.9/GRMustacheKeyedSubscriptingTest.m +++ b/src/tests/Public/v6.9/GRMustacheKeyedSubscriptingTest.m @@ -24,7 +24,6 @@ #import "GRMustachePublicAPITest.h" @interface GRMustacheKeyedSubscriptingClass : NSObject -@property (nonatomic, retain) NSString *property; @property (nonatomic, retain) NSMutableDictionary *dictionary; @end @@ -32,7 +31,6 @@ @implementation GRMustacheKeyedSubscriptingClass - (void)dealloc { - self.property = nil; self.dictionary = nil; [super dealloc]; } @@ -46,6 +44,11 @@ - (id)init return self; } +- (id)valueForKey:(NSString *)key +{ + return @"value"; +} + - (void)setObject:(id)object forKeyedSubscript:(id)key { self.dictionary[key] = object; @@ -63,22 +66,26 @@ @interface GRMustacheKeyedSubscriptingTest : GRMustachePublicAPITest @implementation GRMustacheKeyedSubscriptingTest -- (void)testKeyedSubscriptingHidesProperties +- (void)testKeyedSubscripting { - GRMustacheKeyedSubscriptingClass *object = [[[GRMustacheKeyedSubscriptingClass alloc] init] autorelease]; - object.property = @"foo"; - STAssertEqualObjects([object valueForKey:@"property"], @"foo", nil); - NSString *rendering = [GRMustacheTemplate renderObject:object fromString:@"<{{property}}>" error:NULL]; - STAssertEqualObjects(rendering, @"<>", nil); + id object = [[[GRMustacheKeyedSubscriptingClass alloc] init] autorelease]; + NSString *key = @"foo"; + NSString *value = @"value"; + object[key] = value; + + STAssertEqualObjects(object[key], value, nil); + STAssertEqualObjects(([GRMustacheTemplate renderObject:object fromString:[NSString stringWithFormat:@"{{%@}}", key] error:NULL]), value, nil); } -- (void)testKeyedSubscripting +- (void)testKeyedSubscriptingOverridesValueForKey { - id object = [[[GRMustacheKeyedSubscriptingClass alloc] init] autorelease]; - object[@"foo"] = @"bar"; - STAssertEqualObjects(object[@"foo"], @"bar", nil); - NSString *rendering = [GRMustacheTemplate renderObject:object fromString:@"<{{foo}}>" error:NULL]; - STAssertEqualObjects(rendering, @"", nil); + GRMustacheKeyedSubscriptingClass *object = [[[GRMustacheKeyedSubscriptingClass alloc] init] autorelease]; + NSString *key = @"foo"; + NSString *value = @"value"; + + // Empty rendering for key `foo` despite [object valueForKey:@"foo"] is not empty + STAssertEqualObjects([object valueForKey:key], value, nil); + STAssertEqualObjects(([GRMustacheTemplate renderObject:object fromString:[NSString stringWithFormat:@"{{%@}}", key] error:NULL]), @"", nil); } @end