Differences From Artifact [2ee8657285]:
- File tests/OFJSONTests.m — part of check-in [7e1c8b88b7] at 2024-08-16 22:26:51 on branch trunk — Add OFJSONRepresentationOptionSorted (user: js, size: 4083) [annotate] [blame] [check-ins using]
To Artifact [4578e0b89d]:
- File
tests/OFJSONTests.m
— part of check-in
[6fbc3b18c7]
at
2024-10-27 22:27:20
on branch trunk
— Allow strings to contain \0
In order to not accidentally have C strings with \0, an
OFInvalidEncodingException is thrown when trying to get a C string for a
string that contains \0.In order to get a C string with \0 anyway, a new method
-[insecureCStringWithEncoding:] is added. (user: js, size: 4109) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
24 25 26 27 28 29 30 | @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end | | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end static OFString *string = @"{\"f\\0oo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," @"null//bar\n,\"foo\",false]}"; @implementation OFJSONTests - (void)setUp { [super setUp]; _dictionary = [[OTOrderedDictionary alloc] initWithKeysAndObjects: @"f\0oo", @"b\na\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: .5f], [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: false], nil], |
︙ | ︙ | |||
59 60 61 62 63 64 65 | { OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { OTAssert(_dictionary.JSONRepresentation, | | | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | { OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { OTAssert(_dictionary.JSONRepresentation, @"{\"f\\u0000oo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}"); } - (void)testSortedJSONRepresentation { OTAssertEqualObjects( [([OFDictionary dictionaryWithKeysAndObjects: @"b", @"a", @"a", @"b", nil]) JSONRepresentationWithOptions: OFJSONRepresentationOptionSorted], @"{\"a\":\"b\",\"b\":\"a\"}"); } - (void)testPrettyJSONRepresentation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionPretty], @"{\n\t\"f\\u0000oo\": \"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], @"{\"f\\0oo\":\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}"); } - (void)testObjectByParsingJSONFailsWithInvalidJSON { OTAssertThrowsSpecific([@"{" objectByParsingJSON], OFInvalidJSONException); |
︙ | ︙ |