Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Fix test failures due to new text offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Feb 24, 2019
1 parent cd54b3a commit ff90258
Show file tree
Hide file tree
Showing 70 changed files with 184 additions and 182 deletions.
34 changes: 17 additions & 17 deletions rls/src/actions/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,51 +1282,51 @@ pub mod test {
let file = fixtures_dir().join("hover/src/test_extract_decl.rs");

let expected = "pub fn foo() -> Foo<u32>";
let row_start = Row::new_zero_indexed(10);
let row_start = Row::new_zero_indexed(0);
let actual = extract_decl(&vfs, &file, row_start).expect("function declaration").join("\n");
assert_eq!(expected, actual);

let expected = "pub struct Foo<T>";
let row_start = Row::new_zero_indexed(15);
let row_start = Row::new_zero_indexed(5);
let actual = extract_decl(&vfs, &file, row_start).expect("struct declaration").join("\n");
assert_eq!(expected, actual);

let expected = "pub enum Bar";
let row_start = Row::new_zero_indexed(20);
let row_start = Row::new_zero_indexed(10);
let actual = extract_decl(&vfs, &file, row_start).expect("enum declaration").join("\n");
assert_eq!(expected, actual);

let expected = "pub struct NewType(pub u32, f32)";
let row_start = Row::new_zero_indexed(25);
let row_start = Row::new_zero_indexed(15);
let actual = extract_decl(&vfs, &file, row_start).expect("tuple declaration").join("\n");
assert_eq!(expected, actual);

let expected = "pub fn new() -> NewType";
let row_start = Row::new_zero_indexed(28);
let row_start = Row::new_zero_indexed(18);
let actual =
extract_decl(&vfs, &file, row_start).expect("struct function declaration").join("\n");
assert_eq!(expected, actual);

let expected = "pub fn bar<T: Copy + Add>(&self, the_really_long_name_string: String, the_really_long_name_foo: Foo<T>) -> Vec<(String, Foo<T>)>";
let row_start = Row::new_zero_indexed(32);
let row_start = Row::new_zero_indexed(22);
let actual = extract_decl(&vfs, &file, row_start)
.expect("long struct method declaration with generics")
.join("\n");
assert_eq!(expected, actual);

let expected = "pub trait Baz<T> where T: Copy";
let row_start = Row::new_zero_indexed(37);
let row_start = Row::new_zero_indexed(27);
let actual = extract_decl(&vfs, &file, row_start).expect("enum declaration").join("\n");
assert_eq!(expected, actual);

let expected = "fn make_copy(&self) -> Self";
let row_start = Row::new_zero_indexed(38);
let row_start = Row::new_zero_indexed(28);
let actual =
extract_decl(&vfs, &file, row_start).expect("trait method declaration").join("\n");
assert_eq!(expected, actual);

let expected = "fn make_copy(&self) -> Self";
let row_start = Row::new_zero_indexed(42);
let row_start = Row::new_zero_indexed(32);
let actual =
extract_decl(&vfs, &file, row_start).expect("trait method implementation").join("\n");
assert_eq!(expected, actual);
Expand All @@ -1338,7 +1338,7 @@ pub mod test {
U: Clone
",
);
let row_start = Row::new_zero_indexed(47);
let row_start = Row::new_zero_indexed(37);
let actual =
extract_decl(&vfs, &file, row_start).expect("trait declaration multiline").join("\n");
assert_eq!(expected, actual);
Expand All @@ -1351,7 +1351,7 @@ pub mod test {
)
",
);
let row_start = Row::new_zero_indexed(53);
let row_start = Row::new_zero_indexed(43);
let actual = extract_decl(&vfs, &file, row_start)
.expect("function declaration multiline")
.join("\n");
Expand Down Expand Up @@ -1442,7 +1442,7 @@ pub mod test {
)
",
);
let row_start = Row::new_zero_indexed(21);
let row_start = Row::new_zero_indexed(1);
let actual = extract_decl(&vfs, &file, row_start)
.expect("the empty body should not be extracted")
.join("\n");
Expand Down Expand Up @@ -1501,7 +1501,7 @@ pub mod test {
fn test_extract_docs_comment_block() {
let vfs = Vfs::new();
let file = fixtures_dir().join("hover/src/test_extract_docs_comment_block.rs");
let row_start = Row::new_zero_indexed(21);
let row_start = Row::new_zero_indexed(11);
let actual = extract_docs(&vfs, &file, row_start)
.expect(&format!("failed to extract docs: {:?}", file))
.join("\n");
Expand All @@ -1525,7 +1525,7 @@ pub mod test {
fn test_extract_docs_empty_line_before_decl() {
let vfs = Vfs::new();
let file = fixtures_dir().join("hover/src/test_extract_docs_empty_line_before_decl.rs");
let row_start = Row::new_zero_indexed(18);
let row_start = Row::new_zero_indexed(8);
let actual = extract_docs(&vfs, &file, row_start)
.expect(&format!("failed to extract docs: {:?}", file))
.join("\n");
Expand Down Expand Up @@ -1569,7 +1569,7 @@ pub mod test {

assert_eq!(expected, actual);

let row_start = Row::new_zero_indexed(21);
let row_start = Row::new_zero_indexed(11);
let actual = extract_docs(&vfs, &file, row_start)
.expect(&format!("failed to extract docs: {:?}", file))
.join("\n");
Expand All @@ -1590,7 +1590,7 @@ pub mod test {
let vfs = Vfs::new();
let file = fixtures_dir().join("hover/src/test_extract_docs_attributes.rs");

let row_start = Row::new_zero_indexed(21);
let row_start = Row::new_zero_indexed(11);
let actual = extract_docs(&vfs, &file, row_start)
.expect(&format!("failed to extract docs: {:?}", file))
.join("\n");
Expand All @@ -1609,7 +1609,7 @@ pub mod test {

assert_eq!(expected, actual);

let row_start = Row::new_zero_indexed(32);
let row_start = Row::new_zero_indexed(22);
let actual = extract_docs(&vfs, &file, row_start)
.expect(&format!("failed to extract docs: {:?}", file))
.join("\n");
Expand Down
38 changes: 19 additions & 19 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,8 @@ fn client_lens_run() {
}),
data: None,
range: Range {
start: Position { line: 14, character: 3 },
end: Position { line: 14, character: 11 },
start: Position { line: 4, character: 3 },
end: Position { line: 4, character: 11 },
},
};

Expand Down Expand Up @@ -1167,11 +1167,11 @@ fn client_deglob() {
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("src/main.rs")).unwrap(),
},
range: Range { start: Position::new(12, 0), end: Position::new(12, 0) },
range: Range { start: Position::new(2, 0), end: Position::new(2, 0) },
context: CodeActionContext { diagnostics: vec![], only: None },
},
)
.expect("No code actions returned for line 12");
.expect("No code actions returned for line 2");

// Right now we only support deglobbing via commands. Please update this
// test if we move to making text edits via CodeAction (which we should for
Expand All @@ -1193,7 +1193,7 @@ fn client_deglob() {
assert_eq!(
serde_json::from_value::<Location>(arguments[0]["location"].clone()).unwrap(),
Location {
range: Range { start: Position::new(12, 13), end: Position::new(12, 14) },
range: Range { start: Position::new(2, 13), end: Position::new(2, 14) },
uri: Url::from_file_path(p.root().join("src/main.rs")).unwrap(),
}
);
Expand All @@ -1215,7 +1215,7 @@ fn client_deglob() {
assert_eq!(
edits,
vec![TextEdit {
range: Range { start: Position::new(12, 13), end: Position::new(12, 14) },
range: Range { start: Position::new(2, 13), end: Position::new(2, 14) },
new_text: "{Stdin, Stdout}".to_string(),
}]
);
Expand All @@ -1228,7 +1228,7 @@ fn client_deglob() {
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("src/main.rs")).unwrap(),
},
range: Range { start: Position::new(15, 0), end: Position::new(15, 0) },
range: Range { start: Position::new(5, 0), end: Position::new(5, 0) },
context: CodeActionContext { diagnostics: vec![], only: None },
},
)
Expand Down Expand Up @@ -1256,8 +1256,8 @@ fn client_deglob() {
serde_json::from_value::<Location>(arguments[i]["location"].clone()).unwrap(),
Location {
range: Range {
start: Position::new(15, expected[i].0),
end: Position::new(15, expected[i].1),
start: Position::new(5, expected[i].0),
end: Position::new(5, expected[i].1),
},
uri: Url::from_file_path(p.root().join("src/main.rs")).unwrap(),
}
Expand All @@ -1283,7 +1283,7 @@ fn client_deglob() {
expected
.iter()
.map(|e| TextEdit {
range: Range { start: Position::new(15, e.0), end: Position::new(15, e.1) },
range: Range { start: Position::new(5, e.0), end: Position::new(5, e.1) },
new_text: e.2.to_string()
})
.collect::<Vec<_>>()
Expand Down Expand Up @@ -1816,9 +1816,9 @@ fn client_reformat() {
assert_eq!(result.unwrap()[0], TextEdit {
range: Range {
start: Position { line: 0, character: 0 },
end: Position { line: 12, character: 0 },
end: Position { line: 2, character: 0 },
},
new_text: "// Copyright 2017 The Rust Project Developers. See the COPYRIGHT\n// file at the top-level directory of this distribution and at\n// http://rust-lang.org/COPYRIGHT.\n//\n// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your\n// option. This file may not be copied, modified, or distributed\n// except according to those terms.\n\npub mod foo;\npub fn main() {\n let world = \"world\";\n println!(\"Hello, {}!\", world);\n}\n".to_string(),
new_text: "pub mod foo;\npub fn main() {\n let world = \"world\";\n println!(\"Hello, {}!\", world);\n}\n".to_string(),
});

rls.shutdown();
Expand All @@ -1843,8 +1843,8 @@ fn client_reformat_with_range() {
uri: Url::from_file_path(p.root().join("src/main.rs")).unwrap(),
},
range: Range {
start: Position { line: 12, character: 0 },
end: Position { line: 13, character: 0 },
start: Position { line: 2, character: 0 },
end: Position { line: 3, character: 0 },
},
options: FormattingOptions {
tab_size: 4,
Expand All @@ -1855,7 +1855,7 @@ fn client_reformat_with_range() {
);

let newline = if cfg!(windows) { "\r\n" } else { "\n" };
let formatted = "// Copyright 2017 The Rust Project Developers. See the COPYRIGHT\n// file at the top-level directory of this distribution and at\n// http://rust-lang.org/COPYRIGHT.\n//\n// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or\n// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your\n// option. This file may not be copied, modified, or distributed\n// except according to those terms.\n\npub fn main() {\n let world1 = \"world\";\n println!(\"Hello, {}!\", world1);\n let world2 = \"world\";\n println!(\"Hello, {}!\", world2);\n let world3 = \"world\";\n println!(\"Hello, {}!\", world3);\n}\n"
let formatted = "pub fn main() {\n let world1 = \"world\";\n println!(\"Hello, {}!\", world1);\n let world2 = \"world\";\n println!(\"Hello, {}!\", world2);\n let world3 = \"world\";\n println!(\"Hello, {}!\", world3);\n}\n"
.replace("\n", newline);

assert_eq!(result.unwrap()[0].new_text, formatted);
Expand Down Expand Up @@ -2031,10 +2031,10 @@ fn client_find_impls() {
1,
TextDocumentPositionParams {
text_document: TextDocumentIdentifier::new(uri.clone()),
position: Position { line: 12, character: 7 }, // "Bar"
position: Position { line: 3, character: 7 }, // "Bar"
},
);
let expected = [(18, 15, 18, 18), (19, 12, 19, 15)];
let expected = [(9, 15, 9, 18), (10, 12, 10, 15)];
let expected = expected.iter().map(|(a, b, c, d)| Location {
uri: uri.clone(),
range: Range {
Expand All @@ -2051,10 +2051,10 @@ fn client_find_impls() {
1,
TextDocumentPositionParams {
text_document: TextDocumentIdentifier::new(uri.clone()),
position: Position { line: 15, character: 6 }, // "Super"
position: Position { line: 6, character: 6 }, // "Super"
},
);
let expected = [(18, 15, 18, 18), (22, 15, 22, 18)];
let expected = [(9, 15, 9, 18), (13, 15, 13, 18)];
let expected = expected.iter().map(|(a, b, c, d)| Location {
uri: uri.clone(),
range: Range {
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 13,
"line": 3,
"col": 11
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 15,
"line": 5,
"col": 7
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 17,
"line": 7,
"col": 7
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 21,
"line": 11,
"col": 13
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 23,
"line": 13,
"col": 9
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 23,
"line": 13,
"col": 16
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 35,
"col": 16
"line": 15,
"col": 8
},
"data": {
"Ok": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 27,
"line": 17,
"col": 8
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 33,
"line": 20,
"col": 11
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 32,
"line": 22,
"col": 10
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 42,
"col": 15
"line": 22,
"col": 19
},
"data": {
"Ok": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 32,
"line": 22,
"col": 26
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 32,
"line": 22,
"col": 35
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test": {
"file": "test_tooltip_01.rs",
"line": 32,
"line": 22,
"col": 49
},
"data": {
Expand Down
Loading

0 comments on commit ff90258

Please sign in to comment.