Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/Queries/StringQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public final class StringQuery<T: Reflectable>: 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<T> {
builder.predicateString = "\(property) == \"\(string)\""
@discardableResult public func equals(_ string: String, options: PredicateOptions = .None) -> FinalizedIncluder<T> {
builder.predicateString = "\(property) ==\(optionsString(options)) \"\(string)\""
return FinalizedIncluder(builder: builder)
}

fileprivate func optionsString(_ options: PredicateOptions) -> String {
if !options.isEmpty && !options.contains(.None) {
var string = "["
Expand Down
6 changes: 6 additions & 0 deletions Tests/PrediKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
}

Expand Down