Skip to content

Commit f742a75

Browse files
committed
[test] Array-family mutableSpan properties
1 parent 70a6c65 commit f742a75

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/stdlib/Span/ArraySpanProperties.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ suite.test("Array.span property")
3434
expectEqual(span[0], a[0])
3535
}
3636

37+
suite.test("Array.mutableSpan property")
38+
.require(.stdlib_6_2).code {
39+
guard #available(SwiftStdlib 6.2, *) else { return }
40+
41+
let capacity = 4
42+
var a = Array(0..<capacity)
43+
var span = a.mutableSpan
44+
expectEqual(span.count, capacity)
45+
expectEqual(span[0], 0)
46+
span[0] = 100
47+
_ = consume span
48+
expectEqual(a[0], 100)
49+
}
50+
3751
suite.test("ContiguousArray.span property")
3852
.skip(.custom(
3953
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
@@ -49,6 +63,20 @@ suite.test("ContiguousArray.span property")
4963
expectEqual(span[0], a[0])
5064
}
5165

66+
suite.test("ContiguousArray.mutableSpan property")
67+
.require(.stdlib_6_2).code {
68+
guard #available(SwiftStdlib 6.2, *) else { return }
69+
70+
let capacity = 4
71+
var a = ContiguousArray(0..<capacity)
72+
var span = a.mutableSpan
73+
expectEqual(span.count, capacity)
74+
expectEqual(span[0], 0)
75+
span[0] = 100
76+
_ = consume span
77+
expectEqual(a[0], 100)
78+
}
79+
5280
suite.test("ArraySlice.span property")
5381
.skip(.custom(
5482
{ if #available(SwiftStdlib 6.2, *) { false } else { true } },
@@ -72,3 +100,22 @@ suite.test("ArraySlice.span property")
72100
let i2 = span1.withUnsafeBufferPointer { Int(bitPattern: $0.baseAddress) }
73101
expectEqual(i1, i2)
74102
}
103+
104+
suite.test("ArraySlice.mutableSpan property")
105+
.require(.stdlib_6_2).code {
106+
guard #available(SwiftStdlib 6.2, *) else { return }
107+
108+
let capacity = 4
109+
let a = Array(0..<capacity)
110+
111+
var s = a[...]
112+
var span = s.mutableSpan
113+
expectEqual(span.count, capacity)
114+
expectEqual(span[0], a[0])
115+
116+
span[0] += 100
117+
expectEqual(span[0], a[0]+100)
118+
119+
_ = consume span
120+
expectEqual(s[0], a[0]+100)
121+
}

0 commit comments

Comments
 (0)