-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Imported from CleanCocoa/DeclarativeTextKit#6
E.g. NSTextViewBuffer, MutableStringBuffer, Undoable<Buffer> should all behave the same.
I went with code duplication for each of these so far, but that's getting a bit tedious. I notice that I'm feeling a resistance towards adding new shared Buffer features or changing the API because I need to touch 3+ test suites.
A shared suite would be cool. As a matter of fact, I have never used something like that with XCTest, though.
A naive approach would be to merge all test files into 1, and then add a helper that transforms this:
func testDelete() throws {
let buffer = MutableStringBuffer("Hello: world!")
buffer.insertionLocation = length(of: "Hello: wor")
assertBufferState(buffer, "Hello: wor{^}ld!")
try buffer.delete(in: .init(location: 0, length: 4))
assertBufferState(buffer, "o: wor{^}ld!")
try buffer.delete(in: .init(location: 0, length: 4))
assertBufferState(buffer, "or{^}ld!")
try buffer.delete(in: .init(location: 0, length: 4))
assertBufferState(buffer, "{^}!")
}... into something like this:
func testDelete() throws {
let originalContent = "Hello: world!"
foreach buffer in [
MutableStringBuffer(originalContent),
textView(originalContent),
Undoable(MutableStringBuffer(originalContent)),
] {
buffer.insertionLocation = length(of: "Hello: wor")
assertBufferState(buffer, "Hello: wor{^}ld!")
try buffer.delete(in: .init(location: 0, length: 4))
assertBufferState(buffer, "o: wor{^}ld!")
try buffer.delete(in: .init(location: 0, length: 4))
assertBufferState(buffer, "or{^}ld!")
try buffer.delete(in: .init(location: 0, length: 4))
assertBufferState(buffer, "{^}!")
}
}- The loop should be in a block-based test helper for reuse
- Test failure messages need to mention which buffer type failed to meet the condition
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request