@@ -37,15 +37,25 @@ extension String {
37
37
}
38
38
}
39
39
40
+ func check(
41
+ _ string: String ,
42
+ _ pieces: [ [ Unicode . Scalar ] ] ,
43
+ file: String = #file, line: UInt = #line
44
+ ) {
45
+ expectEqual (
46
+ string. forwardPieces, pieces,
47
+ " string: \( String ( reflecting: string) ) (forward) " ,
48
+ file: file, line: line)
49
+ expectEqual (
50
+ string. backwardPieces, pieces,
51
+ " string: \( String ( reflecting: string) ) (backward) " ,
52
+ file: file, line: line)
53
+ }
54
+
40
55
if #available( SwiftStdlib 5 . 6 , * ) {
41
56
StringGraphemeBreaking . test ( " grapheme breaking " ) {
42
57
for test in graphemeBreakTests {
43
- expectEqual (
44
- test. string. forwardPieces, test. pieces,
45
- " string: \( String ( reflecting: test. string) ) (forward) " )
46
- expectEqual (
47
- test. string. backwardPieces, test. pieces,
48
- " string: \( String ( reflecting: test. string) ) (backward) " )
58
+ check ( test. string, test. pieces)
49
59
}
50
60
}
51
61
}
@@ -65,8 +75,8 @@ class NonContiguousNSString: NSString {
65
75
super. init ( )
66
76
}
67
77
68
- init ( _ value: [ UInt16 ] ) {
69
- _value = value
78
+ init ( _ value: some Sequence < UInt16 > ) {
79
+ _value = Array ( value)
70
80
super. init ( )
71
81
}
72
82
@@ -95,16 +105,27 @@ extension _StringGuts {
95
105
if #available( SwiftStdlib 5 . 6 , * ) {
96
106
StringGraphemeBreaking . test ( " grapheme breaking foreign " ) {
97
107
for test in graphemeBreakTests {
98
- let foreign = NonContiguousNSString ( Array ( test. string. utf16) )
108
+ let foreign = NonContiguousNSString ( test. string. utf16)
99
109
let string = foreign as String
100
110
101
111
expectTrue ( string. _guts. _isForeign ( ) )
102
- expectEqual (
103
- string. forwardPieces, test. pieces,
104
- " string: \( String ( reflecting: test. string) ) (forward) " )
105
- expectEqual (
106
- string. backwardPieces, test. pieces,
107
- " string: \( String ( reflecting: test. string) ) (backward) " )
112
+ check ( string, test. pieces)
108
113
}
109
114
}
110
115
}
116
+
117
+ if #available( SwiftStdlib 5 . 8 , * ) {
118
+ StringGraphemeBreaking . test ( " GB11 " ) {
119
+ // MAN, ZERO WIDTH JOINER, ZERO WIDTH JOINER, GIRL
120
+ let string = " \u{1f468} \u{200d} \u{200d} \u{1f467} "
121
+ let pieces : [ [ Unicode . Scalar ] ] = [
122
+ [ " \u{1f468} " , " \u{200d} " , " \u{200d} " ] ,
123
+ [ " \u{1f467} " ]
124
+ ]
125
+ check ( string, pieces)
126
+
127
+ let foreign = NonContiguousNSString ( string. utf16) as String
128
+ expectTrue ( foreign. _guts. _isForeign ( ) )
129
+ check ( foreign, pieces)
130
+ }
131
+ }
0 commit comments