Skip to content

[4.2] [test] Drop stdlib-redundant tests #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 0 additions & 220 deletions TestFoundation/TestNSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class TestNSString : XCTestCase {
("test_ExternalRepresentation", test_ExternalRepresentation),
("test_mutableStringConstructor", test_mutableStringConstructor),
("test_emptyStringPrefixAndSuffix",test_emptyStringPrefixAndSuffix),
("test_PrefixSuffix", test_PrefixSuffix),
("test_reflection", { _ in test_reflection }),
("test_replacingOccurrences", test_replacingOccurrences),
("test_getLineStart", test_getLineStart),
Expand Down Expand Up @@ -1210,225 +1209,6 @@ class TestNSString : XCTestCase {
}
}

struct ComparisonTest {
enum TestBehavior {
case run
case expectedFailure(String)
case skip(String)
}
let lhs: String
let rhs: String
let loc: UInt
let behavior: TestBehavior

var expectedFailure: Bool {
if case .expectedFailure = behavior {
return true
} else {
return false
}
}

init(
_ lhs: String, _ rhs: String,
expectedFailure xfailReason: String = "",
skip skipReason: String = "",
line: UInt = #line
) {
self.lhs = lhs
self.rhs = rhs
self.loc = line

switch (xfailReason.isEmpty, skipReason.isEmpty) {
case (false, true):
behavior = .expectedFailure(xfailReason)
case (_, false):
behavior = .skip(skipReason)
default:
behavior = .run
}
}
}

let comparisonTests: [ComparisonTest] = [
ComparisonTest("", ""),
ComparisonTest("", "a"),

// ASCII cases
ComparisonTest("t", "tt"),
ComparisonTest("t", "Tt"),
ComparisonTest("\u{0}", "",
skip: "rdar://problem/37686816"),
ComparisonTest("\u{0}", "\u{0}",
expectedFailure: "https://bugs.swift.org/browse/SR-332"),
ComparisonTest("\r\n", "t"),
ComparisonTest("\r\n", "\n",
expectedFailure: "blocked on rdar://problem/19036555"),
ComparisonTest("\u{0}", "\u{0}\u{0}",
expectedFailure: "rdar://problem/19034601"),

// Whitespace
// U+000A LINE FEED (LF)
// U+000B LINE TABULATION
// U+000C FORM FEED (FF)
// U+0085 NEXT LINE (NEL)
// U+2028 LINE SEPARATOR
// U+2029 PARAGRAPH SEPARATOR
ComparisonTest("\u{0085}", "\n"),
ComparisonTest("\u{000b}", "\n"),
ComparisonTest("\u{000c}", "\n"),
ComparisonTest("\u{2028}", "\n"),
ComparisonTest("\u{2029}", "\n"),
ComparisonTest("\r\n\r\n", "\r\n"),

// U+0301 COMBINING ACUTE ACCENT
// U+00E1 LATIN SMALL LETTER A WITH ACUTE
ComparisonTest("a\u{301}", "\u{e1}"),
ComparisonTest("a", "a\u{301}"),
ComparisonTest("a", "\u{e1}"),

// U+304B HIRAGANA LETTER KA
// U+304C HIRAGANA LETTER GA
// U+3099 COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
ComparisonTest("\u{304b}", "\u{304b}"),
ComparisonTest("\u{304c}", "\u{304c}"),
ComparisonTest("\u{304b}", "\u{304c}"),
ComparisonTest("\u{304b}", "\u{304c}\u{3099}"),
ComparisonTest("\u{304c}", "\u{304b}\u{3099}"),
ComparisonTest("\u{304c}", "\u{304c}\u{3099}"),

// U+212B ANGSTROM SIGN
// U+030A COMBINING RING ABOVE
// U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE
ComparisonTest("\u{212b}", "A\u{30a}"),
ComparisonTest("\u{212b}", "\u{c5}"),
ComparisonTest("A\u{30a}", "\u{c5}"),
ComparisonTest("A\u{30a}", "a"),
ComparisonTest("A", "A\u{30a}"),

// U+2126 OHM SIGN
// U+03A9 GREEK CAPITAL LETTER OMEGA
ComparisonTest("\u{2126}", "\u{03a9}"),

// U+0323 COMBINING DOT BELOW
// U+0307 COMBINING DOT ABOVE
// U+1E63 LATIN SMALL LETTER S WITH DOT BELOW
// U+1E69 LATIN SMALL LETTER S WITH DOT BELOW AND DOT ABOVE
ComparisonTest("\u{1e69}", "s\u{323}\u{307}"),
ComparisonTest("\u{1e69}", "s\u{307}\u{323}"),
ComparisonTest("\u{1e69}", "\u{1e63}\u{307}"),
ComparisonTest("\u{1e63}", "s\u{323}"),
ComparisonTest("\u{1e63}\u{307}", "s\u{323}\u{307}"),
ComparisonTest("\u{1e63}\u{307}", "s\u{307}\u{323}"),
ComparisonTest("s\u{323}", "\u{1e69}"),

// U+FB01 LATIN SMALL LIGATURE FI
ComparisonTest("\u{fb01}", "\u{fb01}"),
ComparisonTest("fi", "\u{fb01}"),

// U+1F1E7 REGIONAL INDICATOR SYMBOL LETTER B
// \u{1F1E7}\u{1F1E7} Flag of Barbados
ComparisonTest("\u{1F1E7}", "\u{1F1E7}\u{1F1E7}"),

// Test that Unicode collation is performed in deterministic mode.
//
// U+0301 COMBINING ACUTE ACCENT
// U+0341 COMBINING ACUTE TONE MARK
// U+0954 DEVANAGARI ACUTE ACCENT
//
// Collation elements from DUCET:
// 0301 ; [.0000.0024.0002] # COMBINING ACUTE ACCENT
// 0341 ; [.0000.0024.0002] # COMBINING ACUTE TONE MARK
// 0954 ; [.0000.0024.0002] # DEVANAGARI ACUTE ACCENT
//
// U+0301 and U+0954 don't decompose in the canonical decomposition mapping.
// U+0341 has a canonical decomposition mapping of U+0301.
ComparisonTest("\u{0301}", "\u{0341}"),
ComparisonTest("\u{0301}", "\u{0954}"),
ComparisonTest("\u{0341}", "\u{0954}"),
]

enum Stack: Swift.Error {
case Stack([UInt])
}

func checkHasPrefixHasSuffix(_ lhs: String, _ rhs: String, _ stack: [UInt]) -> Int {
if (lhs == "" && rhs == "") {
var failures = 0
failures += lhs.hasPrefix(rhs) ? 0: 1
failures += lhs.hasSuffix(rhs) ? 0: 1
return failures
} else if lhs == "" {
var failures = 0
failures += lhs.hasPrefix(rhs) ? 1 : 0
failures += lhs.hasSuffix(rhs) ? 1 : 0
return failures
} else if rhs == "" {
var failures = 0
failures += lhs.hasPrefix(rhs) ? 0 : 1
failures += lhs.hasSuffix(rhs) ? 0 : 1
return failures
}

// To determine the expected results, compare grapheme clusters,
// scalar-to-scalar, of the NFD form of the strings.
let lhsNFDGraphemeClusters =
lhs.decomposedStringWithCanonicalMapping.map {
Array(String($0).unicodeScalars)
}
let rhsNFDGraphemeClusters =
rhs.decomposedStringWithCanonicalMapping.map {
Array(String($0).unicodeScalars)
}
let expectHasPrefix = lhsNFDGraphemeClusters.starts(
with: rhsNFDGraphemeClusters, by: (==))
let expectHasSuffix =
lhsNFDGraphemeClusters.lazy.reversed().starts(
with: rhsNFDGraphemeClusters.lazy.reversed(), by: (==))

func testFailure(_ lhs: Bool, _ rhs: Bool, _ stack: [UInt]) -> Int {
guard lhs == rhs else {
// print(stack)
return 1
}
return 0
}

var failures = 0
failures += testFailure(expectHasPrefix, lhs.hasPrefix(rhs), stack + [#line])
failures += testFailure(expectHasSuffix, lhs.hasSuffix(rhs), stack + [#line])
return failures
}

extension TestNSString {
func test_PrefixSuffix() {
for test in comparisonTests {
if case .skip = test.behavior {
continue
}

var failures = 0
failures += checkHasPrefixHasSuffix(test.lhs, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(test.rhs, test.lhs, [test.loc, #line])

let fragment = "abc"
let combiner = "\u{0301}"

failures += checkHasPrefixHasSuffix(test.lhs + fragment, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(fragment + test.lhs, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(test.lhs + combiner, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(combiner + test.lhs, test.rhs, [test.loc, #line])

let fail = (failures > 0)
if fail {
// print("Prefix/Suffix case \(test.loc): \(failures) failures")
// print("Failures were\(test.expectedFailure ? "" : " not") expected")
}
XCTAssert(test.expectedFailure == fail, "Unexpected \(test.expectedFailure ?"success":"failure"): \(test.loc)")
}
}
}

func test_reflection() {
}

Expand Down