mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
25 lines
568 B
Swift
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()
|