2
2
// RUN: %target-run %t.out
3
3
4
4
// REQUIRES: executable_test
5
- // REQUIRES: objc_interop
6
5
// REQUIRES: CPU=arm64 || CPU=x86_64
7
- // REQUIRES: rdar49026133
8
6
9
7
//
10
8
// Tests for small strings
@@ -59,6 +57,7 @@ extension _SmallString {
59
57
}
60
58
self = smol
61
59
}
60
+
62
61
init ? ( _ codeUnits: Array < UInt16 > ) {
63
62
let str = codeUnits. withUnsafeBufferPointer {
64
63
return String . _uncheckedFromUTF16 ( $0)
@@ -68,14 +67,18 @@ extension _SmallString {
68
67
}
69
68
self . init ( str. _guts. _object)
70
69
}
70
+
71
+ #if _runtime(_ObjC)
71
72
init ? ( _cocoaString ns: NSString ) {
72
73
guard _isObjCTaggedPointer ( ns) else { return nil }
73
74
self . init ( taggedCocoa: ns)
74
75
}
76
+ #endif
75
77
76
78
func _appending( _ other: _SmallString ) -> _SmallString ? {
77
79
return _SmallString ( self , appending: other)
78
80
}
81
+
79
82
func _repeated( _ n: Int ) -> _SmallString ? {
80
83
var base = self
81
84
let toAppend = self
@@ -127,6 +130,7 @@ SmallStringTests.test("FitsInSmall") {
127
130
128
131
}
129
132
133
+ #if _runtime(_ObjC)
130
134
SmallStringTests . test ( " Bridging " ) {
131
135
// Test bridging retains small string form
132
136
func bridge( _ small: _SmallString ) -> String {
@@ -144,10 +148,17 @@ SmallStringTests.test("Bridging") {
144
148
}
145
149
146
150
// 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
+ }
151
162
152
163
// Fail tests
153
164
//
@@ -158,6 +169,7 @@ SmallStringTests.test("Bridging") {
158
169
expectThrows ( " Didn't fit " , { try runTestSmall ( " 👨👩👦 " ) } )
159
170
expectThrows ( " Didn't fit " , { try runTestSmall ( " 👨👦abcde " ) } )
160
171
}
172
+ #endif
161
173
162
174
SmallStringTests . test ( " Append, repeating " ) {
163
175
let strings = [
0 commit comments