forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RootLevelAttributeTest.swift
45 lines (39 loc) · 1.19 KB
/
RootLevelAttributeTest.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
//
// RootLevelAttributeTest.swift
// XMLCoderTests
//
// Created by Benjamin Wetherfield on 9/28/19.
//
import Foundation
import XCTest
@testable import XMLCoder
private struct Policy: Encodable, DynamicNodeEncoding {
var name: String
var initial: String
enum CodingKeys: String, CodingKey {
case name, initial
}
public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding {
switch key {
case Policy.CodingKeys.name: return .attribute
default: return .element
}
}
}
let expected = """
<?xml version="1.0" encoding="UTF-8"?>
<policy name="generic">
<initial>more xml here</initial>
</policy>
"""
class RootLevelAttributeTest: XCTestCase {
func testPolicyEncodingAtRoot() throws {
let encoder = XMLEncoder()
encoder.outputFormatting = [.prettyPrinted]
let policy = Policy(name: "generic", initial: "more xml here")
let data = try encoder.encode(policy,
withRootKey: "policy",
header: XMLHeader(version: 1.0, encoding: "UTF-8"))
XCTAssertEqual(String(data: data, encoding: .utf8)!, expected)
}
}