Files
swift-mirror/test/stdlib/DictionaryCompactMapValues.swift
Daiki Matsudate a3552f393e [stdlib] Add compactMapValues(_:) to Dictionary (#15017)
add compact map values on hashed collections
2018-07-14 22:35:16 -07:00

25 lines
568 B
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: objc_interop
import Foundation
import StdlibUnittest
var tests = TestSuite("CompactMapValues")
tests.test("DefaultReturnType") {
var result = ["a": "1", "c": "3"].compactMapValues { $0 }
expectType([String: String].self, &result)
}
tests.test("ExplicitTypeContext") {
expectEqual(["a": "1", "c": "3"],
["a": "1", "b": nil, "c": "3"].compactMapValues({$0})
)
expectEqual(["a": 1, "b": 2],
["a": "1", "b": "2", "c": "three"].compactMapValues(Int.init)
)
}
runAllTests()