Skip to content

Commit 3863b81

Browse files
committed
[test] test Span.bytes
1 parent 9cdd83b commit 3863b81

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- SpanBytesProperty.swift --- test Span's bytes property -----------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// RUN: %target-run-stdlib-swift
14+
15+
// REQUIRES: executable_test
16+
17+
import Swift
18+
import StdlibUnittest
19+
20+
var suite = TestSuite("SpanBytesProperty")
21+
defer { runAllTests() }
22+
23+
suite.test("Span/bytes property")
24+
.skip(.custom(
25+
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
26+
reason: "Requires Swift 6.2's standard library"
27+
))
28+
.code {
29+
guard #available(SwiftStdlib 6.2, *) else { return }
30+
31+
let capacity = 4
32+
let a = ContiguousArray(0..<capacity)
33+
a.withUnsafeBufferPointer {
34+
let bytes = $0.span.bytes
35+
36+
expectEqual(bytes.byteCount, capacity*MemoryLayout<Int>.stride)
37+
expectEqual(bytes.unsafeLoad(fromByteOffset: 3, as: UInt8.self), 0)
38+
}
39+
}

0 commit comments

Comments
 (0)