From 7c555920c246238ab206993d78e71a5b0987f0cd Mon Sep 17 00:00:00 2001 From: Andrii Teplytskyi Date: Thu, 23 May 2019 17:43:13 +0300 Subject: [PATCH 1/3] StringQuery: add and use PredicateOptions in equals method --- Sources/Queries/StringQuery.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Queries/StringQuery.swift b/Sources/Queries/StringQuery.swift index 51a6efe..e6a5d09 100644 --- a/Sources/Queries/StringQuery.swift +++ b/Sources/Queries/StringQuery.swift @@ -125,11 +125,11 @@ public final class StringQuery: NilComparable, Matchable { - file: Name of the file the function is being called from. Defaults to `#file` - line: Number of the line the function is being called from. Defaults to `#line` */ - @discardableResult public func equals(_ string: String) -> FinalizedIncluder { - builder.predicateString = "\(property) == \"\(string)\"" + @discardableResult public func equals(_ string: String, options: PredicateOptions = .None) -> FinalizedIncluder { + builder.predicateString = "\(property) == \(optionsString(options)) \"\(string)\"" return FinalizedIncluder(builder: builder) } - + fileprivate func optionsString(_ options: PredicateOptions) -> String { if !options.isEmpty && !options.contains(.None) { var string = "[" From 8471dfa822f574d924976128fa9f54327e611dcf Mon Sep 17 00:00:00 2001 From: Andrii Teplytskyi Date: Fri, 24 May 2019 19:17:03 +0300 Subject: [PATCH 2/3] StringQuery: remove redundant space --- Sources/Queries/StringQuery.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Queries/StringQuery.swift b/Sources/Queries/StringQuery.swift index e6a5d09..28ec112 100644 --- a/Sources/Queries/StringQuery.swift +++ b/Sources/Queries/StringQuery.swift @@ -126,7 +126,7 @@ public final class StringQuery: NilComparable, Matchable { - line: Number of the line the function is being called from. Defaults to `#line` */ @discardableResult public func equals(_ string: String, options: PredicateOptions = .None) -> FinalizedIncluder { - builder.predicateString = "\(property) == \(optionsString(options)) \"\(string)\"" + builder.predicateString = "\(property) ==\(optionsString(options)) \"\(string)\"" return FinalizedIncluder(builder: builder) } From 94a9e1da4f7e7d8c11e7af957ddeabcea416e4fd Mon Sep 17 00:00:00 2001 From: Andrii Teplytskyi Date: Fri, 24 May 2019 19:18:01 +0300 Subject: [PATCH 3/3] StringQuery: add test for equals(_:options) --- Tests/PrediKitTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/PrediKitTests.swift b/Tests/PrediKitTests.swift index a270097..6a8a1e2 100644 --- a/Tests/PrediKitTests.swift +++ b/Tests/PrediKitTests.swift @@ -72,6 +72,8 @@ class PrediKitTests: XCTestCase { XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title CONTAINS[c] %@", theKrakensTitle).predicateFormat) includeIf.string(.krakenTitle).matches(theKrakensTitle, options: .CaseInsensitive) XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title MATCHES[c] %@", theKrakensTitle).predicateFormat) + includeIf.string(.krakenTitle).equals(theKrakensTitle, options: .CaseInsensitive) + XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title ==[c] %@", theKrakensTitle).predicateFormat) includeIf.string(.krakenTitle).beginsWith(theKrakensTitle, options: .DiacriticInsensitive) XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title BEGINSWITH[d] %@", theKrakensTitle).predicateFormat) @@ -81,6 +83,8 @@ class PrediKitTests: XCTestCase { XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title CONTAINS[d] %@", theKrakensTitle).predicateFormat) includeIf.string(.krakenTitle).matches(theKrakensTitle, options: .DiacriticInsensitive) XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title MATCHES[d] %@", theKrakensTitle).predicateFormat) + includeIf.string(.krakenTitle).equals(theKrakensTitle, options: .DiacriticInsensitive) + XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title ==[d] %@", theKrakensTitle).predicateFormat) includeIf.string(.krakenTitle).beginsWith(theKrakensTitle, options: [.CaseInsensitive, .DiacriticInsensitive]) XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title BEGINSWITH[cd] %@", theKrakensTitle).predicateFormat) @@ -90,6 +94,8 @@ class PrediKitTests: XCTestCase { XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title CONTAINS[cd] %@", theKrakensTitle).predicateFormat) includeIf.string(.krakenTitle).matches(theKrakensTitle, options: [.CaseInsensitive, .DiacriticInsensitive]) XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title MATCHES[cd] %@", theKrakensTitle).predicateFormat) + includeIf.string(.krakenTitle).equals(theKrakensTitle, options: [.CaseInsensitive, .DiacriticInsensitive]) + XCTAssertEqual(includeIf.predicateString, NSPredicate(format: "title ==[cd] %@", theKrakensTitle).predicateFormat) } }