Skip to content

Commit 48018fb

Browse files
author
Lance Parker
committed
Update string comparison tests
1 parent 5c5a1e5 commit 48018fb

File tree

8 files changed

+149
-174
lines changed

8 files changed

+149
-174
lines changed

test/SILOptimizer/string_switch.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-build-swift -O %s -module-name=test -Xllvm -sil-disable-pass=FunctionSignatureOpts -o %t.out
22
// RUN: %target-build-swift -O %s -module-name=test -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil | %FileCheck %s
33
// RUN: %target-run %t.out
4+
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
45
// UNSUPPORTED: nonatomic_rc
56

67
import StdlibUnittest

test/stdlib/CodableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ class TestCodable : TestCodableSuper {
694694
}
695695

696696
func test_URLComponents_Plist() {
697-
for (testLine, components) in urlComponentsValues {
697+
for (testLine, components) in urlComponentsValues {
698698
expectRoundTripEqualityThroughPlist(for: components, lineNumber: testLine)
699699
}
700700
}

test/stdlib/RuntimeObjC.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -466,34 +466,6 @@ var nsStringCanaryCount = 0
466466
}
467467
}
468468

469-
RuntimeFoundationWrappers.test(
470-
"_stdlib_compareNSStringDeterministicUnicodeCollation/NoLeak"
471-
) {
472-
nsStringCanaryCount = 0
473-
autoreleasepool {
474-
let a = NSStringCanary()
475-
let b = NSStringCanary()
476-
expectEqual(2, nsStringCanaryCount)
477-
_stdlib_compareNSStringDeterministicUnicodeCollation(a, b)
478-
}
479-
expectEqual(0, nsStringCanaryCount)
480-
}
481-
482-
RuntimeFoundationWrappers.test(
483-
"_stdlib_compareNSStringDeterministicUnicodeCollationPtr/NoLeak"
484-
) {
485-
nsStringCanaryCount = 0
486-
autoreleasepool {
487-
let a = NSStringCanary()
488-
let b = NSStringCanary()
489-
expectEqual(2, nsStringCanaryCount)
490-
let ptrA = unsafeBitCast(a, to: OpaquePointer.self)
491-
let ptrB = unsafeBitCast(b, to: OpaquePointer.self)
492-
_stdlib_compareNSStringDeterministicUnicodeCollationPointer(ptrA, ptrB)
493-
}
494-
expectEqual(0, nsStringCanaryCount)
495-
}
496-
497469
RuntimeFoundationWrappers.test("_stdlib_NSStringHashValue/NoLeak") {
498470
nsStringCanaryCount = 0
499471
autoreleasepool {

test/stdlib/StringAPI.swift

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ let tests = [
9292
ComparisonTest(.eq, "\u{212b}", "A\u{30a}"),
9393
ComparisonTest(.eq, "\u{212b}", "\u{c5}"),
9494
ComparisonTest(.eq, "A\u{30a}", "\u{c5}"),
95-
ComparisonTest(.lt, "A\u{30a}", "a"),
95+
ComparisonTest(.gt, "A\u{30a}", "a"),
9696
ComparisonTest(.lt, "A", "A\u{30a}"),
9797

9898
// U+2126 OHM SIGN
@@ -176,25 +176,7 @@ func checkStringComparison(
176176

177177
// Mark the test cases that are expected to fail in checkStringComparison
178178

179-
let comparisonTests = tests.map {
180-
(test: ComparisonTest) -> ComparisonTest in
181-
switch (test.expectedUnicodeCollation, test.lhs, test.rhs) {
182-
case (.gt, "t", "Tt"), (.lt, "A\u{30a}", "a"):
183-
return test.replacingPredicate(.nativeRuntime(
184-
"Comparison reversed between ICU and CFString, https://bugs.swift.org/browse/SR-530"))
185-
186-
case (.gt, "\u{0}", ""), (.lt, "\u{0}", "\u{0}\u{0}"):
187-
return test.replacingPredicate(.nativeRuntime(
188-
"Null-related issue: https://bugs.swift.org/browse/SR-630"))
189-
190-
case (.lt, "\u{0301}", "\u{0954}"), (.lt, "\u{0341}", "\u{0954}"):
191-
return test.replacingPredicate(.nativeRuntime(
192-
"Compares as equal with ICU"))
193-
194-
default:
195-
return test
196-
}
197-
}
179+
let comparisonTests = tests
198180

199181
for test in comparisonTests {
200182
StringTests.test("String.{Equatable,Hashable,Comparable}: line \(test.loc.line)")

test/stdlib/StringOrderRelation.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import StdlibUnittest
66

77
var StringOrderRelationTestSuite = TestSuite("StringOrderRelation")
88

9-
StringOrderRelationTestSuite.test("StringOrderRelation/ASCII/NullByte")
10-
.xfail(.nativeRuntime("String comparison: ICU vs. Foundation " +
11-
"https://bugs.swift.org/browse/SR-630"))
12-
.code {
9+
StringOrderRelationTestSuite.test("StringOrderRelation/ASCII/NullByte") {
1310
let baseString = "a"
1411
let nullbyteString = "a\0"
1512
expectTrue(baseString < nullbyteString)

validation-test/stdlib/Algorithm.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ Algorithm.test("min,max") {
7474
expectEqual(c1.identity, max(a1, b1, c2, c1).identity)
7575
}
7676

77-
Algorithm.test("sorted/strings")
78-
.xfail(.nativeRuntime("String comparison: ICU vs. Foundation " +
79-
"https://bugs.swift.org/browse/SR-530"))
80-
.code {
77+
Algorithm.test("sorted/strings") {
8178
expectEqual(
8279
["Banana", "apple", "cherry"],
8380
["apple", "Banana", "cherry"].sorted())

validation-test/stdlib/String.swift

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
// RUN: %target-run-simple-swift
1+
// RUN: %empty-directory(%t)
2+
// RUN: if [ %target-runtime == "objc" ]; \
3+
// RUN: then \
4+
// RUN: %target-clang -fobjc-arc %S/Inputs/NSSlowString/NSSlowString.m -c -o %t/NSSlowString.o && \
5+
// RUN: %target-build-swift -I %S/Inputs/NSSlowString/ %t/NSSlowString.o %s -Xfrontend -disable-access-control -o %t/String; \
6+
// RUN: else \
7+
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/String; \
8+
// RUN: fi
9+
10+
// RUN: %target-run %t/String
211
// REQUIRES: executable_test
3-
412
// XFAIL: interpret
513

614
import StdlibUnittest
715
import StdlibCollectionUnittest
816

917
#if _runtime(_ObjC)
18+
import NSSlowString
1019
import Foundation // For NSRange
1120
#endif
1221

@@ -1165,24 +1174,6 @@ StringTests.test("Conversions") {
11651174
}
11661175
}
11671176

1168-
// Check the internal functions are correct for ASCII values
1169-
StringTests.test(
1170-
"forall x: Int8, y: Int8 . x < 128 ==> x <ascii y == x <unicode y")
1171-
.skip(.nativeRuntime("String._compareASCII undefined without _runtime(_ObjC)"))
1172-
.code {
1173-
#if _runtime(_ObjC)
1174-
let asciiValues: [(value: UInt8, string: String)] = (0..<128).map {
1175-
($0, String(UnicodeScalar($0)))
1176-
}
1177-
for (v1, s1) in asciiValues {
1178-
for (v2, s2) in asciiValues {
1179-
expectEqual(s1 < s2, v1 < v2)
1180-
}
1181-
}
1182-
#else
1183-
expectUnreachable()
1184-
#endif
1185-
}
11861177

11871178
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
11881179
import Glibc
@@ -1937,4 +1928,136 @@ for test in testCases {
19371928
}
19381929
}
19391930

1931+
struct ComparisonTestCase {
1932+
var strings: [String]
1933+
// var test: (String, String) -> Void
1934+
var comparison: _Ordering
1935+
1936+
init(_ strings: [String], _ comparison: _Ordering) {
1937+
self.strings = strings
1938+
self.comparison = comparison
1939+
}
1940+
1941+
func test() {
1942+
for pair in zip(strings, strings[1...]) {
1943+
switch comparison {
1944+
case .less:
1945+
expectLT(pair.0, pair.1)
1946+
case .greater:
1947+
expectGT(pair.0, pair.1)
1948+
case .equal:
1949+
expectEqual(pair.0, pair.1)
1950+
}
1951+
}
1952+
}
1953+
1954+
func testOpaquePath() {
1955+
#if _runtime(_ObjC)
1956+
let opaqueStrings = strings.map { NSSlowString(string: $0) as String }
1957+
for pair in zip(opaqueStrings, opaqueStrings[1...]) {
1958+
switch comparison {
1959+
case .less:
1960+
expectLT(pair.0, pair.1)
1961+
case .greater:
1962+
expectGT(pair.0, pair.1)
1963+
case .equal:
1964+
expectEqual(pair.0, pair.1)
1965+
}
1966+
}
1967+
#endif
1968+
}
1969+
}
1970+
1971+
let comparisonTestCases = [
1972+
ComparisonTestCase(["a", "a"], .equal),
1973+
1974+
ComparisonTestCase(["", "Z", "a", "b", "c", "\u{00c5}", "á"], .less),
1975+
1976+
ComparisonTestCase(["abcdefg", "abcdefg"], .equal),
1977+
1978+
ComparisonTestCase(["ábcdefg", "ábcdefgh", "ábcdefghi"], .less),
1979+
ComparisonTestCase(["abcdefg", "abcdefgh", "abcdefghi"], .less),
1980+
1981+
ComparisonTestCase(["á", "\u{0061}\u{0301}"], .equal),
1982+
ComparisonTestCase(["à", "\u{0061}\u{0301}", "â", "\u{e3}", "a\u{0308}"], .less),
1983+
1984+
// Exploding scalars AND exploding segments
1985+
ComparisonTestCase(["\u{fa2}", "\u{fa1}\u{fb7}"], .equal),
1986+
ComparisonTestCase([
1987+
"\u{fa2}\u{fa2}\u{fa2}\u{fa2}",
1988+
"\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}"
1989+
], .equal),
1990+
ComparisonTestCase([
1991+
"\u{fa2}\u{fa2}\u{fa2}\u{fa2}\u{fa2}\u{fa2}\u{fa2}\u{fa2}",
1992+
"\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}"
1993+
], .equal),
1994+
ComparisonTestCase([
1995+
"a\u{fa2}\u{fa2}a\u{fa2}\u{fa2}\u{fa2}\u{fa2}\u{fa2}\u{fa2}",
1996+
"a\u{fa1}\u{fb7}\u{fa1}\u{fb7}a\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}\u{fa1}\u{fb7}"
1997+
], .equal),
1998+
1999+
ComparisonTestCase(["😀", "😀"], .equal),
2000+
ComparisonTestCase(["\u{2f9df}", "\u{8f38}"], .equal),
2001+
ComparisonTestCase([
2002+
"a",
2003+
"\u{2f9df}", // D87E DDDF as written, but normalizes to 8f38
2004+
"\u{2f9df}\u{2f9df}", // D87E DDDF as written, but normalizes to 8f38
2005+
"👨🏻", // D83D DC68 D83C DFFB
2006+
"👨🏻‍⚕️", // D83D DC68 D83C DFFB 200D 2695 FE0F
2007+
"👩‍⚕️", // D83D DC69 200D 2695 FE0F
2008+
"👩🏾", // D83D DC69 D83C DFFE
2009+
"👩🏾‍⚕", // D83D DC69 D83C DFFE 200D 2695 FE0F
2010+
"😀", // D83D DE00
2011+
"😅", // D83D DE05
2012+
"🧀" // D83E DDC0 -- aka a really big scalar
2013+
], .less),
2014+
2015+
2016+
ComparisonTestCase(["f̛̗̘̙̜̹̺̻̼͇͈͉͍͎̽̾̿̀́͂̓̈́͆͊͋͌̚ͅ͏͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦ͘͜͟͢͝͞͠͡", "ơ̗̘̙̜̹̺̻̼͇͈͉͍͎̽̾̿̀́͂̓̈́͆͊͋͌̚ͅ͏͓͔͕͖͙͚͐͑͒͗͛ͥͦͧͨͩͪͫͬͭͮ͘"], .less),
2017+
ComparisonTestCase(["\u{f90b}", "\u{5587}"], .equal),
2018+
2019+
ComparisonTestCase(["a\u{1D160}a", "a\u{1D158}\u{1D1C7}"], .less),
2020+
2021+
ComparisonTestCase(["\u{212b}", "\u{00c5}"], .equal),
2022+
ComparisonTestCase([
2023+
"A",
2024+
"a",
2025+
"aa",
2026+
"ae",
2027+
"ae🧀",
2028+
"az",
2029+
"aze\u{300}",
2030+
"ae\u{301}",
2031+
"ae\u{301}ae\u{301}",
2032+
"ae\u{301}ae\u{301}ae\u{301}",
2033+
"ae\u{301}ae\u{301}ae\u{301}ae\u{301}",
2034+
"ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}",
2035+
"ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}",
2036+
"ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}",
2037+
"ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}ae\u{301}",
2038+
"ae\u{302}",
2039+
"ae\u{302}{303}",
2040+
"ae\u{302}🧀",
2041+
"ae\u{303}",
2042+
"\u{f90b}\u{f90c}\u{f90d}", // Normalizes to BMP scalars
2043+
"🧀", // D83E DDC0 -- aka a really big scalar
2044+
"\u{FFEE}" // half width CJK dot
2045+
], .less),
2046+
2047+
ComparisonTestCase(["ư̴̵̶̷̸̗̘̙̜̹̺̻̼͇͈͉͍͎̽̾̿̀́͂̓̈́͆͊͋͌̚ͅ͏͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮ͘͜͟͢͝͞͠͡", "ì̡̢̧̨̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̹̺̻̼͇͈͉͍͎́̂̃̄̉̊̋̌̍̎̏̐̑̒̓̽̾̿̀́͂̓̈́͆͊͋͌ͅ͏͓͔͕͖͙͐͑͒͗ͬͭͮ͘"], .greater),
2048+
ComparisonTestCase(["ư̴̵̶̷̸̗̘̙̜̹̺̻̼͇͈͉͍͎̽̾̿̀́͂̓̈́͆͊͋͌̚ͅ͏͓͔͕͖͙͚͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮ͘͜͟͢͝͞͠͡", "aì̡̢̧̨̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̹̺̻̼͇͈͉͍͎́̂̃̄̉̊̋̌̍̎̏̐̑̒̓̽̾̿̀́͂̓̈́͆͊͋͌ͅ͏͓͔͕͖͙͐͑͒͗ͬͭͮ͘"], .greater),
2049+
ComparisonTestCase(["ì̡̢̧̨̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̹̺̻̼͇͈͉͍͎́̂̃̄̉̊̋̌̍̎̏̐̑̒̓̽̾̿̀́͂̓̈́͆͊͋͌ͅ͏͓͔͕͖͙͐͑͒͗ͬͭͮ͘", "ì̡̢̧̨̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̹̺̻̼͇͈͉͍͎́̂̃̄̉̊̋̌̍̎̏̐̑̒̓̽̾̿̀́͂̓̈́͆͊͋͌ͅ͏͓͔͕͖͙͐͑͒͗ͬͭͮ͘"], .equal)
2050+
]
2051+
2052+
for test in comparisonTestCases {
2053+
StringTests.test("Comparison.\(test.strings)") {
2054+
test.test()
2055+
}
2056+
StringTests.test("Comparison.OpaqueString.\(test.strings)")
2057+
.skip(.linuxAny(reason: "NSSlowString requires ObjC interop"))
2058+
.code {
2059+
test.testOpaquePath()
2060+
}
2061+
}
2062+
19402063
runAllTests()

validation-test/stdlib/StringHashableComparable.swift.gyb

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)