Skip to content

Commit 3dfdd87

Browse files
committed
[test] small string compatibility for 32-bit targets
1 parent 77f34f4 commit 3dfdd87

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===--- SmallStringCompatibility.swift -----------------------------------===//
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+
// REQUIRES: CPU=wasm32 || CPU=arm64_32
17+
18+
import StdlibUnittest
19+
20+
var suite = TestSuite("SmallStringCompatibility")
21+
defer { runAllTests() }
22+
23+
var strings = [
24+
("Small", true),
25+
("Less small", true),
26+
("Positively large.", true),
27+
]
28+
29+
#if os(watchOS)
30+
strings[1].1 = false
31+
#endif
32+
33+
strings.forEach { (string, contiguous) in
34+
suite.test("Contiguous: \(string)")
35+
.require(.stdlib_6_2).code {
36+
37+
expectEqual(string.isContiguousUTF8, contiguous)
38+
}
39+
}
40+
41+
strings.forEach { (string, contiguous) in
42+
suite.test("Contiguous Substring: \(string)")
43+
.require(.stdlib_6_2).code {
44+
let substring = string[...]
45+
expectEqual(substring.isContiguousUTF8, contiguous)
46+
}
47+
}
48+
49+
strings.forEach { (string, contiguous) in
50+
suite.test("String.makeContiguousUTF8: \(string)")
51+
.require(.stdlib_6_2).code {
52+
var s = string
53+
s.makeContiguousUTF8()
54+
expectTrue(s.isContiguousUTF8)
55+
expectEqual(s, string)
56+
}
57+
}
58+
59+
strings.forEach { (string, contiguous) in
60+
suite.test("Substring.makeContiguousUTF8: \(string)")
61+
.require(.stdlib_6_2).code {
62+
var s: Substring = string.dropFirst().dropLast()
63+
s.makeContiguousUTF8()
64+
expectTrue(s.isContiguousUTF8)
65+
expectEqual(s, string.dropFirst().dropLast())
66+
}
67+
}

0 commit comments

Comments
 (0)