Skip to content

Commit

Permalink
Don't split function definitions across lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Mar 21, 2018
1 parent 6343a18 commit 2ad0070
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
9 changes: 3 additions & 6 deletions Hamcrest/DictionaryMatchers.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
public func hasEntry<K, V>(_ keyMatcher: Matcher<K>, _ valueMatcher: Matcher<V>)
-> Matcher<Dictionary<K, V>> {
public func hasEntry<K, V>(_ keyMatcher: Matcher<K>, _ valueMatcher: Matcher<V>) -> Matcher<Dictionary<K, V>> {
return Matcher("a dictionary containing [\(keyMatcher.description) -> \(valueMatcher.description)]") {
(dictionary: Dictionary<K, V>) -> Bool in

Expand All @@ -12,17 +11,15 @@ public func hasEntry<K, V>(_ keyMatcher: Matcher<K>, _ valueMatcher: Matcher<V>)
}
}

public func hasEntry<K, V: Equatable>(_ expectedKey: K, _ expectedValue: V)
-> Matcher<Dictionary<K, V>> {
public func hasEntry<K, V: Equatable>(_ expectedKey: K, _ expectedValue: V) -> Matcher<Dictionary<K, V>> {
return hasEntry(equalToWithoutDescription(expectedKey), equalToWithoutDescription(expectedValue))
}

public func hasKey<K, V>(_ matcher: Matcher<K>) -> Matcher<Dictionary<K, V>> {
return hasEntry(matcher, anything())
}

public func hasKey<K, V>(_ expectedKey: K)
-> Matcher<Dictionary<K, V>> {
public func hasKey<K, V>(_ expectedKey: K) -> Matcher<Dictionary<K, V>> {
return hasKey(equalToWithoutDescription(expectedKey))
}

Expand Down
3 changes: 1 addition & 2 deletions Hamcrest/OperatorMatchers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public func <= <T: Comparable>(value: T, expectedValue: T) -> MatchResultDescrip
return MatchResultDescription(value: value, matcher: lessThanOrEqualTo(expectedValue))
}

public func && (lhs: MatchResultDescription, rhs: MatchResultDescription)
-> MatchResultDescription {
public func && (lhs: MatchResultDescription, rhs: MatchResultDescription) -> MatchResultDescription {
switch (lhs.result, rhs.result) {
case (nil, nil):
return MatchResultDescription(result: .none)
Expand Down
42 changes: 14 additions & 28 deletions Hamcrest/SequenceMatchers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public func hasCount<T: Collection>(_ expectedCount: T.IndexDistance) -> Matcher
return hasCount(equalToWithoutDescription(expectedCount))
}

public func everyItem<T, S: Sequence>(_ matcher: Matcher<T>)
-> Matcher<S> where S.Iterator.Element == T {
public func everyItem<T, S: Sequence>(_ matcher: Matcher<T>) -> Matcher<S> where S.Iterator.Element == T {
return Matcher("a sequence where every item \(matcher.description)") {
(values: S) -> MatchResult in
var mismatchDescriptions: [String?] = []
Expand All @@ -36,8 +35,7 @@ public func everyItem<T, S: Sequence>(_ matcher: Matcher<T>)
}
}

private func hasItem<T, S: Sequence>(_ matcher: Matcher<T>,
_ values: S) -> Bool where S.Iterator.Element == T {
private func hasItem<T, S: Sequence>(_ matcher: Matcher<T>, _ values: S) -> Bool where S.Iterator.Element == T {
for value in values {
if matcher.matches(value).boolValue {
return true
Expand All @@ -46,20 +44,17 @@ private func hasItem<T, S: Sequence>(_ matcher: Matcher<T>,
return false
}

public func hasItem<T, S: Sequence>(_ matcher: Matcher<T>)
-> Matcher<S> where S.Iterator.Element == T {
public func hasItem<T, S: Sequence>(_ matcher: Matcher<T>) -> Matcher<S> where S.Iterator.Element == T {
return Matcher("a sequence containing \(matcher.description)") {
(values: S) -> Bool in hasItem(matcher, values)
}
}

public func hasItem<T: Equatable, S: Sequence>(_ expectedValue: T)
-> Matcher<S> where S.Iterator.Element == T {
public func hasItem<T: Equatable, S: Sequence>(_ expectedValue: T) -> Matcher<S> where S.Iterator.Element == T {
return hasItem(equalToWithoutDescription(expectedValue))
}

private func hasItems<T, S: Sequence>(_ matchers: [Matcher<T>])
-> Matcher<S> where S.Iterator.Element == T {
private func hasItems<T, S: Sequence>(_ matchers: [Matcher<T>]) -> Matcher<S> where S.Iterator.Element == T {
return Matcher("a sequence containing \(joinMatcherDescriptions(matchers))") {
(values: S) -> MatchResult in
var missingItems = [] as [Matcher<T>]
Expand All @@ -79,36 +74,30 @@ private func hasItems<T, S: Sequence>(_ matchers: [Matcher<T>])
}
}

public func hasItems<T, S: Sequence>(_ matchers: Matcher<T>...)
-> Matcher<S> where S.Iterator.Element == T {
public func hasItems<T, S: Sequence>(_ matchers: Matcher<T>...) -> Matcher<S> where S.Iterator.Element == T {
return hasItems(matchers)
}

public func hasItems<T: Equatable, S: Sequence>
(_ expectedValues: T...) -> Matcher<S> where S.Iterator.Element == T {
public func hasItems<T: Equatable, S: Sequence>(_ expectedValues: T...) -> Matcher<S> where S.Iterator.Element == T {
return hasItems(expectedValues.map {equalToWithoutDescription($0)})
}

private func contains<T, S: Sequence>(_ matchers: [Matcher<T>])
-> Matcher<S> where S.Iterator.Element == T {
private func contains<T, S: Sequence>(_ matchers: [Matcher<T>]) -> Matcher<S> where S.Iterator.Element == T {
return Matcher("a sequence containing " + joinDescriptions(matchers.map({$0.description}))) {
(values: S) -> MatchResult in
return applyMatchers(matchers, values: values)
}
}

public func contains<T, S: Sequence>(_ matchers: Matcher<T>...)
-> Matcher<S> where S.Iterator.Element == T {
public func contains<T, S: Sequence>(_ matchers: Matcher<T>...) -> Matcher<S> where S.Iterator.Element == T {
return contains(matchers)
}

public func contains<T: Equatable, S: Sequence>
(_ expectedValues: T...) -> Matcher<S> where S.Iterator.Element == T {
public func contains<T: Equatable, S: Sequence>(_ expectedValues: T...) -> Matcher<S> where S.Iterator.Element == T {
return contains(expectedValues.map {equalToWithoutDescription($0)})
}

private func containsInAnyOrder<T, S: Sequence>
(_ matchers: [Matcher<T>]) -> Matcher<S> where S.Iterator.Element == T {
private func containsInAnyOrder<T, S: Sequence>(_ matchers: [Matcher<T>]) -> Matcher<S> where S.Iterator.Element == T {
let descriptions = joinDescriptions(matchers.map({$0.description}))

return Matcher("a sequence containing in any order " + descriptions) {
Expand Down Expand Up @@ -138,18 +127,15 @@ private func containsInAnyOrder<T, S: Sequence>
}
}

public func containsInAnyOrder<T, S: Sequence>
(_ matchers: Matcher<T>...) -> Matcher<S> where S.Iterator.Element == T {
public func containsInAnyOrder<T, S: Sequence>(_ matchers: Matcher<T>...) -> Matcher<S> where S.Iterator.Element == T {
return containsInAnyOrder(matchers)
}

public func containsInAnyOrder<T: Equatable, S: Sequence>
(_ expectedValues: T...) -> Matcher<S> where S.Iterator.Element == T {
public func containsInAnyOrder<T: Equatable, S: Sequence>(_ expectedValues: T...) -> Matcher<S> where S.Iterator.Element == T {
return containsInAnyOrder(expectedValues.map {equalToWithoutDescription($0)})
}

func applyMatchers<T, S: Sequence>
(_ matchers: [Matcher<T>], values: S) -> MatchResult where S.Iterator.Element == T {
func applyMatchers<T, S: Sequence>(_ matchers: [Matcher<T>], values: S) -> MatchResult where S.Iterator.Element == T {
var mismatchDescriptions: [String?] = []

var i = 0
Expand Down

0 comments on commit 2ad0070

Please sign in to comment.