Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update doc comments, add
PropertyWrappersTest
(#246)
When viewing documentation published at https://swiftpackageindex.com/CoreOffice/XMLCoder/main/documentation/xmlcoder, I noticed that some of the doc comments are missing, and we made some of the protocols `public` by mistake. I've added doc comments with example code and update those protocols accordingly. Additionally, tests and a section in `README.md` for recently added property wrappers were missing, that's fixed as well.
- Loading branch information
1 parent
ffd257a
commit 1b15e5a
Showing
11 changed files
with
240 additions
and
12 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
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
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
69 changes: 69 additions & 0 deletions
69
Tests/XMLCoderTests/AdvancedFeatures/PropertyWrappersTest.swift
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,69 @@ | ||
// | ||
// PropertyWrappersTest.swift | ||
// XMLCoderTests | ||
// | ||
// Created by Max Desiatov on 17/08/2022. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
import XMLCoder | ||
|
||
private struct Book: Codable, Equatable { | ||
@Attribute var id: Int | ||
@Element var name: String | ||
@ElementAndAttribute var authorID: Int | ||
|
||
init(id: Int, name: String, authorID: Int) { | ||
_id = Attribute(id) | ||
_name = Element(name) | ||
_authorID = ElementAndAttribute(authorID) | ||
} | ||
} | ||
|
||
private let bookAuthorElementAndAttributeXML = | ||
""" | ||
<Book id="42" authorID="24"> | ||
<name>The Book</name> | ||
<authorID>24</authorID> | ||
</Book> | ||
""" | ||
|
||
private let bookAuthorAttributeXML = | ||
""" | ||
<Book id="42" authorID="24"> | ||
<name>The Book</name> | ||
</Book> | ||
""" | ||
|
||
private let bookAuthorElementXML = | ||
""" | ||
<Book id="42"> | ||
<authorID>24</authorID> | ||
<name>The Book</name> | ||
</Book> | ||
""" | ||
|
||
private let book = Book(id: 42, name: "The Book", authorID: 24) | ||
|
||
final class PropertyWrappersTest: XCTestCase { | ||
func testEncode() throws { | ||
let encoder = XMLEncoder() | ||
encoder.outputFormatting = .prettyPrinted | ||
|
||
let xml = try String(data: encoder.encode(book), encoding: .utf8) | ||
|
||
XCTAssertEqual(bookAuthorElementAndAttributeXML, xml) | ||
} | ||
|
||
func testDecode() throws { | ||
let decoder = XMLDecoder() | ||
let decodedBookBoth = try decoder.decode(Book.self, from: Data(bookAuthorElementAndAttributeXML.utf8)) | ||
let decodedBookElement = try decoder.decode(Book.self, from: Data(bookAuthorElementXML.utf8)) | ||
let decodedBookAttribute = try decoder.decode(Book.self, from: Data(bookAuthorAttributeXML.utf8)) | ||
|
||
XCTAssertEqual(book, decodedBookBoth) | ||
XCTAssertEqual(book, decodedBookElement) | ||
XCTAssertEqual(book, decodedBookAttribute) | ||
} | ||
} |
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