inconsistent behavior of `lapce_core::word::WordCursor::next_boundary()`
Open
Nobody has claimed this yet.
A-editor
C-improvement
question
- Dominant language
- Rust
- Stars
- 38.9k
- Forks
- 1.3k
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
In these tests, given test_1 and test_2, I'd expect test_3 to pass. But it does not. I have to write test_4. It is also suprising that, before returning None, the method returns buffer::len() instead of buffer::len() - 1 (line A and B).
mod test {
use crate::buffer::Buffer;
use super::WordCursor;
#[test]
fn test_1() {
let buffer = Buffer::new("a\nb");
let mut cursor = WordCursor::new(buffer.text(), 0);
assert_eq!(cursor.next_boundary(), Some(2));
assert_eq!(cursor.next_boundary(), Some(buffer.len())); // <- A
assert_eq!(cursor.next_boundary(), None);
}
#[test]
fn test_2() {
let buffer = Buffer::new("a b ");
let mut cursor = WordCursor::new(buffer.text(), 0);
assert_eq!(cursor.next_boundary(), Some(2));
assert_eq!(cursor.next_boundary(), Some(buffer.len())); // <- B
assert_eq!(cursor.next_boundary(), None);
}
// This test fails.
#[test]
fn test_3() {
let buffer = Buffer::new("a\nb\n\n\n");
let mut cursor = WordCursor::new(buffer.text(), 0);
assert_eq!(cursor.next_boundary(), Some(2));
assert_eq!(cursor.next_boundary(), Some(buffer.len()));
assert_eq!(cursor.next_boundary(), None);
}
#[test]
fn test_4() {
let buffer = Buffer::new("a\nb\n\n\n");
let mut cursor = WordCursor::new(buffer.text(), 0);
assert_eq!(cursor.next_boundary(), Some(2));
// This assertion also fails:
// assert_eq!(cursor.next_boundary(), Some(3));
assert_eq!(cursor.next_boundary(), Some(4));
assert_eq!(cursor.next_boundary(), Some(5));
assert_eq!(cursor.next_boundary(), Some(6));
assert_eq!(cursor.next_boundary(), None);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the lapce_core::word::WordCursor::next_boundary() entry point and run the four supplied tests to reproduce the differing boundary behavior. Trace how the cursor advances through trailing newlines and reaches buffer::len(); done means the intended sequence is consistent and the relevant tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100