New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make TopLevelEncoder implementation overridable #182
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,12 @@ private struct Foo: Codable { | |||||
var name: String | ||||||
} | ||||||
|
||||||
final class CustomEncoder: XMLEncoder { | ||||||
override func encode<T>(_ value: T) throws -> Data where T : Encodable { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry I didn't check SwiftFormat. I fixed in 18282b5. |
||||||
try self.encode(value, withRootKey: "bar", rootAttributes: nil, header: nil) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed in 84c33e7. |
||||||
} | ||||||
} | ||||||
|
||||||
@available(iOS 13.0, macOS 10.15.0, tvOS 13.0, watchOS 6.0, *) | ||||||
final class CombineTests: XCTestCase { | ||||||
func testDecode() { | ||||||
|
@@ -51,5 +57,21 @@ final class CombineTests: XCTestCase { | |||||
) | ||||||
XCTAssertEqual(foo?.name, "Foo") | ||||||
} | ||||||
|
||||||
func testCustomEncode() { | ||||||
var foo: Data? | ||||||
_ = Just(Foo(name: "Foo")) | ||||||
.encode(encoder: CustomEncoder()) | ||||||
.sink( | ||||||
receiveCompletion: { _ in }, | ||||||
receiveValue: { | ||||||
foo = $0 | ||||||
} | ||||||
) | ||||||
XCTAssertEqual( | ||||||
String(data: foo!, encoding: .utf8)!, | ||||||
"<bar><name>Foo</name></bar>" | ||||||
) | ||||||
} | ||||||
} | ||||||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed in 84c33e7.