aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-05 22:48:26 +0100
committerAleksey Kladov <[email protected]>2020-05-05 22:48:26 +0100
commitca9e0f5fe9ad29ab0c5a0771a0d0eaec97e4104b (patch)
tree42bf4f4eb6e23720717bbc1f1bc58be6d658e23d /crates/ra_ide
parent27c7ef6d65ffa6a642768377d3f0ba85ac8564bf (diff)
Fixup tests
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/diagnostics.rs24
-rw-r--r--crates/ra_ide/src/join_lines.rs6
-rw-r--r--crates/ra_ide/src/references/rename.rs32
-rw-r--r--crates/ra_ide/src/ssr.rs8
-rw-r--r--crates/ra_ide/src/test_utils.rs6
-rw-r--r--crates/ra_ide/src/typing.rs9
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs3
7 files changed, 58 insertions, 30 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 4c04cee07..87a0b80f1 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -241,7 +241,11 @@ mod tests {
241 diagnostics.pop().unwrap_or_else(|| panic!("no diagnostics for:\n{}\n", before)); 241 diagnostics.pop().unwrap_or_else(|| panic!("no diagnostics for:\n{}\n", before));
242 let mut fix = diagnostic.fix.unwrap(); 242 let mut fix = diagnostic.fix.unwrap();
243 let edit = fix.source_file_edits.pop().unwrap().edit; 243 let edit = fix.source_file_edits.pop().unwrap().edit;
244 let actual = edit.apply(&before); 244 let actual = {
245 let mut actual = before.to_string();
246 edit.apply(&mut actual);
247 actual
248 };
245 assert_eq_text!(after, &actual); 249 assert_eq_text!(after, &actual);
246 } 250 }
247 251
@@ -256,7 +260,11 @@ mod tests {
256 let mut fix = diagnostic.fix.unwrap(); 260 let mut fix = diagnostic.fix.unwrap();
257 let edit = fix.source_file_edits.pop().unwrap().edit; 261 let edit = fix.source_file_edits.pop().unwrap().edit;
258 let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); 262 let target_file_contents = analysis.file_text(file_position.file_id).unwrap();
259 let actual = edit.apply(&target_file_contents); 263 let actual = {
264 let mut actual = target_file_contents.to_string();
265 edit.apply(&mut actual);
266 actual
267 };
260 268
261 // Strip indent and empty lines from `after`, to match the behaviour of 269 // Strip indent and empty lines from `after`, to match the behaviour of
262 // `parse_fixture` called from `analysis_and_position`. 270 // `parse_fixture` called from `analysis_and_position`.
@@ -288,7 +296,11 @@ mod tests {
288 let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap(); 296 let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap();
289 let mut fix = diagnostic.fix.unwrap(); 297 let mut fix = diagnostic.fix.unwrap();
290 let edit = fix.source_file_edits.pop().unwrap().edit; 298 let edit = fix.source_file_edits.pop().unwrap().edit;
291 let actual = edit.apply(&before); 299 let actual = {
300 let mut actual = before.to_string();
301 edit.apply(&mut actual);
302 actual
303 };
292 assert_eq_text!(after, &actual); 304 assert_eq_text!(after, &actual);
293 } 305 }
294 306
@@ -662,10 +674,10 @@ mod tests {
662 1, 674 1,
663 ), 675 ),
664 edit: TextEdit { 676 edit: TextEdit {
665 atoms: [ 677 indels: [
666 AtomTextEdit { 678 Indel {
667 delete: 3..9,
668 insert: "{a:42, b: ()}", 679 insert: "{a:42, b: ()}",
680 delete: 3..9,
669 }, 681 },
670 ], 682 ],
671 }, 683 },
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index 63fd6b3e4..d3af780c4 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -569,7 +569,11 @@ fn foo() {
569 let (sel, before) = extract_range(before); 569 let (sel, before) = extract_range(before);
570 let parse = SourceFile::parse(&before); 570 let parse = SourceFile::parse(&before);
571 let result = join_lines(&parse.tree(), sel); 571 let result = join_lines(&parse.tree(), sel);
572 let actual = result.apply(&before); 572 let actual = {
573 let mut actual = before.to_string();
574 result.apply(&mut actual);
575 actual
576 };
573 assert_eq_text!(after, &actual); 577 assert_eq_text!(after, &actual);
574 } 578 }
575 579
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 52e55b0a0..0398d53bc 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -537,10 +537,10 @@ mod tests {
537 2, 537 2,
538 ), 538 ),
539 edit: TextEdit { 539 edit: TextEdit {
540 atoms: [ 540 indels: [
541 AtomTextEdit { 541 Indel {
542 delete: 4..7,
543 insert: "foo2", 542 insert: "foo2",
543 delete: 4..7,
544 }, 544 },
545 ], 545 ],
546 }, 546 },
@@ -589,10 +589,10 @@ mod tests {
589 1, 589 1,
590 ), 590 ),
591 edit: TextEdit { 591 edit: TextEdit {
592 atoms: [ 592 indels: [
593 AtomTextEdit { 593 Indel {
594 delete: 4..7,
595 insert: "foo2", 594 insert: "foo2",
595 delete: 4..7,
596 }, 596 },
597 ], 597 ],
598 }, 598 },
@@ -672,10 +672,10 @@ mod tests {
672 2, 672 2,
673 ), 673 ),
674 edit: TextEdit { 674 edit: TextEdit {
675 atoms: [ 675 indels: [
676 AtomTextEdit { 676 Indel {
677 delete: 8..11,
678 insert: "foo2", 677 insert: "foo2",
678 delete: 8..11,
679 }, 679 },
680 ], 680 ],
681 }, 681 },
@@ -685,10 +685,10 @@ mod tests {
685 1, 685 1,
686 ), 686 ),
687 edit: TextEdit { 687 edit: TextEdit {
688 atoms: [ 688 indels: [
689 AtomTextEdit { 689 Indel {
690 delete: 27..30,
691 insert: "foo2", 690 insert: "foo2",
691 delete: 27..30,
692 }, 692 },
693 ], 693 ],
694 }, 694 },
@@ -720,13 +720,13 @@ mod tests {
720 if let Some(change) = source_change { 720 if let Some(change) = source_change {
721 for edit in change.info.source_file_edits { 721 for edit in change.info.source_file_edits {
722 file_id = Some(edit.file_id); 722 file_id = Some(edit.file_id);
723 for atom in edit.edit.as_atoms() { 723 for indel in edit.edit.as_indels() {
724 text_edit_builder.replace(atom.delete, atom.insert.clone()); 724 text_edit_builder.replace(indel.delete, indel.insert.clone());
725 } 725 }
726 } 726 }
727 } 727 }
728 let result = 728 let mut result = analysis.file_text(file_id.unwrap()).unwrap().to_string();
729 text_edit_builder.finish().apply(&*analysis.file_text(file_id.unwrap()).unwrap()); 729 text_edit_builder.finish().apply(&mut result);
730 assert_eq_text!(expected, &*result); 730 assert_eq_text!(expected, &*result);
731 } 731 }
732} 732}
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index e213da606..8bf52d0fa 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -511,7 +511,9 @@ mod tests {
511 ); 511 );
512 512
513 let edit = replace(&matches, &query.template); 513 let edit = replace(&matches, &query.template);
514 assert_eq!(edit.apply(input), "fn main() { bar(1+2); }"); 514 let mut after = input.to_string();
515 edit.apply(&mut after);
516 assert_eq!(after, "fn main() { bar(1+2); }");
515 } 517 }
516 518
517 fn assert_ssr_transform(query: &str, input: &str, result: &str) { 519 fn assert_ssr_transform(query: &str, input: &str, result: &str) {
@@ -519,7 +521,9 @@ mod tests {
519 let code = SourceFile::parse(input).tree(); 521 let code = SourceFile::parse(input).tree();
520 let matches = find(&query.pattern, code.syntax()); 522 let matches = find(&query.pattern, code.syntax());
521 let edit = replace(&matches, &query.template); 523 let edit = replace(&matches, &query.template);
522 assert_eq!(edit.apply(input), result); 524 let mut after = input.to_string();
525 edit.apply(&mut after);
526 assert_eq!(after, result);
523 } 527 }
524 528
525 #[test] 529 #[test]
diff --git a/crates/ra_ide/src/test_utils.rs b/crates/ra_ide/src/test_utils.rs
index f14533e14..48c8fd1f4 100644
--- a/crates/ra_ide/src/test_utils.rs
+++ b/crates/ra_ide/src/test_utils.rs
@@ -13,7 +13,11 @@ pub fn check_action<F: Fn(&SourceFile, TextSize) -> Option<TextEdit>>(
13 let (before_cursor_pos, before) = extract_offset(before); 13 let (before_cursor_pos, before) = extract_offset(before);
14 let file = SourceFile::parse(&before).ok().unwrap(); 14 let file = SourceFile::parse(&before).ok().unwrap();
15 let result = f(&file, before_cursor_pos).expect("code action is not applicable"); 15 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
16 let actual = result.apply(&before); 16 let actual = {
17 let mut actual = before.to_string();
18 result.apply(&mut actual);
19 actual
20 };
17 let actual_cursor_pos = 21 let actual_cursor_pos =
18 result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit"); 22 result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit");
19 let actual = add_cursor(&actual, actual_cursor_pos); 23 let actual = add_cursor(&actual, actual_cursor_pos);
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs
index 2a8b4327f..a03da4693 100644
--- a/crates/ra_ide/src/typing.rs
+++ b/crates/ra_ide/src/typing.rs
@@ -142,10 +142,13 @@ mod tests {
142 fn do_type_char(char_typed: char, before: &str) -> Option<(String, SingleFileChange)> { 142 fn do_type_char(char_typed: char, before: &str) -> Option<(String, SingleFileChange)> {
143 let (offset, before) = extract_offset(before); 143 let (offset, before) = extract_offset(before);
144 let edit = TextEdit::insert(offset, char_typed.to_string()); 144 let edit = TextEdit::insert(offset, char_typed.to_string());
145 let before = edit.apply(&before); 145 let mut before = before.to_string();
146 edit.apply(&mut before);
146 let parse = SourceFile::parse(&before); 147 let parse = SourceFile::parse(&before);
147 on_char_typed_inner(&parse.tree(), offset, char_typed) 148 on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| {
148 .map(|it| (it.edit.apply(&before), it)) 149 it.edit.apply(&mut before);
150 (before.to_string(), it)
151 })
149 } 152 }
150 153
151 fn type_char(char_typed: char, before: &str, after: &str) { 154 fn type_char(char_typed: char, before: &str, after: &str) {
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs
index 725237464..78a40cc94 100644
--- a/crates/ra_ide/src/typing/on_enter.rs
+++ b/crates/ra_ide/src/typing/on_enter.rs
@@ -96,7 +96,8 @@ mod tests {
96 let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?; 96 let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?;
97 97
98 assert_eq!(result.source_file_edits.len(), 1); 98 assert_eq!(result.source_file_edits.len(), 1);
99 let actual = result.source_file_edits[0].edit.apply(&before); 99 let mut actual = before.to_string();
100 result.source_file_edits[0].edit.apply(&mut actual);
100 let actual = add_cursor(&actual, result.cursor_position.unwrap().offset); 101 let actual = add_cursor(&actual, result.cursor_position.unwrap().offset);
101 Some(actual) 102 Some(actual)
102 } 103 }