Skip to content

Commit cb76fa1

Browse files
authored
Merge pull request swiftlang#42379 from cabmeurer/cabmeurer/std-iterator-available-operations
[cxx-interop] Add tests for the available operations of `std::iterator`
2 parents 0042354 + 7233635 commit cb76fa1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
2+
//
3+
// REQUIRES: executable_test
4+
//
5+
// Enable this everywhere once we have a solution for modularizing libstdc++: rdar://87654514
6+
// REQUIRES: OS=macosx
7+
8+
import StdlibUnittest
9+
import StdVector
10+
import std.vector
11+
12+
var StdIteratorTestSuite = TestSuite("StdIterator")
13+
14+
StdIteratorTestSuite.test("init") {
15+
var vector = Vector()
16+
var _1: CInt = 1
17+
//There seems to be an issue when importing this method, where the const_ref is mapped with
18+
//the correct typealias to be able to pass immutable values. related to: https://github.com/apple/swift/pull/41611
19+
vector.push_back(&_1)
20+
//ideally we should call vector.begin(), however we need to prevent a copy of self before vector.begin() is invoked
21+
//current workaround is to use beginMutating()
22+
let it = vector.beginMutating()
23+
expectEqual(it[0], 1)
24+
}
25+
26+
StdIteratorTestSuite.test("advance") {
27+
var vector = Vector()
28+
var _1: CInt = 1, _2: CInt = 2, _3: CInt = 3
29+
vector.push_back(&_1)
30+
vector.push_back(&_2)
31+
vector.push_back(&_3)
32+
var it = vector.beginMutating()
33+
std.__1.advance(&it, 2)
34+
expectEqual(it[0], 3)
35+
}
36+
37+
runAllTests()

0 commit comments

Comments
 (0)