CleanCocoa / CleanCocoa/TextBuffer
Add shared testing harness for all Buffer-conforming types we ship
- Dominant language
- Swift
- Stars
- 10
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Imported from https://github.com/CleanCocoa/DeclarativeTextKit/issues/6
-----
E.g. `NSTextViewBuffer`, `MutableStringBuffer`, `Undoable` 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:
```swift
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:
```swift
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.