diff --git a/Sources/RangeState/RangeValidator.swift b/Sources/RangeState/RangeValidator.swift index dc390ba..b90c540 100644 --- a/Sources/RangeState/RangeValidator.swift +++ b/Sources/RangeState/RangeValidator.swift @@ -115,7 +115,7 @@ public final class RangeValidator { /// range = NSRange(1..<2) /// delta = -1 public func contentChanged(in range: NSRange, delta: Int) { - let mutation = RangeMutation(range: range, delta: delta, limit: length) + let mutation = RangeMutation(range: range, delta: delta) self.validSet = mutation.transform(set: validSet) diff --git a/Tests/RangeStateTests/RangeValidatorTests.swift b/Tests/RangeStateTests/RangeValidatorTests.swift index 22bec95..037afba 100644 --- a/Tests/RangeStateTests/RangeValidatorTests.swift +++ b/Tests/RangeStateTests/RangeValidatorTests.swift @@ -6,10 +6,14 @@ final class RangeValidatorTests: XCTestCase { typealias StringValidator = RangeValidator @MainActor - func testContentChange() { + func testContentChange() async { + let validationExp = expectation(description: "validation") + var content = StringContent(string: "abc") let provider = StringValidator.ValidationProvider( syncValue: { + validationExp.fulfill() + return .success($0.value) }, asyncValue: { contentRange, _ in @@ -23,8 +27,41 @@ final class RangeValidatorTests: XCTestCase { ) ) - content.string = "abcd" + validator.validate(.all) + + await fulfillment(of: [validationExp], timeout: 1.0) + content.string = "abcd" validator.contentChanged(in: NSRange(3..<3), delta: 1) } + + @MainActor + func testContentDeleted() async { + let validationExp = expectation(description: "validation") + + var content = StringContent(string: "abc") + let provider = StringValidator.ValidationProvider( + syncValue: { + validationExp.fulfill() + + return .success($0.value) + }, + asyncValue: { contentRange, _ in + return .success(contentRange.value) + }) + + let validator = StringValidator( + configuration: .init( + versionedContent: content, + validationProvider: provider + ) + ) + + validator.validate(.all) + + await fulfillment(of: [validationExp], timeout: 1.0) + + content.string = "ac" + validator.contentChanged(in: NSRange(1..<2), delta: -1) + } } diff --git a/Tests/RangeStateTests/StringContent.swift b/Tests/RangeStateTests/StringContent.swift index 036d657..66eb89d 100644 --- a/Tests/RangeStateTests/StringContent.swift +++ b/Tests/RangeStateTests/StringContent.swift @@ -2,7 +2,7 @@ import Foundation import RangeState -struct StringContent: VersionedContent { +final class StringContent: VersionedContent { private var version: Int = 0 var string: String {