mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Correctly try to unwrap InboundIn
This commit is contained in:
1 parent
251e63e82b
commit
0c3d04580b
3 files changed
+18
-1
No files matched your search
@@ -46,7 +46,7 @@ public extension ChannelInboundHandler {
|
||||
}
|
||||
|
||||
func tryUnwrapInboundIn(_ value: IOData) -> InboundIn? {
|
||||
return value.forceAs()
|
||||
return value.tryAs()
|
||||
}
|
||||
|
||||
func wrapInboundOut(_ value: InboundOut) -> IOData {
|
||||
|
||||
@@ -26,6 +26,7 @@ extension TypeAssistedChannelHandlerTest {
|
||||
|
||||
static var allTests : [(String, (TypeAssistedChannelHandlerTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("testOptionalInboundIn", testOptionalInboundIn),
|
||||
("testCanDefineBothInboundAndOutbound", testCanDefineBothInboundAndOutbound),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -17,6 +17,22 @@ import XCTest
|
||||
@testable import NIO
|
||||
|
||||
class TypeAssistedChannelHandlerTest: XCTestCase {
|
||||
func testOptionalInboundIn() throws {
|
||||
class TestClass: ChannelInboundHandler {
|
||||
public typealias InboundIn = String
|
||||
|
||||
func canUnwrap(_ data: IOData) -> Bool {
|
||||
return tryUnwrapInboundIn(data) != nil
|
||||
}
|
||||
}
|
||||
|
||||
let c = TestClass()
|
||||
let goodIOData = IOData("Hello, world!")
|
||||
let badIOData = IOData(42)
|
||||
XCTAssertTrue(c.canUnwrap(goodIOData))
|
||||
XCTAssertFalse(c.canUnwrap(badIOData))
|
||||
}
|
||||
|
||||
func testCanDefineBothInboundAndOutbound() throws {
|
||||
class TestClass: ChannelInboundHandler, ChannelOutboundHandler {
|
||||
public typealias OutboundIn = ByteBuffer
|
||||
|
||||
Reference in new issue
Block a user