Skip to content

Commit cc23f46

Browse files
committed
[cxx-interop] Add a test for std::optional usage from Swift
1 parent c942dac commit cc23f46

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

test/Interop/Cxx/stdlib/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ module StdMap {
1313
requires cplusplus
1414
}
1515

16+
module StdOptional {
17+
header "std-optional.h"
18+
requires cplusplus
19+
}
20+
1621
module StdSet {
1722
header "std-set.h"
1823
requires cplusplus
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_OPTIONAL_H
2+
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_OPTIONAL_H
3+
4+
#include <optional>
5+
6+
using CxxOptional = std::optional<int>;
7+
8+
inline CxxOptional getNonNilOptional() { return {123}; }
9+
10+
inline CxxOptional getNilOptional() { return {std::nullopt}; }
11+
12+
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_OPTIONAL_H
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xcc -std=c++17)
2+
//
3+
// REQUIRES: executable_test
4+
// REQUIRES: OS=macosx
5+
6+
import StdlibUnittest
7+
import StdOptional
8+
import CxxStdlib
9+
10+
var StdOptionalTestSuite = TestSuite("StdOptional")
11+
12+
StdOptionalTestSuite.test("pointee") {
13+
let nonNilOpt = getNonNilOptional()
14+
let pointee = nonNilOpt.pointee
15+
expectEqual(123, pointee)
16+
}
17+
18+
runAllTests()

0 commit comments

Comments
 (0)