Skip to content

Commit 5a41eaa

Browse files
committed
Separate the list of xfails from the test list, add test for regional indicator symbol.
Expected failures when testing comparisons and substrings are not the same; separating them allows better coverage.
1 parent 68cc65d commit 5a41eaa

File tree

1 file changed

+77
-46
lines changed

1 file changed

+77
-46
lines changed

test/1_stdlib/StringAPI.swift

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct ComparisonTest {
2424
init(
2525
_ expectedUnicodeCollation: ExpectedComparisonResult,
2626
_ lhs: String, _ rhs: String,
27-
xfail: TestRunPredicate = .custom({false}, reason: ""),
27+
xfail: TestRunPredicate = .never,
2828
file: String = #file, line: UInt = #line
2929
) {
3030
self.expectedUnicodeCollation = expectedUnicodeCollation
@@ -33,25 +33,28 @@ struct ComparisonTest {
3333
self.loc = SourceLoc(file, line, comment: "test data")
3434
self.xfail = xfail
3535
}
36+
37+
func replacingPredicate(_ xfail: TestRunPredicate) -> ComparisonTest {
38+
return ComparisonTest(expectedUnicodeCollation, lhs, rhs,
39+
xfail: xfail, file: loc.file, line: loc.line)
40+
}
3641
}
3742

38-
let comparisonTests = [
43+
// List test cases for comparisons and prefix/suffix. Ideally none fail.
44+
45+
let tests = [
3946
ComparisonTest(.eq, "", ""),
4047
ComparisonTest(.lt, "", "a"),
4148

4249
// ASCII cases
4350
ComparisonTest(.lt, "t", "tt"),
44-
ComparisonTest(.gt, "t", "Tt",
45-
xfail: .nativeRuntime(
46-
"Compares in reverse with ICU, https://bugs.swift.org/browse/SR-530")),
47-
ComparisonTest(.gt, "\u{0}", "",
48-
xfail: .nativeRuntime(
49-
"Null-related issue: https://bugs.swift.org/browse/SR-630")),
51+
ComparisonTest(.gt, "t", "Tt"),
52+
ComparisonTest(.gt, "\u{0}", ""),
5053
ComparisonTest(.eq, "\u{0}", "\u{0}"),
51-
// Currently fails:
52-
// ComparisonTest(.lt, "\r\n", "t"),
53-
// ComparisonTest(.gt, "\r\n", "\n"),
54-
// ComparisonTest(.lt, "\u{0}", "\u{0}\u{0}"),
54+
55+
ComparisonTest(.lt, "\r\n", "t"),
56+
ComparisonTest(.gt, "\r\n", "\n"),
57+
ComparisonTest(.lt, "\u{0}", "\u{0}\u{0}"),
5558

5659
// Whitespace
5760
// U+000A LINE FEED (LF)
@@ -89,9 +92,7 @@ let comparisonTests = [
8992
ComparisonTest(.eq, "\u{212b}", "A\u{30a}"),
9093
ComparisonTest(.eq, "\u{212b}", "\u{c5}"),
9194
ComparisonTest(.eq, "A\u{30a}", "\u{c5}"),
92-
ComparisonTest(.lt, "A\u{30a}", "a",
93-
xfail: .nativeRuntime(
94-
"Compares in reverse with ICU, https://bugs.swift.org/browse/SR-530")),
95+
ComparisonTest(.lt, "A\u{30a}", "a"),
9596
ComparisonTest(.lt, "A", "A\u{30a}"),
9697

9798
// U+2126 OHM SIGN
@@ -114,6 +115,10 @@ let comparisonTests = [
114115
ComparisonTest(.eq, "\u{fb01}", "\u{fb01}"),
115116
ComparisonTest(.lt, "fi", "\u{fb01}"),
116117

118+
// U+1F1E7 REGIONAL INDICATOR SYMBOL LETTER B
119+
// \u{1F1E7}\u{1F1E7} Flag of Barbados
120+
ComparisonTest(.lt, "\u{1F1E7}", "\u{1F1E7}\u{1F1E7}"),
121+
117122
// Test that Unicode collation is performed in deterministic mode.
118123
//
119124
// U+0301 COMBINING ACUTE ACCENT
@@ -128,10 +133,8 @@ let comparisonTests = [
128133
// U+0301 and U+0954 don't decompose in the canonical decomposition mapping.
129134
// U+0341 has a canonical decomposition mapping of U+0301.
130135
ComparisonTest(.eq, "\u{0301}", "\u{0341}"),
131-
ComparisonTest(.lt, "\u{0301}", "\u{0954}",
132-
xfail: .nativeRuntime("Compares as equal with ICU")),
133-
ComparisonTest(.lt, "\u{0341}", "\u{0954}",
134-
xfail: .nativeRuntime("Compares as equal with ICU")),
136+
ComparisonTest(.lt, "\u{0301}", "\u{0954}"),
137+
ComparisonTest(.lt, "\u{0341}", "\u{0954}"),
135138
]
136139

137140
func checkStringComparison(
@@ -169,6 +172,28 @@ func checkStringComparison(
169172
#endif
170173
}
171174

175+
// Mark the test cases that are expected to fail in checkStringComparison
176+
177+
let comparisonTests = tests.map {
178+
(test: ComparisonTest) -> ComparisonTest in
179+
switch (test.expectedUnicodeCollation, test.lhs, test.rhs) {
180+
case (.gt, "t", "Tt"), (.lt, "A\u{30a}", "a"):
181+
return test.replacingPredicate(.nativeRuntime(
182+
"Comparison reversed between ICU and CFString, https://bugs.swift.org/browse/SR-530"))
183+
184+
case (.gt, "\u{0}", ""), (.lt, "\u{0}", "\u{0}\u{0}"):
185+
return test.replacingPredicate(.nativeRuntime(
186+
"Null-related issue: https://bugs.swift.org/browse/SR-630"))
187+
188+
case (.lt, "\u{0301}", "\u{0954}"), (.lt, "\u{0341}", "\u{0954}"):
189+
return test.replacingPredicate(.nativeRuntime(
190+
"Compares as equal with ICU"))
191+
192+
default:
193+
return test
194+
}
195+
}
196+
172197
for test in comparisonTests {
173198
StringTests.test("String.{Equatable,Hashable,Comparable}: line \(test.loc.line)")
174199
.xfail(test.xfail)
@@ -257,11 +282,38 @@ StringTests.test("LosslessStringConvertible") {
257282
checkLosslessStringConvertible(comparisonTests.map { $0.rhs })
258283
}
259284

260-
StringTests.test("hasPrefix,hasSuffix")
261-
.skip(.nativeRuntime(
262-
"String.has{Prefix,Suffix} defined when _runtime(_ObjC)"))
263-
.code {
264-
for test in comparisonTests {
285+
// Mark the test cases that are expected to fail in checkHasPrefixHasSuffix
286+
287+
let substringTests = tests.map {
288+
(test: ComparisonTest) -> ComparisonTest in
289+
switch (test.expectedUnicodeCollation, test.lhs, test.rhs) {
290+
case (.eq, "\u{0}", "\u{0}"):
291+
return test.replacingPredicate(.objCRuntime(
292+
"https://bugs.swift.org/browse/SR-332"))
293+
294+
case (.gt, "\r\n", "\n"):
295+
return test.replacingPredicate(.objCRuntime(
296+
"blocked on rdar://problem/19036555"))
297+
298+
case (.eq, "\u{0301}", "\u{0341}"):
299+
return test.replacingPredicate(.objCRuntime(
300+
"https://bugs.swift.org/browse/SR-243"))
301+
302+
case (.lt, "\u{1F1E7}", "\u{1F1E7}\u{1F1E7}"):
303+
return test.replacingPredicate(.objCRuntime(
304+
"https://bugs.swift.org/browse/SR-367"))
305+
306+
default:
307+
return test
308+
}
309+
}
310+
311+
for test in substringTests {
312+
StringTests.test("hasPrefix,hasSuffix: line \(test.loc.line)")
313+
.skip(.nativeRuntime(
314+
"String.has{Prefix,Suffix} defined when _runtime(_ObjC)"))
315+
.xfail(test.xfail)
316+
.code {
265317
checkHasPrefixHasSuffix(test.lhs, test.rhs, test.loc.withCurrentLoc())
266318
checkHasPrefixHasSuffix(test.rhs, test.lhs, test.loc.withCurrentLoc())
267319

@@ -275,26 +327,6 @@ StringTests.test("hasPrefix,hasSuffix")
275327
}
276328
}
277329

278-
StringTests.test("Failures{hasPrefix,hasSuffix}-CF")
279-
.skip(.nativeRuntime(
280-
"String.has{Prefix,Suffix} defined when _runtime(_ObjC)"))
281-
.code {
282-
let test = ComparisonTest(.lt, "\u{0}", "\u{0}\u{0}")
283-
checkHasPrefixHasSuffix(test.lhs, test.rhs, test.loc.withCurrentLoc())
284-
}
285-
286-
StringTests.test("Failures{hasPrefix,hasSuffix}")
287-
.xfail(.custom({ true }, reason: "blocked on rdar://problem/19036555"))
288-
.skip(.nativeRuntime(
289-
"String.has{Prefix,Suffix} defined when _runtime(_ObjC)"))
290-
.code {
291-
let tests =
292-
[ComparisonTest(.lt, "\r\n", "t"), ComparisonTest(.gt, "\r\n", "\n")]
293-
tests.forEach {
294-
checkHasPrefixHasSuffix($0.lhs, $0.rhs, $0.loc.withCurrentLoc())
295-
}
296-
}
297-
298330
StringTests.test("SameTypeComparisons") {
299331
// U+0323 COMBINING DOT BELOW
300332
// U+0307 COMBINING DOT ABOVE
@@ -312,8 +344,7 @@ StringTests.test("SameTypeComparisons") {
312344

313345
StringTests.test("CompareStringsWithUnpairedSurrogates")
314346
.xfail(
315-
.custom({ true },
316-
reason: "<rdar://problem/18029104> Strings referring to underlying " +
347+
.always("<rdar://problem/18029104> Strings referring to underlying " +
317348
"storage with unpaired surrogates compare unequal"))
318349
.code {
319350
let donor = "abcdef"

0 commit comments

Comments
 (0)