mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Give MergeBehaviour variants better names
This commit is contained in:
parent
07cea5e709
commit
6a8d47e7f0
8 changed files with 76 additions and 66 deletions
|
@ -44,7 +44,7 @@ fn insert_not_group_empty() {
|
|||
|
||||
#[test]
|
||||
fn insert_existing() {
|
||||
check_full("std::fs", "use std::fs;", "use std::fs;")
|
||||
check_crate("std::fs", "use std::fs;", "use std::fs;")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -249,7 +249,7 @@ use self::fmt;",
|
|||
|
||||
#[test]
|
||||
fn insert_no_imports() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"foo::bar",
|
||||
"fn main() {}",
|
||||
r"use foo::bar;
|
||||
|
@ -263,7 +263,7 @@ 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(
|
||||
check_crate(
|
||||
"foo::bar",
|
||||
"",
|
||||
r"use foo::bar;
|
||||
|
@ -290,7 +290,7 @@ fn insert_empty_module() {
|
|||
#[test]
|
||||
fn insert_after_inner_attr() {
|
||||
cov_mark::check!(insert_group_empty_inner_attr);
|
||||
check_full(
|
||||
check_crate(
|
||||
"foo::bar",
|
||||
r"#![allow(unused_imports)]",
|
||||
r"#![allow(unused_imports)]
|
||||
|
@ -301,7 +301,7 @@ use foo::bar;",
|
|||
|
||||
#[test]
|
||||
fn insert_after_inner_attr2() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"foo::bar",
|
||||
r"#![allow(unused_imports)]
|
||||
|
||||
|
@ -371,12 +371,12 @@ fn main() {}"#,
|
|||
|
||||
#[test]
|
||||
fn merge_groups() {
|
||||
check_last("std::io", r"use std::fmt;", r"use std::{fmt, io};")
|
||||
check_module("std::io", r"use std::fmt;", r"use std::{fmt, io};")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_groups_last() {
|
||||
check_last(
|
||||
check_module(
|
||||
"std::io",
|
||||
r"use std::fmt::{Result, Display};",
|
||||
r"use std::fmt::{Result, Display};
|
||||
|
@ -386,12 +386,12 @@ use std::io;",
|
|||
|
||||
#[test]
|
||||
fn merge_last_into_self() {
|
||||
check_last("foo::bar::baz", r"use foo::bar;", r"use foo::bar::{self, baz};");
|
||||
check_module("foo::bar::baz", r"use foo::bar;", r"use foo::bar::{self, baz};");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_groups_full() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::io",
|
||||
r"use std::fmt::{Result, Display};",
|
||||
r"use std::{fmt::{Result, Display}, io};",
|
||||
|
@ -400,17 +400,21 @@ fn merge_groups_full() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_long_full() {
|
||||
check_full("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};")
|
||||
check_crate("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_groups_long_last() {
|
||||
check_last("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};")
|
||||
check_module(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::foo::bar::Qux;",
|
||||
r"use std::foo::bar::{Baz, Qux};",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_groups_long_full_list() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::foo::bar::{Qux, Quux};",
|
||||
r"use std::foo::bar::{Baz, Quux, Qux};",
|
||||
|
@ -419,7 +423,7 @@ fn merge_groups_long_full_list() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_long_last_list() {
|
||||
check_last(
|
||||
check_module(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::foo::bar::{Qux, Quux};",
|
||||
r"use std::foo::bar::{Baz, Quux, Qux};",
|
||||
|
@ -428,7 +432,7 @@ fn merge_groups_long_last_list() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_long_full_nested() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
|
||||
r"use std::foo::bar::{Baz, Qux, quux::{Fez, Fizz}};",
|
||||
|
@ -437,7 +441,7 @@ fn merge_groups_long_full_nested() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_long_last_nested() {
|
||||
check_last(
|
||||
check_module(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
|
||||
r"use std::foo::bar::Baz;
|
||||
|
@ -447,7 +451,7 @@ use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
|
|||
|
||||
#[test]
|
||||
fn merge_groups_full_nested_deep() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::foo::bar::quux::Baz",
|
||||
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
|
||||
r"use std::foo::bar::{Qux, quux::{Baz, Fez, Fizz}};",
|
||||
|
@ -456,7 +460,7 @@ fn merge_groups_full_nested_deep() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_full_nested_long() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::{foo::bar::Qux};",
|
||||
r"use std::{foo::bar::{Baz, Qux}};",
|
||||
|
@ -465,7 +469,7 @@ fn merge_groups_full_nested_long() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_last_nested_long() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::foo::bar::Baz",
|
||||
r"use std::{foo::bar::Qux};",
|
||||
r"use std::{foo::bar::{Baz, Qux}};",
|
||||
|
@ -474,7 +478,7 @@ fn merge_groups_last_nested_long() {
|
|||
|
||||
#[test]
|
||||
fn merge_groups_skip_pub() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::io",
|
||||
r"pub use std::fmt::{Result, Display};",
|
||||
r"pub use std::fmt::{Result, Display};
|
||||
|
@ -484,7 +488,7 @@ use std::io;",
|
|||
|
||||
#[test]
|
||||
fn merge_groups_skip_pub_crate() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::io",
|
||||
r"pub(crate) use std::fmt::{Result, Display};",
|
||||
r"pub(crate) use std::fmt::{Result, Display};
|
||||
|
@ -494,7 +498,7 @@ use std::io;",
|
|||
|
||||
#[test]
|
||||
fn merge_groups_skip_attributed() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"std::io",
|
||||
r#"
|
||||
#[cfg(feature = "gated")] use std::fmt::{Result, Display};
|
||||
|
@ -509,7 +513,7 @@ use std::io;
|
|||
#[test]
|
||||
#[ignore] // FIXME: Support this
|
||||
fn split_out_merge() {
|
||||
check_last(
|
||||
check_module(
|
||||
"std::fmt::Result",
|
||||
r"use std::{fmt, io};",
|
||||
r"use std::fmt::{self, Result};
|
||||
|
@ -519,29 +523,33 @@ use std::io;",
|
|||
|
||||
#[test]
|
||||
fn merge_into_module_import() {
|
||||
check_full("std::fmt::Result", r"use std::{fmt, io};", r"use std::{fmt::{self, Result}, io};")
|
||||
check_crate("std::fmt::Result", r"use std::{fmt, io};", r"use std::{fmt::{self, Result}, io};")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_groups_self() {
|
||||
check_full("std::fmt::Debug", r"use std::fmt;", r"use std::fmt::{self, Debug};")
|
||||
check_crate("std::fmt::Debug", r"use std::fmt;", r"use std::fmt::{self, Debug};")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_mod_into_glob() {
|
||||
check_full("token::TokenKind", r"use token::TokenKind::*;", r"use token::TokenKind::{*, self};")
|
||||
check_crate(
|
||||
"token::TokenKind",
|
||||
r"use token::TokenKind::*;",
|
||||
r"use token::TokenKind::{*, self};",
|
||||
)
|
||||
// FIXME: have it emit `use token::TokenKind::{self, *}`?
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_self_glob() {
|
||||
check_full("self", r"use self::*;", r"use self::{*, self};")
|
||||
check_crate("self", r"use self::*;", r"use self::{*, self};")
|
||||
// FIXME: have it emit `use {self, *}`?
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_glob_nested() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"foo::bar::quux::Fez",
|
||||
r"use foo::bar::{Baz, quux::*};",
|
||||
r"use foo::bar::{Baz, quux::{self::*, Fez}};",
|
||||
|
@ -550,7 +558,7 @@ fn merge_glob_nested() {
|
|||
|
||||
#[test]
|
||||
fn merge_nested_considers_first_segments() {
|
||||
check_full(
|
||||
check_crate(
|
||||
"hir_ty::display::write_bounds_like_dyn_trait",
|
||||
r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter}, method_resolution};",
|
||||
r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter, write_bounds_like_dyn_trait}, method_resolution};",
|
||||
|
@ -559,7 +567,7 @@ fn merge_nested_considers_first_segments() {
|
|||
|
||||
#[test]
|
||||
fn skip_merge_last_too_long() {
|
||||
check_last(
|
||||
check_module(
|
||||
"foo::bar",
|
||||
r"use foo::bar::baz::Qux;",
|
||||
r"use foo::bar;
|
||||
|
@ -569,7 +577,7 @@ use foo::bar::baz::Qux;",
|
|||
|
||||
#[test]
|
||||
fn skip_merge_last_too_long2() {
|
||||
check_last(
|
||||
check_module(
|
||||
"foo::bar::baz::Qux",
|
||||
r"use foo::bar;",
|
||||
r"use foo::bar;
|
||||
|
@ -592,7 +600,7 @@ fn merge_last_fail() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::{baz::{Qux, Fez}};",
|
||||
r"use foo::bar::{baaz::{Quux, Feez}};",
|
||||
MergeBehavior::Last,
|
||||
MergeBehavior::Module,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -601,7 +609,7 @@ fn merge_last_fail1() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::{baz::{Qux, Fez}};",
|
||||
r"use foo::bar::baaz::{Quux, Feez};",
|
||||
MergeBehavior::Last,
|
||||
MergeBehavior::Module,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -610,7 +618,7 @@ fn merge_last_fail2() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::baz::{Qux, Fez};",
|
||||
r"use foo::bar::{baaz::{Quux, Feez}};",
|
||||
MergeBehavior::Last,
|
||||
MergeBehavior::Module,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -619,7 +627,7 @@ fn merge_last_fail3() {
|
|||
check_merge_only_fail(
|
||||
r"use foo::bar::baz::{Qux, Fez};",
|
||||
r"use foo::bar::baaz::{Quux, Feez};",
|
||||
MergeBehavior::Last,
|
||||
MergeBehavior::Module,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -648,12 +656,12 @@ fn check(
|
|||
assert_eq_text!(ra_fixture_after, &result);
|
||||
}
|
||||
|
||||
fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Full), false, true)
|
||||
fn check_crate(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Crate), false, true)
|
||||
}
|
||||
|
||||
fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Last), false, true)
|
||||
fn check_module(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Module), false, true)
|
||||
}
|
||||
|
||||
fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue