New test data just found a bug. Fixed it.

Signed-off-by: Adam Rocska <adam.rocska@adams.solutions>
This commit is contained in:
Adam Rocska 2020-04-29 16:51:36 +02:00
parent 4a854026ec
commit c1c9c55d4f
2 changed files with 12 additions and 2 deletions

View File

@ -6,7 +6,7 @@ extension Data {
let patternLength = data.count
precondition(patternLength > 0, "Pattern can't be empty.")
precondition(self.count >= patternLength, "Pattern can't be >= than the Data to search in.")
precondition(data.indices.contains(from), "Index from which to start the lookup must be contained in the Data.")
precondition(self.indices.contains(from), "Index from which to start the lookup must be contained in the Data.")
var skipTable = [UInt8: Int]()
for (i, byte) in data.enumerated() {

View File

@ -20,6 +20,16 @@ class IndexOfData: XCTestCase {
}
func testIndex_ofData_fromIndex() {
XCTAssertEqual(12, "Hello World Hello World".asciiData.index(of: "Hello World".asciiData, from: 3))
XCTAssertEqual(6, "Hello World".asciiData.index(of: "World".asciiData, from: 3))
XCTAssertNil("Hello world".asciiData.index(of: "World".asciiData, from: 3))
XCTAssertEqual(6, "Hello World SOME World".asciiData.index(of: "World".asciiData, from: 2))
XCTAssertEqual(17, "Hello world SOME World".asciiData.index(of: "World".asciiData, from: 4))
XCTAssertNil("Hello World".asciiData.index(of: "Hello".asciiData, from: 3))
XCTAssertNil("hello World".asciiData.index(of: "hello".asciiData, from: 3))
XCTAssertNil("hello world".asciiData.index(of: "Hello".asciiData, from: 3))
XCTAssertNil("hello World SOME World".asciiData.index(of: "Hello".asciiData, from: 3))
XCTAssertNil("hello world SOME World".asciiData.index(of: "Hello".asciiData, from: 3))
XCTAssertEqual(6, "Hello World Hello World".asciiData.index(of: "World".asciiData, from: 6))
XCTAssertEqual(18, "Hello World Hello World".asciiData.index(of: "World".asciiData, from: 7))
}
}