Skip to content

Commit bc59aed

Browse files
committed
[test] UTF8Span from inline-stored String instances
1 parent 3a96d08 commit bc59aed

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/stdlib/Span/StringUTF8SpanProperty.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,35 @@ suite.test("Span from Large Native String's Substring")
8585
expectEqual(span[i], u[i])
8686
}
8787
}
88+
89+
suite.test("Span from UTF8Span")
90+
.require(.stdlib_6_2).code {
91+
guard #available(SwiftStdlib 6.2, *) else { return }
92+
93+
let s = String(200)
94+
let utf8span = s.utf8Span
95+
let span1 = utf8span.span
96+
let utf8view = s.utf8
97+
let span2 = utf8view.span
98+
expectEqual(span1.count, span2.count)
99+
for (i,j) in zip(span1.indices, span2.indices) {
100+
expectEqual(span1[i], span2[j])
101+
}
102+
}
103+
104+
suite.test("UTF8Span from Span")
105+
.require(.stdlib_6_2).code {
106+
guard #available(SwiftStdlib 6.2, *) else { return }
107+
108+
let s = String(200).utf8
109+
let span1 = s.span
110+
guard let utf8 = expectNotNil(try? UTF8Span(validating: span1)) else { return }
111+
112+
expectEqual(utf8.count, span1.count)
113+
let span2 = utf8.span
114+
expectTrue(span1.isIdentical(to: span2))
115+
expectEqual(span1.count, span2.count)
116+
for (i,j) in zip(span1.indices, span2.indices) {
117+
expectEqual(span1[i], span2[j])
118+
}
119+
}

0 commit comments

Comments
 (0)