mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This makes sure that `std::function` is imported consistently on supported platforms, and that it allows basic usage: calling a function with `callAsFunction`, initializing an empty function, and passing a function retrieved from C++ back to C++ as a parameter. rdar://103979602
30 lines
730 B
Swift
30 lines
730 B
Swift
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
|
|
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
import StdlibUnittest
|
|
import StdFunction
|
|
|
|
var StdFunctionTestSuite = TestSuite("StdFunction")
|
|
|
|
StdFunctionTestSuite.test("init empty") {
|
|
let f = FunctionIntToInt()
|
|
expectTrue(isEmptyFunction(f))
|
|
|
|
let copied = f
|
|
expectTrue(isEmptyFunction(copied))
|
|
}
|
|
|
|
StdFunctionTestSuite.test("call") {
|
|
let f = getIdentityFunction()
|
|
expectEqual(123, f(123))
|
|
}
|
|
|
|
StdFunctionTestSuite.test("retrieve and pass back as parameter") {
|
|
let res = invokeFunction(getIdentityFunction(), 456)
|
|
expectEqual(456, res)
|
|
}
|
|
|
|
runAllTests()
|