Skip to content

Commit 0800819

Browse files
authored
Merge pull request swiftlang#24112 from lorentey/reenable-small-string-tests
[test] Re-enable SmallString tests with updated platform checks
2 parents d30eb17 + deeff6b commit 0800819

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

test/stdlib/SmallString.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
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
119
//
1210

1311
import StdlibUnittest
12+
#if _runtime(_ObjC)
1413
import Foundation
14+
#endif
1515
var SmallStringTests = TestSuite("SmallStringTests")
1616

1717
extension String: Error {}
@@ -59,6 +59,7 @@ extension _SmallString {
5959
}
6060
self = smol
6161
}
62+
6263
init?(_ codeUnits: Array<UInt16>) {
6364
let str = codeUnits.withUnsafeBufferPointer {
6465
return String._uncheckedFromUTF16($0)
@@ -68,14 +69,18 @@ extension _SmallString {
6869
}
6970
self.init(str._guts._object)
7071
}
72+
73+
#if _runtime(_ObjC)
7174
init?(_cocoaString ns: NSString) {
7275
guard _isObjCTaggedPointer(ns) else { return nil }
7376
self.init(taggedCocoa: ns)
7477
}
78+
#endif
7579

7680
func _appending(_ other: _SmallString) -> _SmallString? {
7781
return _SmallString(self, appending: other)
7882
}
83+
7984
func _repeated(_ n: Int) -> _SmallString? {
8085
var base = self
8186
let toAppend = self
@@ -127,6 +132,7 @@ SmallStringTests.test("FitsInSmall") {
127132

128133
}
129134

135+
#if _runtime(_ObjC)
130136
SmallStringTests.test("Bridging") {
131137
// Test bridging retains small string form
132138
func bridge(_ small: _SmallString) -> String {
@@ -144,10 +150,17 @@ SmallStringTests.test("Bridging") {
144150
}
145151

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

152165
// Fail tests
153166
//
@@ -158,6 +171,7 @@ SmallStringTests.test("Bridging") {
158171
expectThrows("Didn't fit", { try runTestSmall("👨‍👩‍👦") })
159172
expectThrows("Didn't fit", { try runTestSmall("👨‍👦abcde") })
160173
}
174+
#endif
161175

162176
SmallStringTests.test("Append, repeating") {
163177
let strings = [

0 commit comments

Comments
 (0)