Skip to content

Commit

Permalink
Add single array element example to tests (#66)
Browse files Browse the repository at this point in the history
Resolves #65
  • Loading branch information
MaxDesiatov committed Jan 18, 2019
1 parent 7583691 commit 2f7b0d6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Tests/XMLCoderTests/SingleChildTests.swift
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),
]
}
4 changes: 4 additions & 0 deletions XMLCoder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
BF9457F521CBB6BC005ACFDE /* DecimalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9457EA21CBB6BC005ACFDE /* DecimalTests.swift */; };
BF9457F621CBB6BC005ACFDE /* KeyedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9457EB21CBB6BC005ACFDE /* KeyedTests.swift */; };
BF9457F721CBB6BC005ACFDE /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9457EC21CBB6BC005ACFDE /* DataTests.swift */; };
D14D8A8621F1D6B300B0D31A /* SingleChildTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14D8A8521F1D6B300B0D31A /* SingleChildTests.swift */; };
D1CB1EF521EA9599009CAF02 /* RJITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_37 /* RJITest.swift */; };
D1E0C85321D8E65E0042A261 /* ErrorContextTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C85121D8E6540042A261 /* ErrorContextTest.swift */; };
D1E0C85521D91EBF0042A261 /* Metatypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C85421D91EBF0042A261 /* Metatypes.swift */; };
Expand Down Expand Up @@ -175,6 +176,7 @@
BF9457EA21CBB6BC005ACFDE /* DecimalTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DecimalTests.swift; sourceTree = "<group>"; };
BF9457EB21CBB6BC005ACFDE /* KeyedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyedTests.swift; sourceTree = "<group>"; };
BF9457EC21CBB6BC005ACFDE /* DataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTests.swift; sourceTree = "<group>"; };
D14D8A8521F1D6B300B0D31A /* SingleChildTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleChildTests.swift; sourceTree = "<group>"; };
D1E0C85121D8E6540042A261 /* ErrorContextTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorContextTest.swift; sourceTree = "<group>"; };
D1E0C85421D91EBF0042A261 /* Metatypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metatypes.swift; sourceTree = "<group>"; };
D1FC040421C7EF8200065B43 /* RJISample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RJISample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -353,6 +355,7 @@
BF63EF1D21CEC99A001D38C5 /* BenchmarkTests.swift */,
D1FC040421C7EF8200065B43 /* RJISample.swift */,
A61DCCD621DF8DB300C0A19D /* ClassTests.swift */,
D14D8A8521F1D6B300B0D31A /* SingleChildTests.swift */,
);
name = XMLCoderTests;
path = Tests/XMLCoderTests;
Expand Down Expand Up @@ -549,6 +552,7 @@
BF9457D121CBB516005ACFDE /* UnkeyedBoxTests.swift in Sources */,
BF63EF6921D0FDB5001D38C5 /* XMLHeaderTests.swift in Sources */,
BF9457F021CBB6BC005ACFDE /* StringTests.swift in Sources */,
D14D8A8621F1D6B300B0D31A /* SingleChildTests.swift in Sources */,
A61FE03921E4D60B0015D993 /* UnkeyedIntTests.swift in Sources */,
BF63EF6B21D10284001D38C5 /* XMLElementTests.swift in Sources */,
BF9457ED21CBB6BC005ACFDE /* BoolTests.swift in Sources */,
Expand Down

0 comments on commit 2f7b0d6

Please sign in to comment.