Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly count CRLF newlines when counting line offsets. #1007

Merged
merged 1 commit into from
Dec 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/racer/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl RawSource {
let mut before = 0;
*self.lines.borrow_mut() = self
.code
.lines()
.split('\n')
.map(|line| {
let len = line.len() + 1;
let res = ByteRange::new(before, before + len);
Expand Down Expand Up @@ -586,6 +586,34 @@ fn myfn() {
);
}

#[test]
fn coords_to_point_lf_newline() {
let src = "\n\
fn myfn() {\n\
let a = 3;\n\
print(a);\n\
}\n";
let src = RawSource::new(src.into());
assert_eq!(
src.coords_to_point(&Coordinate::new(3, 5)),
Some(BytePos(18))
);
}

#[test]
fn coords_to_point_crlf_newline() {
let src = "\r\n\
fn myfn() {\r\n\
let a = 3;\r\n\
print(a);\r\n\
}\r\n";
let src = RawSource::new(src.into());
assert_eq!(
src.coords_to_point(&Coordinate::new(3, 5)),
Some(BytePos(20))
);
}

#[test]
fn test_point_to_coords() {
let src = "
Expand Down