Repository: ABridoux/scout (swift)

Issue:
Jaro-Winkler distance crashes with one character key
**Describe the bug**
The Jaro-Winkler distance computing crashed with an index out of bounds when a key with one character is encountered.

Pull request:
Closes #253

Patch:
diff --git a/Sources/Scout/Extensions/String+Jaro-Winkler.swift b/Sources/Scout/Extensions/String+Jaro-Winkler.swift
index 902c924c..f105fc7a 100644
--- a/Sources/Scout/Extensions/String+Jaro-Winkler.swift
+++ b/Sources/Scout/Extensions/String+Jaro-Winkler.swift
@@ -38,7 +38,7 @@ private struct JaroWinklerDistance {
         self.string1 = string1
         self.string2 = string2
 
-        maxSpacing = max(string1.count, string2.count) / 2 - 1
+        maxSpacing = max(0, max(string1.count, string2.count) / 2 - 1)
     }
 
     func computeMatches() -> [Int] {


Test patch:
diff --git a/Tests/ScoutTests/ExtensionsTests/String+Jaro-WinklerTests.swift b/Tests/ScoutTests/ExtensionsTests/String+Jaro-WinklerTests.swift
index 9a0cf573..c6d06fbd 100644
--- a/Tests/ScoutTests/ExtensionsTests/String+Jaro-WinklerTests.swift
+++ b/Tests/ScoutTests/ExtensionsTests/String+Jaro-WinklerTests.swift
@@ -33,4 +33,9 @@ final class String_JaroWinklerTests: XCTestCase {
         let result = target.bestJaroWinklerMatchIn(propositions: propositions)
         XCTAssertEqual(result, "version")
     }
+
+    func testMatchSingleCharacters_Equals0() {
+        let result = "b".jaroWinklerDistance(from: "a")
+        XCTAssertEqual(result, 0)
+    }
 }