@@ -102,22 +102,22 @@ final class EncodingTests: XCTestCase {
102102 XCTAssertEqual ( lhs. attribute, rhs. attribute)
103103 }
104104
105- func AssertDistanceWorks < T> ( _ encoding : T . Type , _ distances : ( Offset < T > , Offset < T > , Offset < T > ) ) {
106- XCTAssertEqual ( T . distance ( from: start, to: start, in: emojis) , distances . 0 )
107- XCTAssertEqual ( T . distance ( from: middle, to: middle, in: emojis) , distances . 0 )
108- XCTAssertEqual ( T . distance ( from: end, to: end, in: emojis) , distances . 0 )
105+ func AssertDistancePerEmoji < T> ( _ type : T . Type , _ stride : Offset < T > ) {
106+ XCTAssertEqual ( T . distance ( from: start, to: start, in: emojis) , stride * 0 )
107+ XCTAssertEqual ( T . distance ( from: middle, to: middle, in: emojis) , stride * 0 )
108+ XCTAssertEqual ( T . distance ( from: end, to: end, in: emojis) , stride * 0 )
109109
110- XCTAssertEqual ( T . distance ( from: start, to: middle, in: emojis) , + distances . 1 )
111- XCTAssertEqual ( T . distance ( from: middle, to: start, in: emojis) , - distances . 1 )
110+ XCTAssertEqual ( T . distance ( from: start, to: middle, in: emojis) , stride * 1 )
111+ XCTAssertEqual ( T . distance ( from: middle, to: start, in: emojis) , - stride * 1 )
112112
113- XCTAssertEqual ( T . distance ( from: middle, to: end, in: emojis) , + distances . 1 )
114- XCTAssertEqual ( T . distance ( from: end, to: middle, in: emojis) , - distances . 1 )
113+ XCTAssertEqual ( T . distance ( from: middle, to: end, in: emojis) , stride * 1 )
114+ XCTAssertEqual ( T . distance ( from: end, to: middle, in: emojis) , - stride * 1 )
115115
116- XCTAssertEqual ( T . distance ( from: start, to: end, in: emojis) , + distances . 2 )
117- XCTAssertEqual ( T . distance ( from: end, to: start, in: emojis) , - distances . 2 )
116+ XCTAssertEqual ( T . distance ( from: start, to: end, in: emojis) , stride * 2 )
117+ XCTAssertEqual ( T . distance ( from: end, to: start, in: emojis) , - stride * 2 )
118118 }
119119
120- func AssertIndexWorks ( _ type: ( some Encoding ) . Type) {
120+ func AssertIndexAwayFromIndexWorks ( _ type: ( some Encoding ) . Type) {
121121 let max = type. distance ( from: start, to: end, in: emojis)
122122 let mid = type. distance ( from: start, to: middle, in: emojis)
123123 let i = { type. index ( from: $0, move: $1, in: self . emojis) }
@@ -143,8 +143,8 @@ final class EncodingTests: XCTestCase {
143143 }
144144
145145 func AssertIndexClampsToStartOfCharacter( _ type: ( some Encoding ) . Type) {
146- let i = { type. index ( from: $0, move: $1, in: self . emojis) }
147- let d = { type. distance ( from: $0, to: $1, in: self . emojis) }
146+ let i = { type . index ( from: $0, move: $1, in: self . emojis) }
147+ let d = { type. distance ( from: $0, to: $1, in: self . emojis) }
148148 //=--------------------------------------=
149149 // Forwards
150150 //=--------------------------------------=
@@ -176,11 +176,11 @@ final class EncodingTests: XCTestCase {
176176 //=------------------------------------------------------------------------=
177177
178178 func testCharacterDistance( ) {
179- AssertDistanceWorks ( Character . self, ( 0 , 1 , 2 ) )
179+ AssertDistancePerEmoji ( Character . self, 1 )
180180 }
181181
182182 func testCharacterIndex( ) {
183- AssertIndexWorks ( Character . self)
183+ AssertIndexAwayFromIndexWorks ( Character . self)
184184 }
185185
186186 func testCharacterIndexClampsToStartOfCharacter( ) {
@@ -192,11 +192,11 @@ final class EncodingTests: XCTestCase {
192192 //=------------------------------------------------------------------------=
193193
194194 func testUnicodeScalarDistance( ) {
195- AssertDistanceWorks ( Unicode . Scalar. self, ( 0 , 2 , 4 ) )
195+ AssertDistancePerEmoji ( Unicode . Scalar. self, 2 )
196196 }
197197
198198 func testUnicodeScalarIndex( ) {
199- AssertIndexWorks ( Unicode . Scalar. self)
199+ AssertIndexAwayFromIndexWorks ( Unicode . Scalar. self)
200200 }
201201
202202 func testUnicodeScalarIndexClampsToStartOfCharacter( ) {
@@ -208,11 +208,11 @@ final class EncodingTests: XCTestCase {
208208 //=------------------------------------------------------------------------=
209209
210210 func testUTF16Distance( ) {
211- AssertDistanceWorks ( UTF16 . self, ( 0 , 4 , 8 ) )
211+ AssertDistancePerEmoji ( UTF16 . self, 4 )
212212 }
213213
214214 func testUTF16Index( ) {
215- AssertIndexWorks ( UTF16 . self)
215+ AssertIndexAwayFromIndexWorks ( UTF16 . self)
216216 }
217217
218218 func testUTF16IndexClampsToStartOfCharacter( ) {
@@ -224,11 +224,11 @@ final class EncodingTests: XCTestCase {
224224 //=------------------------------------------------------------------------=
225225
226226 func testUTF8Distance( ) {
227- AssertDistanceWorks ( UTF8 . self, ( 0 , 8 , 16 ) )
227+ AssertDistancePerEmoji ( UTF8 . self, 8 )
228228 }
229229
230230 func testUTF8Index( ) {
231- AssertIndexWorks ( UTF8 . self)
231+ AssertIndexAwayFromIndexWorks ( UTF8 . self)
232232 }
233233
234234 func testUTF8IndexClampsToStartOfCharacter( ) {
0 commit comments