1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// RUN: %empty-directory(%t)
// RUN: %target-build-swift-dylib(%t/%target-library-name(Swiftskell)) \
// RUN: -module-name Swiftskell \
// RUN: -emit-module \
// RUN: -emit-module-path %t/Swiftskell.swiftmodule \
// RUN: -enable-library-evolution \
// RUN: -parse-as-library \
// RUN: %S/../Inputs/Swiftskell.swift \
// RUN: -enable-experimental-feature SuppressedAssociatedTypes
// RUN: %target-build-swift -I%t -L%t -lSwiftskell -parse-as-library %s \
// RUN: -module-name E -o %t/E %target-rpath(%t)
// RUN: %target-codesign %t/E
// RUN: %target-codesign %t/%target-library-name(Swiftskell)
// RUN: %target-run %t/E %t/%target-library-name(Swiftskell) \
// RUN: | %FileCheck %s --implicit-check-not destroy
// REQUIRES: executable_test
// Temporarily disable for back-deployment (rdar://128544927)
// UNSUPPORTED: back_deployment_runtime
import Swiftskell
/// Basic noncopyable type for testing.
struct File: ~Copyable, Show {
let id: Int
init(_ id: Int) {
self.id = id
}
func show() -> String { return id.show() }
deinit { print("destroying file \(id)") }
}
@main
struct Main {
static func main() {
testListBasic()
}
}
func testListBasic() {
var items = List<File>(length: 5) { .init($0) }
print(items.show()) // CHECK: [0, 1, 2, 3, 4, ]
check(items.length() == 5)
check(!items.isEmpty)
items = List<File>(length: 5) { .init($0) }
// CHECK: destroying file 4
// CHECK: destroying file 3
// CHECK: destroying file 2
// CHECK: destroying file 1
// CHECK: destroying file 0
items = items.reverse()
check(items.length() == 5)
print(items.show()) // CHECK: [4, 3, 2, 1, 0, ]
items = .empty
// CHECK: destroying file 0
// CHECK: destroying file 1
// CHECK: destroying file 2
// CHECK: destroying file 3
// CHECK: destroying file 4
check(items.length() == 0)
check(items.isEmpty)
let nums = List<Int>().push(7).push(7).push(3)
print(nums.show()) // CHECK: [7, 7, 3, ]
}
|