-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify and simplify didChangeContent(in:delta:), add test
- Loading branch information
1 parent
126ece2
commit ca1c369
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import XCTest | ||
import Neon | ||
|
||
class MockInterface: TextSystemInterface { | ||
var length: Int | ||
var visibleRange: NSRange | ||
|
||
init(length: Int = 0, visibleRange: NSRange = .zero) { | ||
self.length = length | ||
self.visibleRange = visibleRange | ||
} | ||
|
||
func clearStyle(in range: NSRange) { | ||
} | ||
|
||
func applyStyle(to token: Token) { | ||
} | ||
} | ||
|
||
class HighlighterTests: XCTestCase { | ||
func testEditAndVisibleRangeChange() throws { | ||
let interface = MockInterface() | ||
|
||
var requestedRange: NSRange? = nil | ||
let provider: TokenProvider = { range, block in | ||
requestedRange = range | ||
block(.success(.noChange)) | ||
} | ||
|
||
let highlighter = Highlighter(textInterface: interface, tokenProvider: provider) | ||
|
||
interface.length = 10 | ||
highlighter.didChangeContent(in: NSRange(0..<0), delta: 10) | ||
|
||
interface.visibleRange = NSRange(0..<10) | ||
highlighter.visibleContentDidChange() | ||
|
||
XCTAssertEqual(requestedRange, NSRange(0..<10)) | ||
} | ||
} |