Skip to content

Commit 9759c4d

Browse files
committed
[interop] add a testcase for std::set iteration in Swift
1 parent d6b6dc4 commit 9759c4d

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ module StdMap {
1212
header "std-map.h"
1313
requires cplusplus
1414
}
15+
16+
module StdSet {
17+
header "std-set.h"
18+
requires cplusplus
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
2+
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
3+
4+
#include <set>
5+
6+
using SetOfCInt = std::set<int>;
7+
8+
inline SetOfCInt initSetOfCInt() { return {1, 5, 3}; }
9+
10+
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none)
2+
//
3+
// REQUIRES: executable_test
4+
//
5+
// Enable this everywhere once we have a solution for modularizing other C++ stdlibs: rdar://87654514
6+
// REQUIRES: OS=macosx || OS=linux-gnu
7+
8+
import StdlibUnittest
9+
import StdSet
10+
import CxxStdlib
11+
import Cxx
12+
13+
var StdSetTestSuite = TestSuite("StdSet")
14+
15+
extension SetOfCInt.const_iterator : UnsafeCxxInputIterator { }
16+
extension SetOfCInt : CxxSequence { }
17+
18+
StdSetTestSuite.test("iterate") {
19+
let s = initSetOfCInt()
20+
var result = [CInt]()
21+
for x in s {
22+
result.append(x)
23+
}
24+
expectEqual(result[0], 1)
25+
expectEqual(result[1], 3)
26+
expectEqual(result[2], 5)
27+
}
28+
29+
runAllTests()

0 commit comments

Comments
 (0)