Skip to content

Commit 2cce7db

Browse files
[stdlib] Remove iterator post-nil checks from UTF validation tests
1 parent 34b82bf commit 2cce7db

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

validation-test/stdlib/Unicode.swift.gyb

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,40 +88,20 @@ UTF16APIs.test("trailSurrogate/trap/U+FFFF") {
8888
_ = UTF16.trailSurrogate(us)
8989
}
9090

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-
11091
func checkDecodeUTF<Codec : UnicodeCodec>(
11192
_ codec: Codec.Type, _ expectedHead: [UInt32],
11293
_ expectedRepairedTail: [UInt32], _ utfStr: [Codec.CodeUnit]
11394
) -> AssertionResult {
11495
do {
11596
var decoded = [UInt32]()
11697
let output: (UInt32) -> Void = { decoded.append($0) }
117-
let iterator = EOFCountingIterator(utfStr)
98+
let iterator = utfStr.makeIterator()
11899
transcode(
119100
iterator,
120101
from: codec,
121102
to: UTF32.self,
122103
stoppingOnError: true,
123104
sendingOutputTo: output)
124-
expectGE(1, iterator.numTimesReturnedEOF)
125105
if expectedHead != decoded {
126106
return assertionFailure()
127107
.withDescription("\n")
@@ -136,14 +116,13 @@ func checkDecodeUTF<Codec : UnicodeCodec>(
136116

137117
var decoded = [UInt32]()
138118
let output: (UInt32) -> Void = { decoded.append($0) }
139-
let iterator = EOFCountingIterator(utfStr)
119+
let iterator = utfStr.makeIterator()
140120
transcode(
141121
iterator,
142122
from: codec,
143123
to: UTF32.self,
144124
stoppingOnError: false,
145125
sendingOutputTo: output)
146-
expectEqual(1, iterator.numTimesReturnedEOF)
147126
if expected != decoded {
148127
return assertionFailure()
149128
.withDescription("\n")
@@ -182,15 +161,14 @@ func checkEncodeUTF8(_ expected: [UInt8],
182161
_ scalars: [UInt32]) -> AssertionResult {
183162
var encoded = [UInt8]()
184163
let output: (UInt8) -> Void = { encoded.append($0) }
185-
let iterator = EOFCountingIterator(scalars)
164+
let iterator = scalars.makeIterator()
186165
let hadError = transcode(
187166
iterator,
188167
from: UTF32.self,
189168
to: UTF8.self,
190169
stoppingOnError: true,
191170
sendingOutputTo: output)
192171
expectFalse(hadError)
193-
expectGE(1, iterator.numTimesReturnedEOF)
194172
if expected != encoded {
195173
return assertionFailure()
196174
.withDescription("\n")

0 commit comments

Comments
 (0)