forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditionally conform to Combine.TopLevelDecoder (CoreOffice#132)
This enables use of `XMLDecoder` with Combine's `decode(_:decoder:)` operator by conditionally conforming to `TopLevelDecoder` when Combine is available. I explored doing the same for `TopLevelEncoder`, but `XMLEncoder` currently requires `rootKey:` to be specified at encoding time, so it's not possible to provide an implementation of `encode(_:)` without some design around how to dynamically determine the root key to use. * Conditionally conform to Combine.TopLevelDecoder * Add test and documentation for Combine integration * Remove macCatalyst from CombineTests This shouldn't be necessary because all versions of Mac Catalyst should have a version of Combine available. * Add CombineTests to the Xcode project * Disable CombineTests on macOS
- Loading branch information
Showing
4 changed files
with
68 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
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,37 @@ | ||
// | ||
// CombineTests.swift | ||
// XMLCoder | ||
// | ||
// Created by Adam Sharp on 9/29/19. | ||
// | ||
|
||
#if canImport(Combine) && !os(macOS) | ||
import Combine | ||
import Foundation | ||
import XCTest | ||
import XMLCoder | ||
|
||
private let xml = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<foo> | ||
<name>Foo</name> | ||
</foo> | ||
""".data(using: .utf8)! | ||
|
||
private struct Foo: Decodable { | ||
var name: String | ||
} | ||
|
||
@available(iOS 13.0, macOS 10.15.0, tvOS 13.0, watchOS 6.0, *) | ||
class CombineTests: XCTestCase { | ||
func testDecodeFromXMLDecoder() { | ||
let data = Just(xml) | ||
var foo: Foo? | ||
_ = data.decode(type: Foo.self, decoder: XMLDecoder()).sink( | ||
receiveCompletion: { _ in }, | ||
receiveValue: { foo = $0 } | ||
) | ||
XCTAssertEqual(foo?.name, "Foo") | ||
} | ||
} | ||
#endif |
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