@@ -15,42 +15,46 @@ #include "config.h" #import "TestsAppDelegate.h" -static OFString *module = @"OFJSON"; +static OFString *const module = @"OFJSON"; @implementation TestsAppDelegate (JSONTests) - (void)JSONTests { void *pool = objc_autoreleasePoolPush(); - OFString *s = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF,null" - @"//bar\n,\"foo\",false]}"; - OFDictionary *d = [OFDictionary dictionaryWithKeysAndObjects: + OFString *string = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," + @"null//bar\n,\"foo\",false]}"; + OFDictionary *dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"b\na\r", @"x", [OFArray arrayWithObjects: - [OFNumber numberWithFloat: .5f], - [OFNumber numberWithInt: 0xF], - [OFNull null], - @"foo", - [OFNumber numberWithBool: false], - nil], + [OFNumber numberWithFloat: .5f], + [OFNumber numberWithInt: 0xF], + [OFNull null], + @"foo", + [OFNumber numberWithBool: false], + nil], nil]; - TEST(@"-[objectByParsingJSON] #1", [s.objectByParsingJSON isEqual: d]) + TEST(@"-[objectByParsingJSON] #1", + [string.objectByParsingJSON isEqual: dict]) - TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual: + TEST(@"-[JSONRepresentation]", + [[dict JSONRepresentation] isEqual: @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"]) - TEST(@"OF_JSON_REPRESENTATION_PRETTY", - [[d JSONRepresentationWithOptions: OF_JSON_REPRESENTATION_PRETTY] - 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}"]) - - TEST(@"OF_JSON_REPRESENTATION_JSON5", - [[d JSONRepresentationWithOptions: OF_JSON_REPRESENTATION_JSON5] - isEqual: @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"]) + TEST(@"OFJSONRepresentationOptionPretty", + [[dict JSONRepresentationWithOptions: + OFJSONRepresentationOptionPretty] 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}"]) + + TEST(@"OFJSONRepresentationOptionJSON5", + [[dict JSONRepresentationWithOptions: + OFJSONRepresentationOptionJSON5] isEqual: + @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #2", OFInvalidJSONException, [@"{" objectByParsingJSON]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #3", OFInvalidJSONException, [@"]" objectByParsingJSON])