-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from fummicc1/support-ORT-param-handler
Support `some` parameter's handler
- Loading branch information
Showing
4 changed files
with
112 additions
and
2 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
91 changes: 91 additions & 0 deletions
91
Tests/TestFuncs/TestOpaqueTypeFuncs/FixtureOpaqueTypeFunc.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,91 @@ | ||
import MockoloFramework | ||
|
||
let someParameterOptionalType = """ | ||
/// \(String.mockAnnotation) | ||
public protocol OpaqueTypeProtocol { | ||
func nonOptional(_ type: some Error) -> Int | ||
func optional(_ type: (some Error)?) | ||
} | ||
""" | ||
|
||
let someParameterOptionalTypeMock = """ | ||
public class OpaqueTypeProtocolMock: OpaqueTypeProtocol { | ||
public init() { } | ||
public private(set) var nonOptionalCallCount = 0 | ||
public var nonOptionalHandler: ((Any) -> (Int))? | ||
public func nonOptional(_ type: some Error) -> Int { | ||
nonOptionalCallCount += 1 | ||
if let nonOptionalHandler = nonOptionalHandler { | ||
return nonOptionalHandler(type) | ||
} | ||
return 0 | ||
} | ||
public private(set) var optionalCallCount = 0 | ||
public var optionalHandler: ((Any?) -> ())? | ||
public func optional(_ type: (some Error)?) { | ||
optionalCallCount += 1 | ||
if let optionalHandler = optionalHandler { | ||
optionalHandler(type) | ||
} | ||
} | ||
} | ||
""" | ||
|
||
let someMultiParameterOptionalType = """ | ||
/// \(String.mockAnnotation) | ||
public protocol OpaqueTypeWithMultiTypeProtocol { | ||
func nonOptional(_ type: some Error) -> Int | ||
func optional(_ type: ((some (Error & Foo)))?) | ||
func multiParam(_ typeA: some Error, _ typeB: some Error) | ||
} | ||
""" | ||
|
||
|
||
let someMultiParameterOptionalTypeMock = """ | ||
public class OpaqueTypeWithMultiTypeProtocolMock: OpaqueTypeWithMultiTypeProtocol { | ||
public init() { } | ||
public private(set) var nonOptionalCallCount = 0 | ||
public var nonOptionalHandler: ((Any) -> (Int))? | ||
public func nonOptional(_ type: some Error) -> Int { | ||
nonOptionalCallCount += 1 | ||
if let nonOptionalHandler = nonOptionalHandler { | ||
return nonOptionalHandler(type) | ||
} | ||
return 0 | ||
} | ||
public private(set) var optionalCallCount = 0 | ||
public var optionalHandler: ((Any?) -> ())? | ||
public func optional(_ type: ((some (Error & Foo)))?) { | ||
optionalCallCount += 1 | ||
if let optionalHandler = optionalHandler { | ||
optionalHandler(type) | ||
} | ||
} | ||
public private(set) var multiParamCallCount = 0 | ||
public var multiParamHandler: ((Any, Any) -> ())? | ||
public func multiParam(_ typeA: some Error, _ typeB: some Error) { | ||
multiParamCallCount += 1 | ||
if let multiParamHandler = multiParamHandler { | ||
multiParamHandler(typeA, typeB) | ||
} | ||
} | ||
} | ||
""" |
14 changes: 14 additions & 0 deletions
14
Tests/TestFuncs/TestOpaqueTypeFuncs/OpaqueTypeFuncTests.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,14 @@ | ||
import Foundation | ||
|
||
class OpaqueTypeFuncTests: MockoloTestCase { | ||
|
||
func testOpaqueTypeParamterFuncs() { | ||
verify(srcContent: someParameterOptionalType, | ||
dstContent: someParameterOptionalTypeMock) | ||
} | ||
|
||
func testOpaqueTypeMultiParamterFuncs() { | ||
verify(srcContent: someMultiParameterOptionalType, | ||
dstContent: someMultiParameterOptionalTypeMock) | ||
} | ||
} |