mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Add tests for NSURLComponents
This commit is contained in:
parent
d05b799740
commit
564f61d572
3 changed files with 59 additions and 14 deletions
|
@ -700,8 +700,6 @@ GS_NSURLComponents_IVARS;
|
|||
- (NSArray *) percentEncodedQueryItems;
|
||||
- (void) setPercentEncodedQueryItems: (NSArray *)queryItems;
|
||||
#endif
|
||||
- (NSString *) percentEncodedScheme;
|
||||
- (void) setPercentEncodedScheme: (NSString *)scheme;
|
||||
- (NSString *) percentEncodedUser;
|
||||
- (void) setPercentEncodedUser: (NSString *)user;
|
||||
|
||||
|
|
|
@ -2419,7 +2419,7 @@ GS_PRIVATE_INTERNAL(NSURLComponents)
|
|||
// Build up the URL from components...
|
||||
if (internal->_scheme != nil)
|
||||
{
|
||||
NSString *comp = [self percentEncodedScheme];
|
||||
NSString *comp = [self scheme];
|
||||
NSInteger len = [comp length];
|
||||
urlString = [urlString stringByAppendingFormat: @"%@://", comp];
|
||||
internal->_rangeOfScheme = NSMakeRange(location, len);
|
||||
|
@ -2779,17 +2779,6 @@ GS_PRIVATE_INTERNAL(NSURLComponents)
|
|||
[self setQueryItems: items];
|
||||
}
|
||||
|
||||
- (NSString *) percentEncodedScheme
|
||||
{
|
||||
return [internal->_scheme stringByAddingPercentEncodingWithAllowedCharacters:
|
||||
[NSCharacterSet URLPathAllowedCharacterSet]];
|
||||
}
|
||||
|
||||
- (void) setPercentEncodedScheme: (NSString *)scheme
|
||||
{
|
||||
[self setScheme: [scheme stringByRemovingPercentEncoding]];
|
||||
}
|
||||
|
||||
- (NSString *) percentEncodedUser
|
||||
{
|
||||
return [internal->_user stringByAddingPercentEncodingWithAllowedCharacters:
|
||||
|
|
58
Tests/base/NSURL/components.m
Normal file
58
Tests/base/NSURL/components.m
Normal file
|
@ -0,0 +1,58 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "Testing.h"
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
START_SET("components");
|
||||
|
||||
NSURLComponents *components = [NSURLComponents componentsWithURL:[NSURL URLWithString:@"https://user:password@some.host.com"] resolvingAgainstBaseURL:NO];
|
||||
|
||||
PASS([[[components URL] absoluteString] isEqualToString: @"https://user:password@some.host.com"],
|
||||
"Absolute URL string is correct");
|
||||
|
||||
|
||||
[components setQueryItems: [NSArray arrayWithObjects:
|
||||
[NSURLQueryItem queryItemWithName:@"lang" value:@"en"],
|
||||
[NSURLQueryItem queryItemWithName:@"response_type" value:@"code"],
|
||||
[NSURLQueryItem queryItemWithName:@"uri" value:[NSURL URLWithString:@"https://some.url.com/path?param1=one¶m2=two"].absoluteString],
|
||||
nil]];
|
||||
// URL
|
||||
PASS([[components string] isEqualToString:
|
||||
@"https://user:password@some.host.com?lang=en&response_type=code&uri=https://some.url.com/path?param1%3Done%26param2%3Dtwo"],
|
||||
"URL string is correct");
|
||||
|
||||
// encoded...
|
||||
PASS([[components percentEncodedQuery] isEqualToString:
|
||||
@"lang=en&response_type=code&uri=https://some.url.com/path?param1%3Done%26param2%3Dtwo"],
|
||||
"percentEncodedQuery is correct");
|
||||
PASS([[components percentEncodedHost] isEqualToString:
|
||||
@"some.host.com"],
|
||||
"percentEncodedHost is correct");
|
||||
PASS([[components percentEncodedUser] isEqualToString:
|
||||
@"user"],
|
||||
"percentEncodedUser is correct");
|
||||
PASS([[components percentEncodedPassword] isEqualToString:
|
||||
@"password"],
|
||||
"percentEncodedPassword is correct");
|
||||
|
||||
// unencoded...
|
||||
PASS([[components query] isEqualToString:
|
||||
@"lang=en&response_type=code&uri=https://some.url.com/path?param1=one¶m2=two"],
|
||||
"query is correct");
|
||||
PASS([[components host] isEqualToString:
|
||||
@"some.host.com"],
|
||||
"host is correct");
|
||||
PASS([[components user] isEqualToString:
|
||||
@"user"],
|
||||
"user is correct");
|
||||
PASS([[components password] isEqualToString:
|
||||
@"password"],
|
||||
"password is correct");
|
||||
|
||||
|
||||
END_SET("components")
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue