Skip to content

Commit b65faee

Browse files
committed
Add unit tests for swift 4 mode
1 parent ae9f5e3 commit b65faee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/stdlib/TestData_Swift4.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
3+
// Licensed under Apache License v2.0 with Runtime Library Exception
4+
//
5+
// See https://swift.org/LICENSE.txt for license information
6+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// RUN: %empty-directory(%t)
11+
// RUN: %target-build-swift -swift-version 4 %s -o %t/TestData_Swift4
12+
// RUN: %target-run %t/TestData_Swift4
13+
// REQUIRES: executable_test
14+
// REQUIRES: objc_interop
15+
16+
import Foundation
17+
import StdlibUnittest
18+
19+
var DataTests = TestSuite("TestDataSwift4")
20+
21+
DataTests.test("functional map init usage") {
22+
let res1 = [[UInt8(0), UInt8(1), UInt8(2)]].map(Data.init) // previously this could be done without being ambiguous (however in swift 4.2 an overload was added that makes it ambiguous as a function ref)
23+
// the following two strategies are preferred to the previous version
24+
let res2 = [[UInt8(0), UInt8(1), UInt8(2)]].map(Data.init(_:))
25+
let res3 = [[UInt8(0), UInt8(1), UInt8(2)]].map { Data($0) }
26+
27+
expectEqual(res1.count, 1)
28+
expectEqual(res2.count, 1)
29+
expectEqual(res3.count, 1)
30+
31+
expectEqual(res1[0], res2[0])
32+
expectEqual(res2[0], res3[0])
33+
}
34+
35+
runAllTests()

0 commit comments

Comments
 (0)