ObjFW  Diff

Differences From Artifact [fbfa925551]:

To Artifact [2e899d37b6]:


28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







-
+







    @"null//bar\n,\"foo\",false]}";

@implementation OFJSONTests
- (void)setUp
{
	[super setUp];

	_dictionary = [[OFDictionary alloc] initWithKeysAndObjects:
	_dictionary = [[OTOrderedDictionary alloc] initWithKeysAndObjects:
	    @"foo", @"b\na\r",
	    @"x", [OFArray arrayWithObjects:
		[OFNumber numberWithFloat: .5f],
		[OFNumber numberWithInt: 0xF],
		[OFNull null],
		@"foo",
		[OFNumber numberWithBool: false],
54
55
56
57
58
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
98
99
100
54
55
56
57
58
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







-
+
-
-
-
-
-
-
+




-
-
+
+
-
-
-
-
-
-

-
+




-
-
+
+
-
-
-
-
-
-
+







- (void)testObjectByParsingJSON
{
	OTAssertEqualObjects(string.objectByParsingJSON, _dictionary);
}

- (void)testJSONRepresentation
{
	OFString *representation = _dictionary.JSONRepresentation;
	OTAssert(_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]}"]);
	    @"{\"foo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}");
}

- (void)testPrettyJSONRepresentation
{
	OFString *representation = [_dictionary JSONRepresentationWithOptions:
	    OFJSONRepresentationOptionPretty];
	OTAssertEqualObjects([_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}"] ||
	    [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}"]);
	    @"\n\t\tnull,\n\t\t\"foo\",\n\t\tfalse\n\t]\n}");
}

- (void)testJSON5Representation
{
	OFString *representation = [_dictionary JSONRepresentationWithOptions:
	    OFJSONRepresentationOptionJSON5];
	OTAssertEqualObjects([_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]}"]);
	    @"{foo:\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}");
}

- (void)testObjectByParsingJSONFailsWithInvalidJSON
{
	OTAssertThrowsSpecific([@"{" objectByParsingJSON],
	    OFInvalidJSONException);