-
-
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.
Generic over TextRange, MockTextTokenizer
- Loading branch information
1 parent
036f19e
commit b184b82
Showing
5 changed files
with
52 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
public final class MockTextTokenizer: TextTokenizer { | ||
public enum Request: Hashable { | ||
case position(Int, TextGranularity, TextDirection) | ||
} | ||
|
||
public enum Response: Hashable { | ||
case position(Int?) | ||
case rangeEnclosingPosition(Range<Int>?) | ||
} | ||
|
||
public private(set) var requests: [Request] = [] | ||
public var responses: [Response] = [] | ||
|
||
public init() { | ||
} | ||
|
||
public func closestMatchingVerticalLocation(to location: Int, above: Bool) -> Int? { | ||
return nil | ||
} | ||
|
||
public func position(from position: Int, toBoundary granularity: TextGranularity, inDirection direction: TextDirection) -> Int? { | ||
requests.append(.position(position, granularity, direction)) | ||
|
||
switch responses.removeFirst() { | ||
case let .position(value): | ||
return value | ||
default: | ||
fatalError("wrong return type") | ||
} | ||
} | ||
|
||
public func rangeEnclosingPosition(_ position: Int, with granularity: TextGranularity, inDirection direction: TextDirection) -> Range<Int>? { | ||
return nil | ||
} | ||
|
||
public func isPosition(_ position: Int, atBoundary granularity: TextGranularity, inDirection direction: TextDirection) -> Bool { | ||
return false | ||
} | ||
|
||
public func isPosition(_ position: Int, withinTextUnit granularity: TextGranularity, inDirection direction: TextDirection) -> Bool { | ||
return false | ||
} | ||
} |
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