mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-29 21:25:51 +08:00
Introduces RKPathMatcher. This is basically a dressed up front end to jverkoey/SOCKit. Using this will make it very easy to do complex things with patterns, resource paths, and object property interpolation thereof. Whereas RKMakePathWithObject() once took parenthesized parameters like "/stuff/(things)" it now uses colons like "/stuff/:things". It has specs and updated header docs where appropriate. Closes #305.
This commit is contained in:
22
Vendor/SOCKit/tests/SOCKitTests-Info.plist
vendored
Executable file
22
Vendor/SOCKit/tests/SOCKitTests-Info.plist
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.jeffverkoeyen.omkit</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
195
Vendor/SOCKit/tests/SOCKitTests.m
vendored
Executable file
195
Vendor/SOCKit/tests/SOCKitTests.m
vendored
Executable file
@@ -0,0 +1,195 @@
|
||||
//
|
||||
// Copyright 2011 Jeff Verkoeyen
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import <SenTestingKit/SenTestingKit.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#import "SOCKit.h"
|
||||
|
||||
typedef void (^SimpleBlock)(void);
|
||||
|
||||
@interface SOCTestObject : NSObject
|
||||
|
||||
- (id)initWithId:(NSInteger)ident floatValue:(CGFloat)flv doubleValue:(double)dv longLongValue:(long long)llv stringValue:(NSString *)string;
|
||||
- (id)initWithId:(NSInteger)ident floatValue:(CGFloat)flv doubleValue:(double)dv longLongValue:(long long)llv stringValue:(NSString *)string userInfo:(id)userInfo;
|
||||
|
||||
@property (nonatomic, readwrite, assign) NSInteger ident;
|
||||
@property (nonatomic, readwrite, assign) CGFloat flv;
|
||||
@property (nonatomic, readwrite, assign) double dv;
|
||||
@property (nonatomic, readwrite, assign) long long llv;
|
||||
@property (nonatomic, readwrite, copy) NSString* string;
|
||||
@end
|
||||
|
||||
@implementation SOCTestObject
|
||||
|
||||
@synthesize ident;
|
||||
@synthesize flv;
|
||||
@synthesize dv;
|
||||
@synthesize llv;
|
||||
@synthesize string;
|
||||
|
||||
- (void)dealloc {
|
||||
[string release]; string = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithId:(NSInteger)anIdent floatValue:(CGFloat)anFlv doubleValue:(double)aDv longLongValue:(long long)anLlv stringValue:(NSString *)aString {
|
||||
if ((self = [super init])) {
|
||||
self.ident = anIdent;
|
||||
self.flv = anFlv;
|
||||
self.dv = aDv;
|
||||
self.llv = anLlv;
|
||||
self.string = aString;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithId:(NSInteger)anIdent floatValue:(CGFloat)anFlv doubleValue:(double)aDv longLongValue:(long long)anLlv stringValue:(NSString *)aString userInfo:(id)userInfo {
|
||||
return [self initWithId:anIdent floatValue:anFlv doubleValue:aDv longLongValue:anLlv stringValue:aString];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface SOCKitTests : SenTestCase
|
||||
@end
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@implementation SOCKitTests
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testEmptyCases {
|
||||
STAssertTrue([SOCStringFromStringWithObject(nil, nil) isEqualToString:@""], @"Should be the same string.");
|
||||
|
||||
STAssertTrue([SOCStringFromStringWithObject(@"", nil) isEqualToString:@""], @"Should be the same string.");
|
||||
STAssertTrue([SOCStringFromStringWithObject(@" ", nil) isEqualToString:@" "], @"Should be the same string.");
|
||||
|
||||
STAssertTrue([SOCStringFromStringWithObject(@"abcdef", nil) isEqualToString:@"abcdef"], @"Should be the same string.");
|
||||
STAssertTrue([SOCStringFromStringWithObject(@"abcdef", [NSArray array]) isEqualToString:@"abcdef"], @"Should be the same string.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testFailureCases {
|
||||
STAssertThrows([SOCPattern patternWithString:@":dilly:isacat"], @"Parameters must be separated by strings.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testSingleParameterCoding {
|
||||
NSDictionary* obj = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:1337], @"leet",
|
||||
[NSNumber numberWithInt:5000], @"five",
|
||||
nil];
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":leet", obj) isEqualToString:@"1337"], @"Should be the same string.");
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":five", obj) isEqualToString:@"5000"], @"Should be the same string.");
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":six", obj) isEqualToString:@"(null)"], @"Should be the same string.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testMultiParameterCoding {
|
||||
NSDictionary* obj = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:1337], @"leet",
|
||||
[NSNumber numberWithInt:5000], @"five",
|
||||
nil];
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":leet/:five", obj) isEqualToString:@"1337/5000"], @"Should be the same string.");
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":five/:five", obj) isEqualToString:@"5000/5000"], @"Should be the same string.");
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":five/:five/:five/:five/:five/:five", obj) isEqualToString:@"5000/5000/5000/5000/5000/5000"], @"Should be the same string.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testCollectionOperators {
|
||||
NSDictionary* obj = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:1337], @"leet",
|
||||
[NSNumber numberWithInt:5000], @"five",
|
||||
nil];
|
||||
STAssertTrue([SOCStringFromStringWithObject(@":@count", obj) isEqualToString:@"2"], @"Should be the same string.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testOutboundParameters {
|
||||
SOCPattern* pattern = [SOCPattern patternWithString:@"soc://:ident"];
|
||||
STAssertTrue([pattern stringMatches:@"soc://3"], @"String should conform.");
|
||||
STAssertTrue([pattern stringMatches:@"soc://33413413454353254235245235"], @"String should conform.");
|
||||
|
||||
STAssertFalse([pattern stringMatches:@""], @"String should not conform.");
|
||||
STAssertFalse([pattern stringMatches:@"soc://"], @"String should not conform.");
|
||||
|
||||
STAssertTrue([pattern stringMatches:@"soc://joe"], @"String might conform.");
|
||||
|
||||
pattern = [SOCPattern patternWithString:@"soc://:ident/sandwich"];
|
||||
STAssertTrue([pattern stringMatches:@"soc://3/sandwich"], @"String should conform.");
|
||||
STAssertTrue([pattern stringMatches:@"soc://33413413454353254235245235/sandwich"], @"String should conform.");
|
||||
|
||||
STAssertFalse([pattern stringMatches:@""], @"String should not conform.");
|
||||
STAssertFalse([pattern stringMatches:@"soc://"], @"String should not conform.");
|
||||
STAssertFalse([pattern stringMatches:@"soc:///sandwich"], @"String should not conform.");
|
||||
|
||||
pattern = [SOCPattern patternWithString:@"soc://:ident/sandwich/:catName"];
|
||||
STAssertTrue([pattern stringMatches:@"soc://3/sandwich/dilly"], @"String should conform.");
|
||||
STAssertTrue([pattern stringMatches:@"soc://33413413454353254235245235/sandwich/dilly"], @"String should conform.");
|
||||
|
||||
STAssertFalse([pattern stringMatches:@""], @"String should not conform.");
|
||||
STAssertFalse([pattern stringMatches:@"soc://"], @"String should not conform.");
|
||||
STAssertFalse([pattern stringMatches:@"soc://33413413454353254235245235/sandwich/"], @"String should not conform.");
|
||||
STAssertFalse([pattern stringMatches:@"soc:///sandwich/"], @"String should not conform.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testPerformSelectorOnObjectWithSourceString {
|
||||
SOCPattern* pattern = [SOCPattern patternWithString:@"soc://:ident/:flv/:dv/:llv/:string"];
|
||||
SOCTestObject* testObject = [pattern performSelector:@selector(initWithId:floatValue:doubleValue:longLongValue:stringValue:userInfo:) onObject:[SOCTestObject class] sourceString:@"soc://3/3.5/6.14/13413143124321/dilly"];
|
||||
STAssertEquals(testObject.ident, (NSInteger)3, @"Values should be equal.");
|
||||
STAssertEquals(testObject.flv, (CGFloat)3.5, @"Values should be equal.");
|
||||
STAssertEquals(testObject.dv, 6.14, @"Values should be equal.");
|
||||
STAssertEquals(testObject.llv, (long long)13413143124321, @"Values should be equal.");
|
||||
STAssertTrue([testObject.string isEqualToString:@"dilly"], @"Values should be equal.");
|
||||
|
||||
testObject = [pattern performSelector:@selector(initWithId:floatValue:doubleValue:longLongValue:stringValue:) onObject:[SOCTestObject class] sourceString:@"soc://3/3.5/6.14/13413143124321/dilly"];
|
||||
STAssertEquals(testObject.ident, (NSInteger)3, @"Values should be equal.");
|
||||
STAssertEquals(testObject.flv, (CGFloat)3.5, @"Values should be equal.");
|
||||
STAssertEquals(testObject.dv, 6.14, @"Values should be equal.");
|
||||
STAssertEquals(testObject.llv, (long long)13413143124321, @"Values should be equal.");
|
||||
STAssertTrue([testObject.string isEqualToString:@"dilly"], @"Values should be equal.");
|
||||
|
||||
pattern = [SOCPattern patternWithString:@"soc://:ident"];
|
||||
[pattern performSelector:@selector(setIdent:) onObject:testObject sourceString:@"soc://6"];
|
||||
STAssertEquals(testObject.ident, (NSInteger)6, @"Values should be equal.");
|
||||
|
||||
[pattern performSelector:@selector(setLlv:) onObject:testObject sourceString:@"soc://6"];
|
||||
STAssertEquals(testObject.llv, (long long)6, @"Values should be equal.");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
- (void)testExtractParameterKeyValuesFromSourceString {
|
||||
SOCPattern* pattern = [SOCPattern patternWithString:@"soc://:ident/:flv/:dv/:llv/:string"];
|
||||
NSDictionary* kvs = [pattern extractParameterKeyValuesFromSourceString:@"soc://3/3.5/6.14/13413143124321/dilly"];
|
||||
STAssertEquals([[kvs objectForKey:@"ident"] intValue], 3, @"Values should be equal.");
|
||||
STAssertEquals([[kvs objectForKey:@"flv"] floatValue], 3.5f, @"Values should be equal.");
|
||||
STAssertEquals([[kvs objectForKey:@"dv"] doubleValue], 6.14, @"Values should be equal.");
|
||||
STAssertEquals([[kvs objectForKey:@"llv"] longLongValue], 13413143124321L, @"Values should be equal.");
|
||||
STAssertTrue([[kvs objectForKey:@"string"] isEqualToString:@"dilly"], @"Values should be equal.");
|
||||
}
|
||||
|
||||
@end
|
||||
2
Vendor/SOCKit/tests/en.lproj/InfoPlist.strings
vendored
Executable file
2
Vendor/SOCKit/tests/en.lproj/InfoPlist.strings
vendored
Executable file
@@ -0,0 +1,2 @@
|
||||
/* Localized versions of Info.plist keys */
|
||||
|
||||
Reference in New Issue
Block a user