Skip to content

Commit a2f8ba6

Browse files
committed
[test] Re-enable SmallString tests with correct platform checks
1 parent b6ca2fb commit a2f8ba6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

test/stdlib/SmallString.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// RUN: %target-run %t.out
33

44
// REQUIRES: executable_test
5-
// REQUIRES: objc_interop
65
// REQUIRES: CPU=arm64 || CPU=x86_64
7-
// REQUIRES: rdar49026133
86

97
//
108
// Tests for small strings
@@ -59,6 +57,7 @@ extension _SmallString {
5957
}
6058
self = smol
6159
}
60+
6261
init?(_ codeUnits: Array<UInt16>) {
6362
let str = codeUnits.withUnsafeBufferPointer {
6463
return String._uncheckedFromUTF16($0)
@@ -68,14 +67,18 @@ extension _SmallString {
6867
}
6968
self.init(str._guts._object)
7069
}
70+
71+
#if _runtime(_ObjC)
7172
init?(_cocoaString ns: NSString) {
7273
guard _isObjCTaggedPointer(ns) else { return nil }
7374
self.init(taggedCocoa: ns)
7475
}
76+
#endif
7577

7678
func _appending(_ other: _SmallString) -> _SmallString? {
7779
return _SmallString(self, appending: other)
7880
}
81+
7982
func _repeated(_ n: Int) -> _SmallString? {
8083
var base = self
8184
let toAppend = self
@@ -127,6 +130,7 @@ SmallStringTests.test("FitsInSmall") {
127130

128131
}
129132

133+
#if _runtime(_ObjC)
130134
SmallStringTests.test("Bridging") {
131135
// Test bridging retains small string form
132136
func bridge(_ small: _SmallString) -> String {
@@ -144,10 +148,17 @@ SmallStringTests.test("Bridging") {
144148
}
145149

146150
// Pass tests
147-
//
148-
expectDoesNotThrow({ try runTestSmall("abc") })
149-
expectDoesNotThrow({ try runTestSmall("defghijk") })
150-
expectDoesNotThrow({ try runTestSmall("aaaaaaaaaaa") })
151+
152+
if #available(macOS 10.10, iOS 9, *) {
153+
expectDoesNotThrow({ try runTestSmall("abc") })
154+
expectDoesNotThrow({ try runTestSmall("defghijk") })
155+
expectDoesNotThrow({ try runTestSmall("aaaaaaaaaaa") })
156+
} else {
157+
// OS X 10.9, iOS 7/8 did not have tagged strings
158+
expectThrows("Didn't fit", { try runTestSmall("abc") })
159+
expectThrows("Didn't fit", { try runTestSmall("defghijk") })
160+
expectThrows("Didn't fit", { try runTestSmall("aaaaaaaaaaa") })
161+
}
151162

152163
// Fail tests
153164
//
@@ -158,6 +169,7 @@ SmallStringTests.test("Bridging") {
158169
expectThrows("Didn't fit", { try runTestSmall("👨‍👩‍👦") })
159170
expectThrows("Didn't fit", { try runTestSmall("👨‍👦abcde") })
160171
}
172+
#endif
161173

162174
SmallStringTests.test("Append, repeating") {
163175
let strings = [

0 commit comments

Comments
 (0)