Skip to content

Commit 6214336

Browse files
authored
Merge pull request #67744 from apple/egorzhdan/nested-std-map-test
[cxx-interop] Add test for mutation of nested `std::map`
2 parents 208fce1 + e5784db commit 6214336

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/Interop/Cxx/stdlib/Inputs/std-map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using Map = std::map<int, int>;
99
using MapStrings = std::map<std::string, std::string>;
10+
using NestedMap = std::map<int, Map>;
1011
using UnorderedMap = std::unordered_map<int, int>;
1112

1213
inline Map initMap() { return {{1, 3}, {2, 2}, {3, 3}}; }

test/Interop/Cxx/stdlib/use-std-map.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ StdMapTestSuite.test("MapStrings.subscript") {
5050
expectEqual(m[std.string("abc")], std.string("qwe"))
5151
}
5252

53+
StdMapTestSuite.test("NestedMap.subscript") {
54+
var m = NestedMap()
55+
expectNil(m[0])
56+
expectNil(m[0])
57+
m[1] = Map()
58+
expectNotNil(m[1])
59+
60+
expectNil(m[1]![0])
61+
m[1]![0] = 123
62+
expectEqual(m[1]![0], 123)
63+
64+
m[1]![0] = nil
65+
expectNil(m[1]![0])
66+
67+
m[1] = nil
68+
expectNil(m[1])
69+
}
70+
5371
StdMapTestSuite.test("UnorderedMap.subscript") {
5472
// This relies on the `std::unordered_map` conformance to `CxxDictionary` protocol.
5573
var m = initUnorderedMap()

0 commit comments

Comments
 (0)