|
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 |
2 | 11 | // REQUIRES: executable_test
|
3 |
| - |
4 | 12 | // XFAIL: interpret
|
5 | 13 |
|
6 | 14 | import StdlibUnittest
|
7 | 15 | import StdlibCollectionUnittest
|
8 | 16 |
|
9 | 17 | #if _runtime(_ObjC)
|
| 18 | +import NSSlowString |
10 | 19 | import Foundation // For NSRange
|
11 | 20 | #endif
|
12 | 21 |
|
@@ -1165,24 +1174,6 @@ StringTests.test("Conversions") {
|
1165 | 1174 | }
|
1166 | 1175 | }
|
1167 | 1176 |
|
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 |
| -} |
1186 | 1177 |
|
1187 | 1178 | #if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
|
1188 | 1179 | import Glibc
|
@@ -1937,4 +1928,136 @@ for test in testCases {
|
1937 | 1928 | }
|
1938 | 1929 | }
|
1939 | 1930 |
|
| 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 | + |
1940 | 2063 | runAllTests()
|
0 commit comments