Skip to content

Commit

Permalink
Improve failing tests for issue #66
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Jan 25, 2014
1 parent b26894f commit 581d4bf
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/tests/Public/v6.9/GRMustacheKeyedSubscriptingTest.m
Expand Up @@ -24,15 +24,13 @@
#import "GRMustachePublicAPITest.h"

@interface GRMustacheKeyedSubscriptingClass : NSObject
@property (nonatomic, retain) NSString *property;
@property (nonatomic, retain) NSMutableDictionary *dictionary;
@end

@implementation GRMustacheKeyedSubscriptingClass

- (void)dealloc
{
self.property = nil;
self.dictionary = nil;
[super dealloc];
}
Expand All @@ -46,6 +44,11 @@ - (id)init
return self;
}

- (id)valueForKey:(NSString *)key
{
return @"value";
}

- (void)setObject:(id)object forKeyedSubscript:(id<NSCopying>)key
{
self.dictionary[key] = object;
Expand All @@ -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, @"<bar>", 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

0 comments on commit 581d4bf

Please sign in to comment.