-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathStringToTests.swift
50 lines (39 loc) · 1003 Bytes
/
StringToTests.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
//
// StringToTests.swift
// MoreCodableTests
//
// Created by Tatsuya Tanaka on 20180221.
// Copyright © 2018年 tattn. All rights reserved.
//
import XCTest
@testable import MoreCodable
class StringToTests: XCTestCase {
let json = """
{
"int": "100",
"articleId": "abc"
}
""".data(using: .utf8)!
struct Root: Codable {
let int: StringTo<Int>
let articleId: StringTo<ArticleId>
struct ArticleId: LosslessStringConvertible, Codable {
var description: String
init?(_ description: String) {
self.description = description
}
}
}
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testExample() {
let decoder = JSONDecoder()
let root = try! decoder.decode(Root.self, from: json)
XCTAssertEqual(root.int.value, 100)
XCTAssertEqual(root.articleId.value.description, "abc")
}
}