mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
NSJSONSerialization: Implement NSJSONWritingSortedKeys
This commit is contained in:
parent
0606cb9db4
commit
cc0d8d88e5
3 changed files with 58 additions and 10 deletions
34
Tests/base/NSJSONSerialization/sorted.m
Normal file
34
Tests/base/NSJSONSerialization/sorted.m
Normal file
|
@ -0,0 +1,34 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
void testLexicographicalOrder() {
|
||||
NSArray *objects =
|
||||
[NSArray arrayWithObjects:@"a", @"b", @"c", @"d", @"e", nil];
|
||||
NSArray *keys = [NSArray
|
||||
arrayWithObjects:@"c_ab", @"a_ab", @"d_ab", @"f_cb", @"f_ab", nil];
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithObjects:objects
|
||||
forKeys:keys];
|
||||
|
||||
NSError *error = nil;
|
||||
NSData *actualData =
|
||||
[NSJSONSerialization dataWithJSONObject:dict
|
||||
options:NSJSONWritingSortedKeys
|
||||
error:&error];
|
||||
PASS_EQUAL(error, nil, "no error occurred during serialisation");
|
||||
|
||||
|
||||
NSString *actual = [[NSString alloc] initWithData:actualData
|
||||
encoding:NSUTF8StringEncoding];
|
||||
NSString *expected = @"{\"a_ab\":\"b\",\"c_ab\":\"a\",\"d_ab\":\"c\",\"f_"
|
||||
"ab\":\"e\",\"f_cb\":\"d\"}";
|
||||
PASS_EQUAL(actual, expected, "JSON is correctly sorted");
|
||||
NSLog(@"%@", actual);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
testLexicographicalOrder();
|
||||
|
||||
[arp release];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue