File tree 3 files changed +35
-15
lines changed
__Snapshots__/AnyJSONTests
3 files changed +35
-15
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ let package = Package(
60
60
dependencies: [
61
61
" _Helpers " ,
62
62
. product( name: " CustomDump " , package : " swift-custom-dump " ) ,
63
+ . product( name: " SnapshotTesting " , package : " swift-snapshot-testing " ) ,
63
64
]
64
65
) ,
65
66
. target( name: " Functions " , dependencies: [ " _Helpers " ] ) ,
Original file line number Diff line number Diff line change 8
8
@testable import _Helpers
9
9
import CustomDump
10
10
import Foundation
11
+ import SnapshotTesting
11
12
import XCTest
12
13
13
14
final class AnyJSONTests : XCTestCase {
@@ -63,21 +64,8 @@ final class AnyJSONTests: XCTestCase {
63
64
] ,
64
65
]
65
66
66
- func testDecode( ) throws {
67
- let data = try XCTUnwrap ( jsonString. data ( using: . utf8) )
68
- let decodedJSON = try AnyJSON . decoder. decode ( AnyJSON . self, from: data)
69
-
70
- XCTAssertNoDifference ( decodedJSON, jsonObject)
71
- }
72
-
73
- func testEncode( ) throws {
74
- let encoder = AnyJSON . encoder
75
- encoder. outputFormatting = [ . prettyPrinted, . sortedKeys]
76
-
77
- let data = try encoder. encode ( jsonObject)
78
- let decodedJSONString = try XCTUnwrap ( String ( data: data, encoding: . utf8) )
79
-
80
- XCTAssertNoDifference ( decodedJSONString, jsonString)
67
+ func testCodable( ) throws {
68
+ assertSnapshot ( of: jsonObject, as: . json)
81
69
}
82
70
83
71
func testInitFromCodable( ) {
Original file line number Diff line number Diff line change
1
+ {
2
+ "array" : [
3
+ 1 ,
4
+ 2 ,
5
+ 3 ,
6
+ 4 ,
7
+ 5
8
+ ],
9
+ "bool" : true ,
10
+ "double" : 3.14 ,
11
+ "integer" : 1 ,
12
+ "null" : null ,
13
+ "object" : {
14
+ "array" : [
15
+ 1 ,
16
+ 2 ,
17
+ 3 ,
18
+ 4 ,
19
+ 5
20
+ ],
21
+ "bool" : true ,
22
+ "double" : 3.14 ,
23
+ "integer" : 1 ,
24
+ "null" : null ,
25
+ "object" : {
26
+
27
+ },
28
+ "string" : " A string value"
29
+ },
30
+ "string" : " A string value"
31
+ }
You can’t perform that action at this time.
0 commit comments