-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathAnyCodingKeyTests.swift
57 lines (44 loc) · 1.29 KB
/
AnyCodingKeyTests.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// AnyCodingKeyTests.swift
// PotentCodables
//
// Copyright © 2021 Outfox, inc.
//
//
// Distributed under the MIT License, See LICENSE for details.
//
import Foundation
import PotentCodables
import XCTest
class AnyCodingKeyTests: XCTestCase {
func testInit() {
let intKey: AnyCodingKey = 5
XCTAssertEqual(intKey, AnyCodingKey(intValue: 5))
XCTAssertEqual(intKey.intValue, 5)
XCTAssertEqual(intKey.stringValue, "5")
let idxKey = AnyCodingKey(index: 5)
XCTAssertEqual(idxKey, AnyCodingKey(intValue: 5))
XCTAssertEqual(idxKey.intValue, 5)
XCTAssertEqual(idxKey.stringValue, "5")
let strKey: AnyCodingKey = "test"
XCTAssertEqual(strKey, AnyCodingKey(stringValue: "test"))
XCTAssertEqual(strKey.stringValue, "test")
XCTAssertEqual(strKey.intValue, nil)
}
func testConvert() {
enum StrKey: CodingKey {
case test
}
let strKey = AnyCodingKey(StrKey.test)
XCTAssertEqual(strKey.stringValue, "test")
XCTAssertNil(strKey.intValue)
XCTAssertEqual(try strKey.key() as StrKey, .test)
enum IntKey: Int, CodingKey {
case test = 1
}
let intKey = AnyCodingKey(IntKey.test)
XCTAssertEqual(intKey.stringValue, "1")
XCTAssertEqual(intKey.intValue, 1)
XCTAssertEqual(try intKey.key() as IntKey, .test)
}
}