Files
swift-mirror/test/Interop/Cxx/stdlib/use-std-map.swift
Egor Zhdan bc56ddc2bb [cxx-interop] Handle inherited templated operators during auto-conformance
This fixes the automatic `std::unordered_map` conformance to CxxDictionary on Linux. Previously `std::unordered_map::const_iterator` was not auto-conformed to UnsafeCxxInputIterator because its `operator==` is defined on a templated base class of `const_iterator`.

rdar://105220600
2023-07-17 21:10:32 +01:00

43 lines
943 B
Swift

// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
//
// REQUIRES: executable_test
//
// REQUIRES: OS=macosx || OS=linux-gnu
import StdlibUnittest
import StdMap
import CxxStdlib
import Cxx
var StdMapTestSuite = TestSuite("StdMap")
StdMapTestSuite.test("init") {
let m = Map()
expectEqual(m.size(), 0)
expectTrue(m.empty())
}
StdMapTestSuite.test("Map.subscript") {
// This relies on the `std::map` conformance to `CxxDictionary` protocol.
var m = initMap()
let at1 = m[1]
expectNotNil(at1)
expectEqual(at1, 3)
expectEqual(m[2], 2)
expectEqual(m[3], 3)
expectNil(m[-1])
expectNil(m[5])
}
StdMapTestSuite.test("UnorderedMap.subscript") {
// This relies on the `std::unordered_map` conformance to `CxxDictionary` protocol.
var m = initUnorderedMap()
expectEqual(m[1], 3)
expectEqual(m[2], 2)
expectEqual(m[3], 3)
expectNil(m[-1])
expectNil(m[5])
}
runAllTests()