Skip to content

[interop] add a testcase for std::set iteration in Swift #62627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/Interop/Cxx/stdlib/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ module StdMap {
header "std-map.h"
requires cplusplus
}

module StdSet {
header "std-set.h"
requires cplusplus
}
10 changes: 10 additions & 0 deletions test/Interop/Cxx/stdlib/Inputs/std-set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H

#include <set>

using SetOfCInt = std::set<int>;

inline SetOfCInt initSetOfCInt() { return {1, 5, 3}; }

#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_SET_H
29 changes: 29 additions & 0 deletions test/Interop/Cxx/stdlib/use-std-set.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xfrontend -validate-tbd-against-ir=none)
//
// REQUIRES: executable_test
//
// Enable this everywhere once we have a solution for modularizing other C++ stdlibs: rdar://87654514
// REQUIRES: OS=macosx || OS=linux-gnu

import StdlibUnittest
import StdSet
import CxxStdlib
import Cxx

var StdSetTestSuite = TestSuite("StdSet")

extension SetOfCInt.const_iterator : UnsafeCxxInputIterator { }
extension SetOfCInt : CxxSequence { }

StdSetTestSuite.test("iterate") {
let s = initSetOfCInt()
var result = [CInt]()
for x in s {
result.append(x)
}
expectEqual(result[0], 1)
expectEqual(result[1], 3)
expectEqual(result[2], 5)
}

runAllTests()