10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- // RUN: %target-run-stdlib-swift -enable-experimental-feature LifetimeDependence
13
+ // RUN: %target-run-stdlib-swift
14
14
15
15
// REQUIRES: executable_test
16
16
// REQUIRES: objc_interop
17
- // REQUIRES: swift_feature_LifetimeDependence
18
17
19
18
import StdlibUnittest
20
19
@@ -25,6 +24,7 @@ defer { runAllTests() }
25
24
26
25
let strings = [
27
26
" Hello, World! " ,
27
+ " 123456789 " ,
28
28
" A long ASCII string exceeding 16 code units. " ,
29
29
" 🇯🇵 " ,
30
30
" 🏂☃❅❆❄︎⛄️❄️ " ,
@@ -37,13 +37,12 @@ strings.forEach { expected in
37
37
. require ( . stdlib_6_2) . code {
38
38
guard #available( SwiftStdlib 6 . 2 , * ) else { return }
39
39
40
- let string = NSString ( utf8String: expected)
41
- guard let string else { expectNotNil ( string) ; return }
40
+ guard let nss = expectNotNil ( NSString ( utf8String: expected) ) else { return }
42
41
43
- let bridged = String ( string ) . utf8
42
+ let bridged = String ( nss ) . utf8
44
43
var p : ObjectIdentifier ? = nil
45
44
for (i, j) in zip ( 0 ..< 3 , bridged. indices) {
46
- let span = bridged. span
45
+ guard let span = expectNotNil ( bridged. _span ) else { continue }
47
46
let c = span. withUnsafeBufferPointer {
48
47
let o = unsafeBitCast ( $0. baseAddress, to: ObjectIdentifier . self)
49
48
if p == nil {
@@ -63,34 +62,65 @@ strings.forEach { expected in
63
62
. require ( . stdlib_6_2) . code {
64
63
guard #available( SwiftStdlib 6 . 2 , * ) else { return }
65
64
66
- let string = NSString ( utf8String: expected)
67
- guard let string else { expectNotNil ( string) ; return }
65
+ guard let nss = expectNotNil ( NSString ( utf8String: expected) ) else { return }
68
66
69
- let bridged = String ( string )
67
+ let bridged = String ( nss )
70
68
let utf8 = bridged. utf8
71
- let span = utf8. span
69
+ guard let span = expectNotNil ( utf8. _span ) else { return }
72
70
expectEqual ( span. count, expected. utf8. count)
73
71
for (i, j) in zip ( span. indices, expected. utf8. indices) {
74
72
expectEqual ( span [ i] , expected. utf8 [ j] )
75
73
}
76
74
}
77
75
}
78
76
77
+ strings. forEach { expected in
78
+ suite. test ( " UTF8Span from Bridged String: \( expected) " )
79
+ . require ( . stdlib_6_2) . code {
80
+ guard #available( SwiftStdlib 6 . 2 , * ) else { return }
81
+
82
+ guard let nss = expectNotNil ( NSString ( utf8String: expected) ) else { return }
83
+
84
+ let bridged = String ( nss)
85
+ guard let utf8 = expectNotNil ( bridged. _utf8Span) else { return }
86
+ expectEqual ( utf8. count, expected. utf8. count)
87
+ for (i, j) in zip ( utf8. span. indices, expected. utf8. indices) {
88
+ expectEqual ( utf8. span [ i] , expected. utf8 [ j] )
89
+ }
90
+ }
91
+ }
92
+
79
93
strings. forEach { expected in
80
94
suite. test ( " Span from Bridged String Substring: \( expected) " )
81
95
. require ( . stdlib_6_2) . code {
82
96
guard #available( SwiftStdlib 6 . 2 , * ) else { return }
83
97
84
- let string = NSString ( utf8String: expected)
85
- guard let string else { expectNotNil ( string) ; return }
98
+ guard let nss = expectNotNil ( NSString ( utf8String: expected) ) else { return }
86
99
87
- let bridged = String ( string ) . dropFirst ( )
100
+ let bridged = String ( nss ) . dropFirst ( )
88
101
let utf8 = bridged. utf8
89
- let span = utf8. span
102
+ guard let span = expectNotNil ( utf8. _span ) else { return }
90
103
let expected = expected. dropFirst ( )
91
104
expectEqual ( span. count, expected. utf8. count)
92
105
for (i, j) in zip ( span. indices, expected. utf8. indices) {
93
106
expectEqual ( span [ i] , expected. utf8 [ j] )
94
107
}
95
108
}
109
+
110
+ strings. forEach { expected in
111
+ suite. test ( " UTF8Span from Bridged String Substring: \( expected) " )
112
+ . require ( . stdlib_6_2) . code {
113
+ guard #available( SwiftStdlib 6 . 2 , * ) else { return }
114
+
115
+ guard let nss = expectNotNil ( NSString ( utf8String: expected) ) else { return }
116
+
117
+ let bridged = String ( nss) . dropFirst ( )
118
+ guard let utf8 = expectNotNil ( bridged. _utf8Span) else { return }
119
+ let expected = expected. dropFirst ( )
120
+ expectEqual ( utf8. count, expected. utf8. count)
121
+ for (i, j) in zip ( utf8. span. indices, expected. utf8. indices) {
122
+ expectEqual ( utf8. span [ i] , expected. utf8 [ j] )
123
+ }
124
+ }
125
+ }
96
126
}
0 commit comments