From 47d243f15e61c1c3b9988c856f7bdedbce2f2d35 Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Tue, 21 Feb 2017 10:33:04 -0800 Subject: [PATCH 1/4] add test to print nested json --- Tests/SwiftyJSONTests/PrintableTests.swift | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index f60fc8c1..75e06f55 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -120,5 +120,28 @@ class PrintableTests: XCTestCase { 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) + } } From b40b3d14e44f3a4106266f3b9fd2fb537349a53f Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Mon, 27 Feb 2017 19:10:20 -0800 Subject: [PATCH 2/4] lint --- Tests/SwiftyJSONTests/PrintableTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index 75e06f55..639baa56 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -123,7 +123,7 @@ class PrintableTests: XCTestCase { } func testJson() { - let dictionary = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"], "foo": []] as NSDictionary + 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") From 3784e8715f5f7395555df21c65c5c320d5995753 Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Mon, 27 Feb 2017 19:17:05 -0800 Subject: [PATCH 3/4] lint again --- Tests/SwiftyJSONTests/PrintableTests.swift | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index 639baa56..ce097fd3 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -117,11 +117,20 @@ 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) @@ -141,7 +150,13 @@ class PrintableTests: XCTestCase { } 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) + XCTAssertTrue(description2.range( + of: "\"json\":{", + options: NSString.CompareOptions.caseInsensitive + ) != nil) + XCTAssertTrue(description2.range( + of: description, + options: NSString.CompareOptions.caseInsensitive + ) != nil) } } From 61b55b52061694bea91207403125d97052235401 Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Mon, 27 Feb 2017 19:18:46 -0800 Subject: [PATCH 4/4] lint 3 --- Tests/SwiftyJSONTests/PrintableTests.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index ce097fd3..df2e2a56 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -132,7 +132,13 @@ class PrintableTests: XCTestCase { } func testJson() { - let dictionary = ["1": 2,"2": 2,"three": 3,"list": ["aa", "bb", "dd"], "foo": []] as NSDictionary + 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")