-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add single array element example to tests (#66)
Resolves #65
- Loading branch information
1 parent
7583691
commit 2f7b0d6
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// SingleChild.swift | ||
// XMLCoderTests | ||
// | ||
// Created by Max Desiatov on 18/01/2019. | ||
// | ||
|
||
import XCTest | ||
@testable import XMLCoder | ||
|
||
struct ProudParent: Codable, Equatable { | ||
var myChildAge: [Int] | ||
} | ||
|
||
final class Test: XCTestCase { | ||
func testEncoder() throws { | ||
let encoder = XMLEncoder() | ||
|
||
let parent = ProudParent(myChildAge: [2]) | ||
let expectedXML = | ||
""" | ||
<ProudParent><myChildAge>2</myChildAge></ProudParent> | ||
""".data(using: .utf8)! | ||
|
||
let encodedXML = try encoder.encode(parent, withRootKey: "ProudParent") | ||
|
||
XCTAssertEqual(expectedXML, encodedXML) | ||
} | ||
|
||
func testDecoder() throws { | ||
let decoder = XMLDecoder() | ||
|
||
let parent = ProudParent(myChildAge: [2]) | ||
let xml = | ||
""" | ||
<ProudParent><myChildAge>2</myChildAge></ProudParent> | ||
""".data(using: .utf8)! | ||
|
||
let decoded = try decoder.decode(ProudParent.self, from: xml) | ||
|
||
XCTAssertEqual(decoded, parent) | ||
} | ||
|
||
static var allTests = [ | ||
("testDecoder", testDecoder), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters