Skip to content

Commit f757334

Browse files
author
Lance Parker
committed
Add failing test for opaque substrings
1 parent b54ce15 commit f757334

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

validation-test/stdlib/String.swift

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,9 @@ struct ComparisonTestCase {
19511951
}
19521952
}
19531953

1954-
func testOpaquePath() {
1954+
func testOpaqueStrings() {
19551955
#if _runtime(_ObjC)
1956-
let opaqueStrings = strings.map { NSSlowString(string: $0) as String }
1956+
let opaqueStrings = strings.map { NSSlowString(string: $0) as String }
19571957
for pair in zip(opaqueStrings, opaqueStrings[1...]) {
19581958
switch comparison {
19591959
case .less:
@@ -1964,20 +1964,37 @@ struct ComparisonTestCase {
19641964
expectEqual(pair.0, pair.1)
19651965
}
19661966
}
1967+
#endif
1968+
}
1969+
1970+
func testOpaqueSubstrings() {
1971+
#if _runtime(_ObjC)
1972+
for pair in zip(strings, strings[1...]) {
1973+
let string1 = pair.0.dropLast()
1974+
let string2 = pair.1
1975+
let opaqueString = (NSSlowString(string: pair.0) as String).dropLast()
1976+
1977+
guard string1.count > 0 else { return }
1978+
1979+
let expectedResult: _Ordering = string1 < string2 ? .less : (string1 > string2 ? .greater : .equal)
1980+
let opaqueResult: _Ordering = opaqueString < string2 ? .less : (opaqueString > string2 ? .greater : .equal)
1981+
1982+
expectEqual(opaqueResult, expectedResult)
1983+
}
19671984
#endif
19681985
}
19691986
}
19701987

1971-
let comparisonTestCases = [
1988+
let simpleComparisonTestCases = [
19721989
ComparisonTestCase(["a", "a"], .equal),
1973-
1974-
ComparisonTestCase(["", "Z", "a", "b", "c", "\u{00c5}", "á"], .less),
1975-
19761990
ComparisonTestCase(["abcdefg", "abcdefg"], .equal),
1991+
ComparisonTestCase(["", "Z", "a", "b", "c", "\u{00c5}", "á"], .less),
19771992

19781993
ComparisonTestCase(["ábcdefg", "ábcdefgh", "ábcdefghi"], .less),
19791994
ComparisonTestCase(["abcdefg", "abcdefgh", "abcdefghi"], .less),
1995+
]
19801996

1997+
let complexComparisonTestCases = [
19811998
ComparisonTestCase(["á", "\u{0061}\u{0301}"], .equal),
19821999
ComparisonTestCase(["à", "\u{0061}\u{0301}", "â", "\u{e3}", "a\u{0308}"], .less),
19832000

@@ -2049,14 +2066,25 @@ let comparisonTestCases = [
20492066
ComparisonTestCase(["ì̡̢̧̨̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̹̺̻̼͇͈͉͍͎́̂̃̄̉̊̋̌̍̎̏̐̑̒̓̽̾̿̀́͂̓̈́͆͊͋͌ͅ͏͓͔͕͖͙͐͑͒͗ͬͭͮ͘", "ì̡̢̧̨̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̹̺̻̼͇͈͉͍͎́̂̃̄̉̊̋̌̍̎̏̐̑̒̓̽̾̿̀́͂̓̈́͆͊͋͌ͅ͏͓͔͕͖͙͐͑͒͗ͬͭͮ͘"], .equal)
20502067
]
20512068

2069+
let comparisonTestCases = simpleComparisonTestCases + complexComparisonTestCases
2070+
20522071
for test in comparisonTestCases {
20532072
StringTests.test("Comparison.\(test.strings)") {
20542073
test.test()
20552074
}
2075+
20562076
StringTests.test("Comparison.OpaqueString.\(test.strings)")
20572077
.skip(.linuxAny(reason: "NSSlowString requires ObjC interop"))
20582078
.code {
2059-
test.testOpaquePath()
2079+
test.testOpaqueStrings()
2080+
}
2081+
}
2082+
2083+
for test in simpleComparisonTestCases {
2084+
StringTests.test("Comparison.OpaqueSubstring.\(test.strings)")
2085+
.skip(.linuxAny(reason: "NSSlowString requires ObjC interop"))
2086+
.code {
2087+
test.testOpaqueSubstrings()
20602088
}
20612089
}
20622090

0 commit comments

Comments
 (0)