Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve code coverage of auxiliary types (#43)
* Add unit tests for `XMLKey` * Add unit tests for `XMLHeader` * Add unit tests for `XMLStackParser` * Add unit tests for `XMLElement` * Delete a bunch of dead code from `XMLElement`
- Loading branch information
1 parent
68f9c8f
commit fec4900
Showing
8 changed files
with
180 additions
and
21 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
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
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
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,51 @@ | ||
// | ||
// XMLElementTests.swift | ||
// XMLCoderTests | ||
// | ||
// Created by Vincent Esche on 12/24/18. | ||
// | ||
|
||
import XCTest | ||
@testable import XMLCoder | ||
|
||
class XMLElementTests: XCTestCase { | ||
func testInitNull() { | ||
let null = _XMLElement(key: "foo") | ||
|
||
XCTAssertEqual(null.key, "foo") | ||
XCTAssertNil(null.value) | ||
XCTAssertEqual(null.elements, [:]) | ||
XCTAssertEqual(null.attributes, [:]) | ||
} | ||
|
||
func testInitUnkeyed() { | ||
let keyed = _XMLElement(key: "foo", box: UnkeyedBox()) | ||
|
||
XCTAssertEqual(keyed.key, "foo") | ||
XCTAssertNil(keyed.value) | ||
debugPrint(keyed.elements) | ||
XCTAssertEqual(keyed.elements, ["foo": []]) | ||
XCTAssertEqual(keyed.attributes, [:]) | ||
} | ||
|
||
func testInitKeyed() { | ||
let keyed = _XMLElement(key: "foo", box: KeyedBox( | ||
elements: [:], | ||
attributes: ["baz": NullBox(), "blee": IntBox(42)] | ||
)) | ||
|
||
XCTAssertEqual(keyed.key, "foo") | ||
XCTAssertNil(keyed.value) | ||
XCTAssertEqual(keyed.elements, [:]) | ||
XCTAssertEqual(keyed.attributes, ["blee": "42"]) | ||
} | ||
|
||
func testInitSimple() { | ||
let keyed = _XMLElement(key: "foo", box: StringBox("bar")) | ||
|
||
XCTAssertEqual(keyed.key, "foo") | ||
XCTAssertEqual(keyed.value, "bar") | ||
XCTAssertEqual(keyed.elements, [:]) | ||
XCTAssertEqual(keyed.attributes, [:]) | ||
} | ||
} |
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,61 @@ | ||
// | ||
// XMLHeaderTests.swift | ||
// XMLCoderTests | ||
// | ||
// Created by Vincent Esche on 12/24/18. | ||
// | ||
|
||
import XCTest | ||
@testable import XMLCoder | ||
|
||
class XMLHeaderTests: XCTestCase { | ||
func testInitVersionEncodingStandalone() { | ||
let header = XMLHeader(version: 1.0, encoding: "UTF-8", standalone: "yes") | ||
XCTAssertEqual(header.version, 1.0) | ||
XCTAssertEqual(header.encoding, "UTF-8") | ||
XCTAssertEqual(header.standalone, "yes") | ||
} | ||
|
||
func testInitVersionEncoding() { | ||
let header = XMLHeader(version: 1.0, encoding: "UTF-8") | ||
XCTAssertEqual(header.version, 1.0) | ||
XCTAssertEqual(header.encoding, "UTF-8") | ||
XCTAssertNil(header.standalone) | ||
} | ||
|
||
func testInitVersion() { | ||
let header = XMLHeader(version: 1.0) | ||
XCTAssertEqual(header.version, 1.0) | ||
XCTAssertNil(header.encoding) | ||
XCTAssertNil(header.standalone) | ||
} | ||
|
||
func testInit() { | ||
let header = XMLHeader() | ||
XCTAssertNil(header.version) | ||
XCTAssertNil(header.encoding) | ||
XCTAssertNil(header.standalone) | ||
} | ||
|
||
func testIsEmpty() { | ||
let empty = XMLHeader() | ||
XCTAssertTrue(empty.isEmpty()) | ||
|
||
let nonEmpty = XMLHeader(version: 1.0) | ||
XCTAssertFalse(nonEmpty.isEmpty()) | ||
} | ||
|
||
func testToXML() { | ||
let empty = XMLHeader() | ||
XCTAssertNil(empty.toXML()) | ||
|
||
let version = XMLHeader(version: 1.0) | ||
XCTAssertEqual(version.toXML(), "<?xml version=\"1.0\"?>\n") | ||
|
||
let versionEncoding = XMLHeader(version: 1.0, encoding: "UTF-8") | ||
XCTAssertEqual(versionEncoding.toXML(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") | ||
|
||
let versionEncodingStandalone = XMLHeader(version: 1.0, encoding: "UTF-8", standalone: "yes") | ||
XCTAssertEqual(versionEncodingStandalone.toXML(), "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n") | ||
} | ||
} |
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,29 @@ | ||
// | ||
// XMLKeyTests.swift | ||
// XMLCoderTests | ||
// | ||
// Created by Vincent Esche on 12/24/18. | ||
// | ||
|
||
import XCTest | ||
@testable import XMLCoder | ||
|
||
class XMLKeyTests: XCTestCase { | ||
func testInitStringValue() { | ||
let key = _XMLKey(stringValue: "foo") | ||
XCTAssertEqual(key?.stringValue, "foo") | ||
XCTAssertEqual(key?.intValue, nil) | ||
} | ||
|
||
func testInitIntValue() { | ||
let key = _XMLKey(intValue: 42) | ||
XCTAssertEqual(key?.stringValue, "42") | ||
XCTAssertEqual(key?.intValue, 42) | ||
} | ||
|
||
func testInitStringValueIntValue() { | ||
let key = _XMLKey(stringValue: "foo", intValue: 42) | ||
XCTAssertEqual(key.stringValue, "foo") | ||
XCTAssertEqual(key.intValue, 42) | ||
} | ||
} |
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
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