Replaced RCTSparseArray with NSDictionary

Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
This commit is contained in:
Nick Lockwood
2015-11-14 10:25:00 -08:00
committed by facebook-github-bot-4
parent 5a34a097f2
commit fa0b45c58b
67 changed files with 338 additions and 547 deletions

View File

@@ -31,7 +31,7 @@
@interface TestExecutor : NSObject <RCTJavaScriptExecutor>
@property (nonatomic, readonly, copy) NSMutableDictionary *injectedStuff;
@property (nonatomic, readonly, copy) NSMutableDictionary<NSString *, id> *injectedStuff;
@end
@@ -137,7 +137,7 @@ _Pragma("clang diagnostic pop")
RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"]));
__block NSNumber *testModuleID = nil;
__block NSDictionary *testConstants = nil;
__block NSDictionary<NSString *, id> *testConstants = nil;
__block NSNumber *testMethodID = nil;
NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"];
@@ -165,7 +165,7 @@ _Pragma("clang diagnostic pop")
RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"]));
__block NSNumber *testModuleID = nil;
__block NSDictionary *testConstants = nil;
__block NSDictionary<NSString *, id> *testConstants = nil;
__block NSNumber *testMethodID = nil;
NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"];
@@ -211,7 +211,7 @@ RCT_EXPORT_METHOD(testMethod:(NSInteger)integer
XCTAssertNotNil(callback);
}
- (NSDictionary *)constantsToExport
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{@"eleventyMillion": @42};
}

View File

@@ -26,7 +26,7 @@
@implementation RCTTestEvent
- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary *)body
- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary<NSString *, id> *)body
{
if (self = [super initWithViewTag:viewTag eventName:eventName body:body]) {
self.canCoalesce = YES;
@@ -50,7 +50,7 @@
RCTEventDispatcher *_eventDispatcher;
NSString *_eventName;
NSDictionary *_body;
NSDictionary<NSString *, id> *_body;
RCTTestEvent *_testEvent;
NSString *_JSMethod;
}

View File

@@ -20,7 +20,7 @@ extern BOOL RCTIsGzippedData(NSData *data);
@interface RCTNetworking (Private)
- (void)buildRequest:(NSDictionary *)query
- (void)buildRequest:(NSDictionary<NSString *, id> *)query
completionBlock:(void (^)(NSURLRequest *request))block;
@end

View File

@@ -23,14 +23,14 @@
- (void)testEncodingObject
{
NSDictionary *obj = @{@"foo": @"bar"};
NSDictionary<NSString *, id> *obj = @{@"foo": @"bar"};
NSString *json = @"{\"foo\":\"bar\"}";
XCTAssertEqualObjects(json, RCTJSONStringify(obj, NULL));
}
- (void)testEncodingArray
{
NSArray *array = @[@"foo", @"bar"];
NSArray<id> *array = @[@"foo", @"bar"];
NSString *json = @"[\"foo\",\"bar\"]";
XCTAssertEqualObjects(json, RCTJSONStringify(array, NULL));
}
@@ -44,14 +44,14 @@
- (void)testDecodingObject
{
NSDictionary *obj = @{@"foo": @"bar"};
NSDictionary<NSString *, id> *obj = @{@"foo": @"bar"};
NSString *json = @"{\"foo\":\"bar\"}";
XCTAssertEqualObjects(obj, RCTJSONParse(json, NULL));
}
- (void)testDecodingArray
{
NSArray *array = @[@"foo", @"bar"];
NSArray<id> *array = @[@"foo", @"bar"];
NSString *json = @"[\"foo\",\"bar\"]";
XCTAssertEqualObjects(array, RCTJSONParse(json, NULL));
}
@@ -66,14 +66,14 @@
- (void)testDecodingMutableArray
{
NSString *json = @"[1,2,3]";
NSMutableArray *array = RCTJSONParseMutable(json, NULL);
NSMutableArray<id> *array = RCTJSONParseMutable(json, NULL);
XCTAssertNoThrow([array addObject:@4]);
XCTAssertEqualObjects(array, (@[@1, @2, @3, @4]));
}
- (void)testLeadingWhitespace
{
NSDictionary *obj = @{@"foo": @"bar"};
NSDictionary<NSString *, id> *obj = @{@"foo": @"bar"};
NSString *json = @" \r\n\t{\"foo\":\"bar\"}";
XCTAssertEqualObjects(obj, RCTJSONParse(json, NULL));
}

View File

@@ -1,55 +0,0 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* 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 NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK 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 <XCTest/XCTest.h>
#import "RCTSparseArray.h"
#import "UIView+React.h"
@interface RCTSparseArrayTests : XCTestCase
@end
@implementation RCTSparseArrayTests
- (void)testDictionary
{
id<RCTComponent> myView = [UIView new];
myView.reactTag = @4;
id<RCTComponent> myOtherView = [UIView new];
myOtherView.reactTag = @5;
RCTSparseArray *registry = [RCTSparseArray new];
XCTAssertNil(registry[@4], @"how did you have a view when none are registered?");
XCTAssertNil(registry[@5], @"how did you have a view when none are registered?");
registry[myView.reactTag] = myView;
XCTAssertEqual(registry[@4], myView);
XCTAssertNil(registry[@5], @"didn't register other view yet");
registry[myOtherView.reactTag] = myOtherView;
XCTAssertEqual(registry[@4], myView);
XCTAssertEqual(registry[@5], myOtherView);
registry[myView.reactTag] = nil;
XCTAssertNil(registry[@4]);
XCTAssertEqual(registry[@5], myOtherView);
registry[myOtherView.reactTag] = nil;
XCTAssertNil(registry[@4], @"how did you have a view when none are registered?");
XCTAssertNil(registry[@5], @"how did you have a view when none are registered?");
}
@end

View File

@@ -14,7 +14,6 @@
#import <XCTest/XCTest.h>
#import "RCTSparseArray.h"
#import "RCTUIManager.h"
#import "UIView+React.h"
@@ -26,9 +25,9 @@
addChildReactTags:(NSArray *)addChildReactTags
addAtIndices:(NSArray *)addAtIndices
removeAtIndices:(NSArray *)removeAtIndices
registry:(RCTSparseArray *)registry;
registry:(NSDictionary<NSNumber *, id<RCTComponent>> *)registry;
@property (nonatomic, readonly) RCTSparseArray *viewRegistry;
@property (nonatomic, copy, readonly) NSMutableDictionary<NSNumber *, UIView *> *viewRegistry;
@end
@@ -50,13 +49,13 @@
for (NSInteger i = 1; i <= 20; i++) {
UIView *registeredView = [UIView new];
registeredView.reactTag = @(i);
_uiManager.viewRegistry[i] = registeredView;
_uiManager.viewRegistry[@(i)] = registeredView;
}
}
- (void)testManagingChildrenToAddViews
{
UIView *containerView = _uiManager.viewRegistry[20];
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *addedViews = [NSMutableArray array];
NSArray *tagsToAdd = @[@1, @2, @3, @4, @5];
@@ -86,7 +85,7 @@
- (void)testManagingChildrenToRemoveViews
{
UIView *containerView = _uiManager.viewRegistry[20];
UIView *containerView = _uiManager.viewRegistry[@20];
NSMutableArray *removedViews = [NSMutableArray array];
NSArray *removeAtIndices = @[@0, @4, @8, @12, @16];
@@ -95,7 +94,7 @@
[removedViews addObject:_uiManager.viewRegistry[reactTag]];
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView addSubview:view];
}
@@ -119,7 +118,7 @@
_uiManager.viewRegistry[view.reactTag] = view;
}
for (NSInteger i = 2; i < 20; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
if (![removedViews containsObject:view]) {
XCTAssertTrue([view superview] == containerView,
@"Should not have removed view with react tag %ld during delete but did", (long)i);
@@ -138,7 +137,7 @@
// [11,5,1,2,7,8,12,10]
- (void)testManagingChildrenToAddRemoveAndMove
{
UIView *containerView = _uiManager.viewRegistry[20];
UIView *containerView = _uiManager.viewRegistry[@20];
NSArray *removeAtIndices = @[@2, @3, @5, @8];
NSArray *addAtIndices = @[@0, @6];
@@ -155,7 +154,7 @@
}
for (NSInteger i = 1; i < 11; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
[containerView addSubview:view];
}
@@ -180,7 +179,7 @@
// Clean up after ourselves
for (NSInteger i = 1; i < 13; i++) {
UIView *view = _uiManager.viewRegistry[i];
UIView *view = _uiManager.viewRegistry[@(i)];
[view removeFromSuperview];
}
for (UIView *view in viewsToRemove) {