Skip to content

Commit 0c3f084

Browse files
committed
[test] Array-family mutableSpan properties
1 parent 107b38f commit 0c3f084

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/stdlib/Span/ArraySpanProperties.swift

+47
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 } },
@@ -90,3 +118,22 @@ suite.test("KeyValuePairs.span property")
90118
expectEqual(span[i], pairs[i])
91119
}
92120
}
121+
122+
suite.test("ArraySlice.mutableSpan property")
123+
.require(.stdlib_6_2).code {
124+
guard #available(SwiftStdlib 6.2, *) else { return }
125+
126+
let capacity = 4
127+
let a = Array(0..<capacity)
128+
129+
var s = a[...]
130+
var span = s.mutableSpan
131+
expectEqual(span.count, capacity)
132+
expectEqual(span[0], a[0])
133+
134+
span[0] += 100
135+
expectEqual(span[0], a[0]+100)
136+
137+
_ = consume span
138+
expectEqual(s[0], a[0]+100)
139+
}

0 commit comments

Comments
 (0)