-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathCodingTests.swift
40 lines (26 loc) · 1.29 KB
/
CodingTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Foundation
import OrderedDictionary
import XCTest
class CodingTests: XCTestCase {
func testEncodingAndDecodingViaJSON() throws {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let jsonEncoder = JSONEncoder()
let data = try jsonEncoder.encode(orderedDictionary)
let actualString = String(data: data, encoding: .utf8)
let expectedString = "[\"a\",1,\"b\",2,\"c\",3]"
XCTAssertEqual(actualString, expectedString)
let jsonDecoder = JSONDecoder()
let actual = try jsonDecoder.decode(OrderedDictionary<String, Int>.self, from: data)
let expected = orderedDictionary
XCTAssertEqual(actual, expected)
}
func testEncodingAndDecodingViaPropertyList() throws {
let orderedDictionary: OrderedDictionary<String, Int> = ["a": 1, "b": 2, "c": 3]
let plistEncoder = PropertyListEncoder()
let data = try plistEncoder.encode(orderedDictionary)
let plistDecoder = PropertyListDecoder()
let actual = try plistDecoder.decode(OrderedDictionary<String, Int>.self, from: data)
let expected = orderedDictionary
XCTAssertEqual(actual, expected)
}
}