@@ -18,28 +18,22 @@ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFJSONTests: OTTestCase { - unsigned long long _hashSeed; OFDictionary *_dictionary; } @end -extern unsigned long long OFHashSeed; - static OFString *string = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," @"null//bar\n,\"foo\",false]}"; @implementation OFJSONTests - (void)setUp { [super setUp]; - _hashSeed = OFHashSeed; - OFHashSeed = 0; - _dictionary = [[OFDictionary alloc] initWithKeysAndObjects: @"foo", @"b\na\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: .5f], [OFNumber numberWithInt: 0xF], @@ -48,17 +42,10 @@ [OFNumber numberWithBool: false], nil], nil]; } -- (void)tearDown -{ - OFHashSeed = _hashSeed; - - [super tearDown]; -} - - (void)dealloc { [_dictionary release]; [super dealloc]; @@ -69,27 +56,43 @@ OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { - OTAssertEqualObjects(_dictionary.JSONRepresentation, - @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"); + OFString *representation = _dictionary.JSONRepresentation; + + OTAssert( + [representation isEqual: + @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"] || + [representation isEqual: + @"{\"foo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}"]); } - (void)testPrettyJSONRepresentation { - OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: - OFJSONRepresentationOptionPretty], + OFString *representation = [_dictionary JSONRepresentationWithOptions: + OFJSONRepresentationOptionPretty]; + + OTAssert( + [representation isEqual: @"{\n\t\"x\": [\n\t\t0.5,\n\t\t15,\n\t\tnull,\n\t\t" - @"\"foo\",\n\t\tfalse\n\t],\n\t\"foo\": \"b\\na\\r\"\n}"); + @"\"foo\",\n\t\tfalse\n\t],\n\t\"foo\": \"b\\na\\r\"\n}"] || + [representation isEqual: + @"{\n\t\"foo\": \"b\\na\\r\",\n\t\"x\": [\n\t\t0.5,\n\t\t15," + @"\n\t\tnull,\n\t\t\"foo\",\n\t\tfalse\n\t]\n}"]); } - (void)testJSON5Representation { - OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: - OFJSONRepresentationOptionJSON5], - @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"); + OFString *representation = [_dictionary JSONRepresentationWithOptions: + OFJSONRepresentationOptionJSON5]; + + OTAssert( + [representation isEqual: + @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"] || + [representation isEqual: + @"{foo:\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}"]); } - (void)testObjectByParsingJSONFailsWithInvalidJSON { OTAssertThrowsSpecific([@"{" objectByParsingJSON],