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
11
9
//
12
10
13
11
import StdlibUnittest
12
+ #if _runtime(_ObjC)
14
13
import Foundation
14
+ #endif
15
15
var SmallStringTests = TestSuite ( " SmallStringTests " )
16
16
17
17
extension String : Error { }
@@ -59,6 +59,7 @@ extension _SmallString {
59
59
}
60
60
self = smol
61
61
}
62
+
62
63
init ? ( _ codeUnits: Array < UInt16 > ) {
63
64
let str = codeUnits. withUnsafeBufferPointer {
64
65
return String . _uncheckedFromUTF16 ( $0)
@@ -68,14 +69,18 @@ extension _SmallString {
68
69
}
69
70
self . init ( str. _guts. _object)
70
71
}
72
+
73
+ #if _runtime(_ObjC)
71
74
init ? ( _cocoaString ns: NSString ) {
72
75
guard _isObjCTaggedPointer ( ns) else { return nil }
73
76
self . init ( taggedCocoa: ns)
74
77
}
78
+ #endif
75
79
76
80
func _appending( _ other: _SmallString ) -> _SmallString ? {
77
81
return _SmallString ( self , appending: other)
78
82
}
83
+
79
84
func _repeated( _ n: Int ) -> _SmallString ? {
80
85
var base = self
81
86
let toAppend = self
@@ -127,6 +132,7 @@ SmallStringTests.test("FitsInSmall") {
127
132
128
133
}
129
134
135
+ #if _runtime(_ObjC)
130
136
SmallStringTests . test ( " Bridging " ) {
131
137
// Test bridging retains small string form
132
138
func bridge( _ small: _SmallString ) -> String {
@@ -144,10 +150,17 @@ SmallStringTests.test("Bridging") {
144
150
}
145
151
146
152
// 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
+ }
151
164
152
165
// Fail tests
153
166
//
@@ -158,6 +171,7 @@ SmallStringTests.test("Bridging") {
158
171
expectThrows ( " Didn't fit " , { try runTestSmall ( " 👨👩👦 " ) } )
159
172
expectThrows ( " Didn't fit " , { try runTestSmall ( " 👨👦abcde " ) } )
160
173
}
174
+ #endif
161
175
162
176
SmallStringTests . test ( " Append, repeating " ) {
163
177
let strings = [
0 commit comments