diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index f60fc8c1..df2e2a56 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -117,8 +117,52 @@ class PrintableTests: XCTestCase { description = description.replacingOccurrences(of: "\n", with: "") description = description.replacingOccurrences(of: " ", with: "") XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) - XCTAssertTrue(description.range(of: "\"1\":2", options: NSString.CompareOptions.caseInsensitive) != nil) - XCTAssertTrue(description.range(of: "\"2\":\"two\"", options: NSString.CompareOptions.caseInsensitive) != nil) - XCTAssertTrue(description.range(of: "\"3\":null", options: NSString.CompareOptions.caseInsensitive) != nil) - } + XCTAssertTrue(description.range( + of: "\"1\":2", + options: NSString.CompareOptions.caseInsensitive) != nil + ) + XCTAssertTrue(description.range( + of: "\"2\":\"two\"", + options: NSString.CompareOptions.caseInsensitive) != nil + ) + XCTAssertTrue(description.range( + of: "\"3\":null", + options: NSString.CompareOptions.caseInsensitive) != nil + ) + } + + func testJson() { + let dictionary = [ + "1": 2, + "2": 2, + "three": 3, + "list": ["aa", "bb", "dd"], + "foo": [], + ] as NSDictionary + let json = JSON(dictionary) + guard var description = json.rawString([.castNilToNSNull: true]) else { + XCTFail("could not represent dictionary") + return + } + description = description.replacingOccurrences(of: "\n", with: "") + description = description.replacingOccurrences(of: " ", with: "") + + let dict2 = ["json": json, "baa": "boo"] as [String: Any?] + let json2 = JSON(dict2) + + guard var description2 = json2.rawString([.castNilToNSNull: true]) else { + XCTFail("could not represent json") + return + } + description2 = description2.replacingOccurrences(of: "\n", with: "") + description2 = description2.replacingOccurrences(of: " ", with: "") + XCTAssertTrue(description2.range( + of: "\"json\":{", + options: NSString.CompareOptions.caseInsensitive + ) != nil) + XCTAssertTrue(description2.range( + of: description, + options: NSString.CompareOptions.caseInsensitive + ) != nil) + } }