Skip to content

Commit 9dce40c

Browse files
committed
[stdlib] Add tests for index hashability
1 parent 6c66cf3 commit 9dce40c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

validation-test/stdlib/Dictionary.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ DictionaryTestSuite.test("sizeof") {
7777
#endif
7878
}
7979

80+
DictionaryTestSuite.test("Index.Hashable") {
81+
let d = [1: "meow", 2: "meow", 3: "meow"]
82+
let e = Dictionary(uniqueKeysWithValues: zip(d.indices, d))
83+
expectEqual(d.count, e.count)
84+
expectNotNil(e[d.startIndex])
85+
}
86+
8087
DictionaryTestSuite.test("valueDestruction") {
8188
var d1 = Dictionary<Int, TestValueTy>()
8289
for i in 100...110 {

validation-test/stdlib/Set.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ SetTestSuite.test("sizeof") {
331331
#endif
332332
}
333333

334+
SetTestSuite.test("Index.Hashable") {
335+
let s: Set = [1, 2, 3, 4, 5]
336+
let t = Set(s.indices)
337+
expectEqual(s.count, t.count)
338+
expectTrue(t.contains(s.startIndex))
339+
}
340+
334341
SetTestSuite.test("COW.Smoke") {
335342
var s1 = Set<TestKeyTy>(minimumCapacity: 10)
336343
for i in [1010, 2020, 3030]{ s1.insert(TestKeyTy(i)) }

validation-test/stdlib/String.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ StringTests.test("unicodeScalars") {
148148
checkUnicodeScalarViewIteration([ 0x10ffff ], "\u{0010ffff}")
149149
}
150150

151-
StringTests.test("indexComparability") {
151+
StringTests.test("Index/Comparable") {
152152
let empty = ""
153153
expectTrue(empty.startIndex == empty.endIndex)
154154
expectFalse(empty.startIndex != empty.endIndex)
@@ -166,6 +166,13 @@ StringTests.test("indexComparability") {
166166
expectTrue(nonEmpty.startIndex < nonEmpty.endIndex)
167167
}
168168

169+
StringTests.test("Index/Hashable") {
170+
let s = "abcdef"
171+
let t = Set(s.indices)
172+
expectEqual(s.count, t.count)
173+
expectTrue(t.contains(s.startIndex))
174+
}
175+
169176
StringTests.test("ForeignIndexes/Valid") {
170177
// It is actually unclear what the correct behavior is. This test is just a
171178
// change detector.

0 commit comments

Comments
 (0)