mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
“Work” in this case means that they can be enabled without breaking the build — not necessarily that all features are available. Swift 6.2 is highly prone to runtime crashes in `swift_getTypeByMangledName` in generic code that uses ownership features. Swift 6.3 will resolve that.
47 lines
1.1 KiB
Swift
47 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2024 - 2026 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import XCTest
|
|
#if COLLECTIONS_SINGLE_MODULE
|
|
import Collections
|
|
#else
|
|
import _CollectionsTestSupport
|
|
import ContainersPreview
|
|
#endif
|
|
|
|
#if compiler(>=6.2)
|
|
final class BoxTests: XCTestCase {
|
|
func test_basic() {
|
|
var intOnHeap = Box<Int>(0)
|
|
|
|
XCTAssertEqual(intOnHeap[], 0)
|
|
|
|
intOnHeap[] = 123
|
|
|
|
XCTAssertEqual(intOnHeap[], 123)
|
|
|
|
XCTAssertEqual(intOnHeap.copy(), 123)
|
|
|
|
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
|
var inoutToIntOnHeap = intOnHeap.leak()
|
|
|
|
XCTAssertEqual(inoutToIntOnHeap.value, 123)
|
|
|
|
inoutToIntOnHeap.value = 321
|
|
|
|
XCTAssertEqual(inoutToIntOnHeap.value, 321)
|
|
#endif
|
|
}
|
|
}
|
|
#endif
|