@@ -88,40 +88,20 @@ UTF16APIs.test("trailSurrogate/trap/U+FFFF") {
88
88
_ = UTF16.trailSurrogate(us)
89
89
}
90
90
91
- class EOFCountingIterator<T> : IteratorProtocol {
92
- var array: [T]
93
- var index: Int = 0
94
- var numTimesReturnedEOF: Int = 0
95
-
96
- init(_ array: [T]) {
97
- self.array = array
98
- }
99
-
100
- func next() -> T? {
101
- if index == array.count {
102
- numTimesReturnedEOF += 1
103
- return .none
104
- }
105
- index += 1
106
- return array[index - 1]
107
- }
108
- }
109
-
110
91
func checkDecodeUTF<Codec : UnicodeCodec>(
111
92
_ codec: Codec.Type, _ expectedHead: [UInt32],
112
93
_ expectedRepairedTail: [UInt32], _ utfStr: [Codec.CodeUnit]
113
94
) -> AssertionResult {
114
95
do {
115
96
var decoded = [UInt32]()
116
97
let output: (UInt32) -> Void = { decoded.append($0) }
117
- let iterator = EOFCountingIterator( utfStr)
98
+ let iterator = utfStr.makeIterator( )
118
99
transcode(
119
100
iterator,
120
101
from: codec,
121
102
to: UTF32.self,
122
103
stoppingOnError: true,
123
104
sendingOutputTo: output)
124
- expectGE(1, iterator.numTimesReturnedEOF)
125
105
if expectedHead != decoded {
126
106
return assertionFailure()
127
107
.withDescription("\n")
@@ -136,14 +116,13 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
136
116
137
117
var decoded = [UInt32]()
138
118
let output: (UInt32) -> Void = { decoded.append($0) }
139
- let iterator = EOFCountingIterator( utfStr)
119
+ let iterator = utfStr.makeIterator( )
140
120
transcode(
141
121
iterator,
142
122
from: codec,
143
123
to: UTF32.self,
144
124
stoppingOnError: false,
145
125
sendingOutputTo: output)
146
- expectEqual(1, iterator.numTimesReturnedEOF)
147
126
if expected != decoded {
148
127
return assertionFailure()
149
128
.withDescription("\n")
@@ -182,15 +161,14 @@ func checkEncodeUTF8(_ expected: [UInt8],
182
161
_ scalars: [UInt32]) -> AssertionResult {
183
162
var encoded = [UInt8]()
184
163
let output: (UInt8) -> Void = { encoded.append($0) }
185
- let iterator = EOFCountingIterator( scalars)
164
+ let iterator = scalars.makeIterator( )
186
165
let hadError = transcode(
187
166
iterator,
188
167
from: UTF32.self,
189
168
to: UTF8.self,
190
169
stoppingOnError: true,
191
170
sendingOutputTo: output)
192
171
expectFalse(hadError)
193
- expectGE(1, iterator.numTimesReturnedEOF)
194
172
if expected != encoded {
195
173
return assertionFailure()
196
174
.withDescription("\n")
0 commit comments