aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMNSDictionary+URLArgumentsTest.m
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-07-29 02:00:24 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-07-29 02:00:24 +0000
commiteff8351b590bcf190b175e2add2ab87c8e7204ec (patch)
treebf73a229e0bf1d397d93461fea55e076c5fa87a4 /Foundation/GTMNSDictionary+URLArgumentsTest.m
parentb65c5509d204b37eb79af1307f04a048806def48 (diff)
[Author: iwade]
Add gtm_dictionaryWithHttpArgumentsString to NSDictionary+URLArguments. R=thomasvl APPROVED=thomasvl DELTA=73 (72 added, 0 deleted, 1 changed)
Diffstat (limited to 'Foundation/GTMNSDictionary+URLArgumentsTest.m')
-rw-r--r--Foundation/GTMNSDictionary+URLArgumentsTest.m33
1 files changed, 33 insertions, 0 deletions
diff --git a/Foundation/GTMNSDictionary+URLArgumentsTest.m b/Foundation/GTMNSDictionary+URLArgumentsTest.m
index f01519e..8ec9520 100644
--- a/Foundation/GTMNSDictionary+URLArgumentsTest.m
+++ b/Foundation/GTMNSDictionary+URLArgumentsTest.m
@@ -25,6 +25,39 @@
@implementation GTMNSDictionary_URLArgumentsTest
+- (void)testFromArgumentsString {
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@""],
+ [NSDictionary dictionary],
+ @"- empty arguments string should give an empty dictionary");
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@"a"],
+ [NSDictionary dictionaryWithObject:@"" forKey:@"a"],
+ @"- missing '=' should result in an empty string value");
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@"a="],
+ [NSDictionary dictionaryWithObject:@"" forKey:@"a"],
+ @"- no value");
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@"&a=1"],
+ [NSDictionary dictionaryWithObject:@"1" forKey:@"a"],
+ @"- empty segment should be skipped");
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@"abc=123"],
+ [NSDictionary dictionaryWithObject:@"123" forKey:@"abc"],
+ @"- simple one-pair dictionary should work");
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@"a=1&a=2&a=3"],
+ [NSDictionary dictionaryWithObject:@"1" forKey:@"a"],
+ @"- only first occurrence of a key is returned");
+ NSString* complex = @"a%2Bb=specialkey&complex=1%2B1%21%3D3%20%26%202%2A6%2F3%3D4&c";
+ NSDictionary* result = [NSDictionary dictionaryWithObjectsAndKeys:
+ @"1+1!=3 & 2*6/3=4", @"complex",
+ @"specialkey", @"a+b",
+ @"", @"c",
+ nil];
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:complex],
+ result,
+ @"- keys and values should be unescaped correctly");
+ STAssertEqualObjects([NSDictionary gtm_dictionaryWithHttpArgumentsString:@"a=%FC"],
+ [NSDictionary dictionaryWithObject:@"" forKey:@"a"],
+ @"- invalid UTF8 characters result in an empty value, not a crash");
+}
+
- (void)testArgumentsString {
STAssertEqualObjects([[NSDictionary dictionary] gtm_httpArgumentsString], @"",
@"- empty dictionary should give an empty string");