-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving to using TextTokenizer completely
- Loading branch information
1 parent
73e264a
commit 0e6e265
Showing
6 changed files
with
74 additions
and
42 deletions.
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,32 @@ | ||
import Testing | ||
import IBeam | ||
|
||
class MockCoordinateProvider: TextCoordinateProvider { | ||
func closestMatchingVerticalLocation(to location: Int, above: Bool) -> Int? { | ||
let offset = above ? -5 : 5 | ||
|
||
return location + offset | ||
} | ||
} | ||
import Ligature | ||
|
||
final class MultiCursorStateTests { | ||
@Test | ||
func addCursorBelow() async throws { | ||
@Test @MainActor | ||
func addCursorBelow() throws { | ||
let cursor = Cursor(range: 0..<10) | ||
let provider = MockCoordinateProvider() | ||
var state = MultiCursorState(cursors: [cursor], coordinateProvider: provider) | ||
let tokenizer = MockTextTokenizer() | ||
let state = MultiCursorState(cursors: [cursor], tokenizer: tokenizer) | ||
|
||
tokenizer.responses = [.position(5), .position(15)] | ||
state.addCursorBelow() | ||
|
||
#expect(tokenizer.requests == [.position(0, .character, .layout(.down)), .position(10, .character, .layout(.down))]) | ||
#expect(state.cursors.map(\.range) == [0..<10, 5..<15]) | ||
} | ||
|
||
@Test @MainActor | ||
func handleLeftArrowWithSingleInsertion() throws { | ||
let cursor = Cursor(range: 1..<1) | ||
let tokenizer = MockTextTokenizer() | ||
let state = MultiCursorState(cursors: [cursor], affinity: .upstream, tokenizer: tokenizer) | ||
|
||
tokenizer.responses = [.position(0)] | ||
state.moveLeft(nil) | ||
|
||
#expect(tokenizer.requests == [.position(1, .character, .layout(.left))]) | ||
#expect(state.cursors.map(\.range) == [0..<0]) | ||
} | ||
} |