From e17dc1e52f911aa0e80edfbdb28c76e2b424fd77 Mon Sep 17 00:00:00 2001 From: Watson Date: Tue, 4 Feb 2014 01:03:57 +0900 Subject: [PATCH] [spec] add test for Subscripting --- test/test/spec/subscripting_spec.rb | 22 ++++++++++++++++ test/test/vendor/code/subscripting.h | 11 ++++++++ test/test/vendor/code/subscripting.m | 39 ++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 test/test/spec/subscripting_spec.rb create mode 100644 test/test/vendor/code/subscripting.h create mode 100644 test/test/vendor/code/subscripting.m diff --git a/test/test/spec/subscripting_spec.rb b/test/test/spec/subscripting_spec.rb new file mode 100644 index 00000000..a885946b --- /dev/null +++ b/test/test/spec/subscripting_spec.rb @@ -0,0 +1,22 @@ +describe "Subscripting" do + it "#respond_to?(:[])" do + obj = TestSubscripting.new + obj.respond_to?(:[]).should == true + end + + it "#respond_to?(:[]=)" do + obj = TestSubscripting.new + obj.respond_to?(:[]=).should == true + end + + it "Objective-C literals should work" do + obj = TestSubscripting.new + o = obj[0] = 42 + obj[0].should == 42 + o.should == 42 + + o = obj['a'] = 'foo' + obj['a'].should == 'foo' + o.should == 'foo' + end +end diff --git a/test/test/vendor/code/subscripting.h b/test/test/vendor/code/subscripting.h new file mode 100644 index 00000000..59755602 --- /dev/null +++ b/test/test/vendor/code/subscripting.h @@ -0,0 +1,11 @@ +#import + +@interface TestSubscripting : NSObject + +- (id)objectAtIndexedSubscript:(NSUInteger)index; +- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index; + +- (id)objectForKeyedSubscript:(id)key; +- (void)setObject:(id)object forKeyedSubscript:(id)key; + +@end \ No newline at end of file diff --git a/test/test/vendor/code/subscripting.m b/test/test/vendor/code/subscripting.m new file mode 100644 index 00000000..77d2ee15 --- /dev/null +++ b/test/test/vendor/code/subscripting.m @@ -0,0 +1,39 @@ +#import "subscripting.h" + +@interface TestSubscripting () +@property (strong) NSMutableArray *array; +@property (strong) NSMutableDictionary *dictionary; +@end + +@implementation TestSubscripting + +- (instancetype)init; +{ + if ((self = [super init])) { + _array = [NSMutableArray new]; + _dictionary = [NSMutableDictionary new]; + } + return self; +} + +- (id)objectAtIndexedSubscript:(NSUInteger)index; +{ + return self.array[index]; +} + +- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index; +{ + self.array[index] = object; +} + +- (id)objectForKeyedSubscript:(id)key; +{ + return self.dictionary[key]; +} + +- (void)setObject:(id)object forKeyedSubscript:(id)key; +{ + self.dictionary[key] = object; +} + +@end \ No newline at end of file