Skip to content

Commit 42c8238

Browse files
committed
[test] stdlib/StringIndex: Simplify
1 parent e0bd5f7 commit 42c8238

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

test/stdlib/StringIndex.swift

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func dumpIndices(_ string: String) {
2828
let char = string[i]
2929
print(" \(i) -> \(String(reflecting: char))")
3030
}
31-
print("Unicode Scalars:")
31+
print("Scalars:")
3232
string.unicodeScalars.indices.forEach { i in
3333
let scalar = string.unicodeScalars[i]
3434
let value = String(scalar.value, radix: 16, uppercase: true)
@@ -978,19 +978,20 @@ suite.test("Substring.replaceSubrange index validation")
978978
let sm = scalarMap[m]!.index
979979
let sn = scalarMap[n]!.index
980980

981-
// Check Substring.replaceSubrange(_:with:)
982-
do {
983-
let replacement = "x"
981+
let replacement = "x"
984982

985-
var expected = "".unicodeScalars
986-
expected += string.unicodeScalars[si ..< sm]
987-
expected += replacement.unicodeScalars
988-
expected += string.unicodeScalars[sn ..< sj]
983+
var _expected = "".unicodeScalars
984+
_expected += string.unicodeScalars[si ..< sm]
985+
_expected += replacement.unicodeScalars
986+
_expected += string.unicodeScalars[sn ..< sj]
987+
let expected = String(_expected)[...]
989988

989+
// Check Substring.replaceSubrange(_:with:)
990+
do {
990991
var actual = substring
991-
actual.replaceSubrange(m ..< n, with: replacement)
992+
actual.replaceSubrange(m ..< n, with: Array(replacement))
992993

993-
expectEqual(actual, Substring(expected[...]),
994+
expectEqual(actual, expected,
994995
"""
995996
string: \(string.debugDescription)
996997
i: \(i)
@@ -1002,27 +1003,17 @@ suite.test("Substring.replaceSubrange index validation")
10021003

10031004
// Check String.unicodeScalars.replaceSubrange(_:with:)
10041005
do {
1005-
let replacement = "x".unicodeScalars
1006-
1007-
var expected = "".unicodeScalars
1008-
expected += string.unicodeScalars[si ..< sm]
1009-
expected += replacement
1010-
expected += string.unicodeScalars[sn ..< sj]
1011-
10121006
var actual = substring
1013-
actual.unicodeScalars.replaceSubrange(m ..< n, with: replacement)
1007+
actual.unicodeScalars.replaceSubrange(
1008+
m ..< n, with: Array(replacement.unicodeScalars))
10141009

1015-
expectEqual(actual, Substring(expected[...]),
1010+
expectEqual(actual, expected,
10161011
"""
10171012
string: \(string.debugDescription)
10181013
i: \(i)
10191014
j: \(j)
10201015
m: \(m)
10211016
n: \(n)
1022-
substring.startIndex: \(substring.startIndex)
1023-
substring.endIndex: \(substring.endIndex)
1024-
actual.startIndex: \(actual.startIndex)
1025-
actual.endIndex: \(actual.endIndex)
10261017
""")
10271018
}
10281019
}

0 commit comments

Comments
 (0)