Skip to content

Commit

Permalink
Remove unused variable that does impossible checks sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Feb 1, 2024
1 parent a937f1d commit 8483025
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Sources/RangeState/RangeProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public final class RangeProcessor {
// when starting, we have not even processed zero yet
public private(set) var maximumProcessedLocation: Int?
private var targetProcessingLocation: Int = -1
private var pendingProcessedLocation: Int = -1
private var version = 0
private var processedVersion = -1

Expand Down Expand Up @@ -195,9 +194,6 @@ extension RangeProcessor {
self.pendingEvents.append(.change(VersionedMutation(mutation, version: version)))
self.version += 1

self.pendingProcessedLocation += mutation.delta
precondition(pendingProcessedLocation >= 0)

// at this point, it is possible that the target location is no longer meaningful. But that's ok, because it will be clamped and possibly overwritten anyways

configuration.changeHandler(mutation, {
Expand Down
37 changes: 37 additions & 0 deletions Tests/RangeStateTests/RangeProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,41 @@ final class RangeProcessorTests: XCTestCase {

XCTAssertEqual(handler.mutations, expected)
}

@MainActor
func testDeleteEverythingAfterProcessing() {
let exp = expectation(description: "mutation")
exp.expectedFulfillmentCount = 2

let handler = MockChangeHandler()

handler.changeCompleted = {
exp.fulfill()
}

let content = StringContent(string: "abcde")

let processor = RangeProcessor(
configuration: .init(
lengthProvider: { content.currentLength },
changeHandler: handler.handleChange
)
)

XCTAssertTrue(processor.processLocation(5, mode: .required))
XCTAssertTrue(processor.processed(5))

// insert a character
content.string = ""
processor.didChangeContent(in: NSRange(0..<5), delta: -5)

wait(for: [exp], enforceOrder: true)

let expected = [
RangeMutation(range: NSRange(0..<0), delta: 5, limit: nil),
RangeMutation(range: NSRange(0..<5), delta: -5, limit: 5),
]

XCTAssertEqual(handler.mutations, expected)
}
}

0 comments on commit 8483025

Please sign in to comment.