mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
isEquivalent: => by areEquivalent:
This commit is contained in:
@@ -2244,7 +2244,7 @@ public func expectEqualSequence<
|
||||
) where
|
||||
Expected.Iterator.Element == Actual.Iterator.Element {
|
||||
|
||||
if !expected.elementsEqual(actual, isEquivalent: sameValue) {
|
||||
if !expected.elementsEqual(actual, by: sameValue) {
|
||||
expectationFailure("expected elements: \"\(expected)\"\n"
|
||||
+ "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))",
|
||||
trace: ${trace})
|
||||
|
||||
@@ -36,10 +36,10 @@ equivalenceExplanation = """\
|
||||
/// is, for any elements `a`, `b`, and `c`, the following conditions must
|
||||
/// hold:
|
||||
///
|
||||
/// - `isEquivalent(a, a)` is always `true`. (Reflexivity)
|
||||
/// - `isEquivalent(a, b)` implies `isEquivalent(b, a)`. (Symmetry)
|
||||
/// - If `isEquivalent(a, b)` and `isEquivalent(b, c)` are both `true`, then
|
||||
/// `isEquivalent(a, c)` is also `true`. (Transitivity)
|
||||
/// - `areEquivalent(a, a)` is always `true`. (Reflexivity)
|
||||
/// - `areEquivalent(a, b)` implies `areEquivalent(b, a)`. (Symmetry)
|
||||
/// - If `areEquivalent(a, b)` and `areEquivalent(b, c)` are both `true`, then
|
||||
/// `areEquivalent(a, c)` is also `true`. (Transitivity)
|
||||
///"""
|
||||
|
||||
}%
|
||||
@@ -211,7 +211,7 @@ extension Sequence ${"" if preds else "where Iterator.Element : Equatable"} {
|
||||
${equivalenceExplanation}
|
||||
/// - Parameters:
|
||||
/// - possiblePrefix: A sequence to compare to this sequence.
|
||||
/// - isEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// - areEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// are equivalent; otherwise, `false`.
|
||||
/// - Returns: `true` if the initial elements of the sequence are equivalent
|
||||
/// to the elements of `possiblePrefix`; otherwise, `false`. Returns
|
||||
@@ -237,12 +237,12 @@ ${equivalenceExplanation}
|
||||
/// the elements of `possiblePrefix`; otherwise, `false`. Returns `true`
|
||||
/// if `possiblePrefix` has no elements.
|
||||
///
|
||||
/// - SeeAlso: `starts(with:isEquivalent:)`
|
||||
/// - SeeAlso: `starts(with:by:)`
|
||||
% end
|
||||
public func starts<PossiblePrefix>(
|
||||
with possiblePrefix: PossiblePrefix${"," if preds else ""}
|
||||
% if preds:
|
||||
isEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
by areEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> Bool
|
||||
where
|
||||
@@ -252,7 +252,7 @@ ${equivalenceExplanation}
|
||||
var possiblePrefixIterator = possiblePrefix.makeIterator()
|
||||
for e0 in self {
|
||||
if let e1 = possiblePrefixIterator.next() {
|
||||
if ${"try !isEquivalent(e0, e1)" if preds else "e0 != e1"} {
|
||||
if ${"try !areEquivalent(e0, e1)" if preds else "e0 != e1"} {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -287,10 +287,10 @@ extension Sequence ${"" if preds else "where Iterator.Element : Equatable"} {
|
||||
${equivalenceExplanation}
|
||||
/// - Parameters:
|
||||
/// - other: A sequence to compare to this sequence.
|
||||
/// - isEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// - areEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// are equivalent; otherwise, `false`.
|
||||
/// - Returns: `true` if this sequence and `other` contain equivalent items,
|
||||
/// using `isEquivalent` as the equivalence test; otherwise, `false.`
|
||||
/// using `areEquivalent` as the equivalence test; otherwise, `false.`
|
||||
///
|
||||
/// - SeeAlso: `elementsEqual(_:)`
|
||||
% else:
|
||||
@@ -313,12 +313,12 @@ ${equivalenceExplanation}
|
||||
/// - Returns: `true` if this sequence and `other` contain the same elements
|
||||
/// in the same order.
|
||||
///
|
||||
/// - SeeAlso: `elementsEqual(_:isEquivalent:)`
|
||||
/// - SeeAlso: `elementsEqual(_:by:)`
|
||||
% end
|
||||
public func elementsEqual<OtherSequence>(
|
||||
_ other: OtherSequence${"," if preds else ""}
|
||||
% if preds:
|
||||
isEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
by areEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> Bool
|
||||
where
|
||||
@@ -330,7 +330,7 @@ ${equivalenceExplanation}
|
||||
while true {
|
||||
switch (iter1.next(), iter2.next()) {
|
||||
case let (e1?, e2?):
|
||||
if ${'try !isEquivalent(e1, e2)' if preds else 'e1 != e2'} {
|
||||
if ${'try !areEquivalent(e1, e2)' if preds else 'e1 != e2'} {
|
||||
return false
|
||||
}
|
||||
case (_?, nil),
|
||||
@@ -694,7 +694,7 @@ extension Sequence {
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "starts(with:isEquivalent:)")
|
||||
@available(*, unavailable, renamed: "starts(with:by:)")
|
||||
public func startsWith<PossiblePrefix>(
|
||||
_ possiblePrefix: PossiblePrefix,
|
||||
isEquivalent: @noescape (Iterator.Element, Iterator.Element) throws -> Bool
|
||||
|
||||
@@ -240,10 +240,10 @@ func checkHasPrefixHasSuffix(
|
||||
Array(String($0).unicodeScalars)
|
||||
}
|
||||
let expectHasPrefix = lhsNFDGraphemeClusters.starts(
|
||||
with: rhsNFDGraphemeClusters, isEquivalent: (==))
|
||||
with: rhsNFDGraphemeClusters, by: (==))
|
||||
|
||||
let expectHasSuffix = lhsNFDGraphemeClusters.lazy.reversed()
|
||||
.starts(with: rhsNFDGraphemeClusters.lazy.reversed(), isEquivalent: (==))
|
||||
.starts(with: rhsNFDGraphemeClusters.lazy.reversed(), by: (==))
|
||||
|
||||
expectEqual(expectHasPrefix, lhs.hasPrefix(rhs), stackTrace: stackTrace)
|
||||
expectEqual(
|
||||
@@ -411,7 +411,7 @@ CStringTests.test("String(cString:)") {
|
||||
CStringTests.test("String.decodeCString") {
|
||||
do {
|
||||
let s = getNullCString()
|
||||
let result = String.decodeCString(UnsafePointer(s), `as`: UTF8.self)
|
||||
let result = String.decodeCString(UnsafePointer(s), as: UTF8.self)
|
||||
expectEmpty(result)
|
||||
}
|
||||
do { // repairing
|
||||
|
||||
@@ -166,7 +166,7 @@ func testArchetypeReplacement3 (_ a : [Int]) {
|
||||
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropLast({#(n): Int#})[#ArraySlice<Int>#]
|
||||
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropFirst({#(n): Int#})[#AnySequence<Int>#]
|
||||
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: prefix({#(maxLength): Int#})[#AnySequence<Int>#]
|
||||
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#isEquivalent: (Int, Int) throws -> Bool##(Int, Int) throws -> Bool#})[' rethrows'][#Bool#]
|
||||
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#by: (Int, Int) throws -> Bool##(Int, Int) throws -> Bool#})[' rethrows'][#Bool#]
|
||||
|
||||
|
||||
protocol P2 {
|
||||
|
||||
Reference in New Issue
Block a user