Skip to content

Commit 12f72f9

Browse files
authored
Merge pull request #583 from Quick/sequence-allsatisfy-shim
Rename `Sequence.all` to `allSatisfy` to match SE-0207
2 parents e04ac7a + 7968198 commit 12f72f9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Sources/Nimble/Matchers/Contain.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public func contain<S: Sequence, T: Equatable>(_ items: [T]) -> Predicate<S>
1010
where S.Iterator.Element == T {
1111
return Predicate.simple("contain <\(arrayAsString(items))>") { actualExpression in
1212
if let actual = try actualExpression.evaluate() {
13-
let matches = items.all {
13+
let matches = items.allSatisfy {
1414
return actual.contains($0)
1515
}
1616
return PredicateStatus(bool: matches)
@@ -27,7 +27,7 @@ public func contain(_ substrings: String...) -> Predicate<String> {
2727
public func contain(_ substrings: [String]) -> Predicate<String> {
2828
return Predicate.simple("contain <\(arrayAsString(substrings))>") { actualExpression in
2929
if let actual = try actualExpression.evaluate() {
30-
let matches = substrings.all {
30+
let matches = substrings.allSatisfy {
3131
let range = actual.range(of: $0)
3232
return range != nil && !range!.isEmpty
3333
}
@@ -45,7 +45,7 @@ public func contain(_ substrings: NSString...) -> Predicate<NSString> {
4545
public func contain(_ substrings: [NSString]) -> Predicate<NSString> {
4646
return Predicate.simple("contain <\(arrayAsString(substrings))>") { actualExpression in
4747
if let actual = try actualExpression.evaluate() {
48-
let matches = substrings.all { actual.range(of: $0.description).length != 0 }
48+
let matches = substrings.allSatisfy { actual.range(of: $0.description).length != 0 }
4949
return PredicateStatus(bool: matches)
5050
}
5151
return .fail
@@ -60,7 +60,7 @@ public func contain(_ items: Any?...) -> Predicate<NMBContainer> {
6060
public func contain(_ items: [Any?]) -> Predicate<NMBContainer> {
6161
return Predicate.simple("contain <\(arrayAsString(items))>") { actualExpression in
6262
guard let actual = try actualExpression.evaluate() else { return .fail }
63-
let matches = items.all { item in
63+
let matches = items.allSatisfy { item in
6464
return item.map { actual.contains($0) } ?? false
6565
}
6666
return PredicateStatus(bool: matches)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Foundation
22

3+
#if !swift(>=4.2)
34
extension Sequence {
4-
internal func all(_ predicate: (Iterator.Element) -> Bool) -> Bool {
5+
internal func allSatisfy(_ predicate: (Element) throws -> Bool) rethrows -> Bool {
56
for item in self {
6-
if !predicate(item) {
7+
if try !predicate(item) {
78
return false
89
}
910
}
1011
return true
1112
}
1213
}
14+
#endif

0 commit comments

Comments
 (0)