Index: tests/OFJSONTests.m ================================================================== --- tests/OFJSONTests.m +++ tests/OFJSONTests.m @@ -21,19 +21,22 @@ #import "OFDictionary.h" #import "OFNumber.h" #import "OFNull.h" #import "OFAutoreleasePool.h" +#import "OFInvalidEncodingException.h" + #import "TestsAppDelegate.h" static OFString *module = @"OFJSON"; @implementation TestsAppDelegate (JSONTests) - (void)JSONTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *s = @"{\"foo\"\t:\"bar\", \"x\": [7.5\r,null,\"foo\",false]}"; + OFString *s = @"{\"foo\"\t:\"bar\", \"x\":/*fooo*/ [7.5\r,null//bar\n" + @",\"foo\",false]}"; OFDictionary *d = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: 7.5], [OFNull null], @@ -40,13 +43,22 @@ @"foo", [OFNumber numberWithBool: NO], nil], nil]; - TEST(@"-[JSONValue]", [[s JSONValue] isEqual: d]) + TEST(@"-[JSONValue #1]", [[s JSONValue] isEqual: d]) TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual: @"{\"foo\":\"bar\",\"x\":[7.5,null,\"foo\",false]}"]) + + EXPECT_EXCEPTION(@"-[JSONValue #2]", OFInvalidEncodingException, + [@"{" JSONValue]) + EXPECT_EXCEPTION(@"-[JSONValue #3]", OFInvalidEncodingException, + [@"]" JSONValue]) + EXPECT_EXCEPTION(@"-[JSONValue #4]", OFInvalidEncodingException, + [@"bar" JSONValue]) + EXPECT_EXCEPTION(@"-[JSONValue #5]", OFInvalidEncodingException, + [@"[\"a\" \"b\"]" JSONValue]) [pool drain]; } @end