From fa20a5064be85349d2d05abcd66f5662d3aecb0c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 20 Apr 2021 02:05:22 +0200 Subject: Remove SyntaxRewriter usage in insert_use in favor of ted --- crates/ide_db/src/helpers/insert_use/tests.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'crates/ide_db/src/helpers/insert_use/tests.rs') diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs index 3d151e629..a3464d606 100644 --- a/crates/ide_db/src/helpers/insert_use/tests.rs +++ b/crates/ide_db/src/helpers/insert_use/tests.rs @@ -51,17 +51,16 @@ use std::bar::G;", #[test] fn insert_start_indent() { - cov_mark::check!(insert_use_indent_after); check_none( "std::bar::AA", r" use std::bar::B; - use std::bar::D;", + use std::bar::C;", r" use std::bar::AA; use std::bar::B; - use std::bar::D;", - ) + use std::bar::C;", + ); } #[test] @@ -120,7 +119,6 @@ use std::bar::ZZ;", #[test] fn insert_end_indent() { - cov_mark::check!(insert_use_indent_before); check_none( "std::bar::ZZ", r" @@ -255,7 +253,6 @@ fn insert_empty_file() { #[test] fn insert_empty_module() { - cov_mark::check!(insert_use_no_indent_after); check( "foo::bar", "mod x {}", @@ -615,7 +612,7 @@ fn check( if module { syntax = syntax.descendants().find_map(ast::Module::cast).unwrap().syntax().clone(); } - let file = super::ImportScope::from(syntax).unwrap(); + let file = super::ImportScope::from(syntax.clone_for_update()).unwrap(); let path = ast::SourceFile::parse(&format!("use {};", path)) .tree() .syntax() @@ -623,12 +620,8 @@ fn check( .find_map(ast::Path::cast) .unwrap(); - let rewriter = insert_use( - &file, - path, - InsertUseConfig { merge: mb, prefix_kind: PrefixKind::Plain, group }, - ); - let result = rewriter.rewrite(file.as_syntax_node()).to_string(); + insert_use(&file, path, InsertUseConfig { merge: mb, prefix_kind: PrefixKind::Plain, group }); + let result = file.as_syntax_node().to_string(); assert_eq_text!(ra_fixture_after, &result); } -- cgit v1.2.3 From b290cd578260f307e872a95f971e5a7c656a80ed Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 20 Apr 2021 19:28:18 +0200 Subject: Add cov_marks to insert_use tests --- crates/ide_db/src/helpers/insert_use/tests.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crates/ide_db/src/helpers/insert_use/tests.rs') diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs index a3464d606..048c213e2 100644 --- a/crates/ide_db/src/helpers/insert_use/tests.rs +++ b/crates/ide_db/src/helpers/insert_use/tests.rs @@ -5,6 +5,7 @@ use test_utils::assert_eq_text; #[test] fn insert_not_group() { + cov_mark::check!(insert_no_grouping_last); check( "use external_crate2::bar::A", r" @@ -26,6 +27,21 @@ use external_crate2::bar::A;", ); } +#[test] +fn insert_not_group_empty() { + cov_mark::check!(insert_no_grouping_last2); + check( + "use external_crate2::bar::A", + r"", + r"use external_crate2::bar::A; + +", + None, + false, + false, + ); +} + #[test] fn insert_existing() { check_full("std::fs", "use std::fs;", "use std::fs;") @@ -65,6 +81,7 @@ fn insert_start_indent() { #[test] fn insert_middle() { + cov_mark::check!(insert_group); check_none( "std::bar::EE", r" @@ -101,6 +118,7 @@ fn insert_middle_indent() { #[test] fn insert_end() { + cov_mark::check!(insert_group_last); check_none( "std::bar::ZZ", r" @@ -199,6 +217,7 @@ fn insert_first_matching_group() { #[test] fn insert_missing_group_std() { + cov_mark::check!(insert_group_new_group); check_none( "std::fmt", r" @@ -214,6 +233,7 @@ fn insert_missing_group_std() { #[test] fn insert_missing_group_self() { + cov_mark::check!(insert_group_no_group); check_none( "self::fmt", r" @@ -240,6 +260,7 @@ fn main() {}", #[test] fn insert_empty_file() { + cov_mark::check!(insert_group_empty_file); // empty files will get two trailing newlines // this is due to the test case insert_no_imports above check_full( @@ -253,6 +274,7 @@ fn insert_empty_file() { #[test] fn insert_empty_module() { + cov_mark::check!(insert_group_empty_module); check( "foo::bar", "mod x {}", @@ -267,6 +289,7 @@ fn insert_empty_module() { #[test] fn insert_after_inner_attr() { + cov_mark::check!(insert_group_empty_inner_attr); check_full( "foo::bar", r"#![allow(unused_imports)]", -- cgit v1.2.3