Skip to content

Commit

Permalink
Merge pull request #565 from Quick/refactor-belessthan-matcher
Browse files Browse the repository at this point in the history
[7.x] Refactor `beLessThan` matcher using `Predicate.simple`
  • Loading branch information
ikesyo committed Jul 8, 2018
2 parents 9f65713 + 8728d41 commit dc046d2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Sources/Nimble/Matchers/BeLessThan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import Foundation

/// A Nimble matcher that succeeds when the actual value is less than the expected value.
public func beLessThan<T: Comparable>(_ expectedValue: T?) -> Predicate<T> {
return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in
failureMessage.postfixMessage = "be less than <\(stringify(expectedValue))>"
let message = "be less than <\(stringify(expectedValue))>"
return Predicate.simple(message) { actualExpression in
if let actual = try actualExpression.evaluate(), let expected = expectedValue {
return actual < expected
return PredicateStatus(bool: actual < expected)
}
return false
}.requireNonNil
return .fail
}
}

/// A Nimble matcher that succeeds when the actual value is less than the expected value.
public func beLessThan(_ expectedValue: NMBComparable?) -> Predicate<NMBComparable> {
return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in
failureMessage.postfixMessage = "be less than <\(stringify(expectedValue))>"
let message = "be less than <\(stringify(expectedValue))>"
return Predicate.simple(message) { actualExpression in
let actualValue = try actualExpression.evaluate()
let matches = actualValue != nil && actualValue!.NMB_compare(expectedValue) == ComparisonResult.orderedAscending
return matches
}.requireNonNil
return PredicateStatus(bool: matches)
}
}

public func <<T: Comparable>(lhs: Expectation<T>, rhs: T) {
Expand Down

0 comments on commit dc046d2

Please sign in to comment.