forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmptyTests.swift
45 lines (34 loc) · 1.14 KB
/
EmptyTests.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
//
// EmptyTests.swift
// XMLCoderTests
//
// Created by Vincent Esche on 12/19/18.
//
import XCTest
@testable import XMLCoder
class EmptyTests: XCTestCase {
struct Container: Codable, Equatable {
// empty
func encode(to _: Encoder) throws {
// do nothing
}
}
func testAttribute() throws {
let decoder = XMLDecoder()
let encoder = XMLEncoder()
encoder.nodeEncodingStrategy = .custom { _, _ in
{ _ in .attribute }
}
XCTAssertThrowsError(try decoder.decode(Container.self, from: Data()))
let encoded = try encoder.encode(Container(), withRootKey: "container")
XCTAssertEqual(String(data: encoded, encoding: .utf8)!, "<container />")
}
func testElement() throws {
let decoder = XMLDecoder()
let encoder = XMLEncoder()
encoder.outputFormatting = [.prettyPrinted]
XCTAssertThrowsError(try decoder.decode(Container.self, from: Data()))
let encoded = try encoder.encode(Container(), withRootKey: "container")
XCTAssertEqual(String(data: encoded, encoding: .utf8)!, "<container />")
}
}