Files
swift-mirror/test/Interop/Cxx/stdlib/use-std-function.swift
Egor Zhdan 2d0863aba2 [cxx-interop] Initial tests for std::function usage
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
2024-01-11 12:02:12 +00:00

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()