2021-07-15 16:27:01 +02:00
|
|
|
//! Completion tests for use trees.
|
2021-06-17 13:13:12 +02:00
|
|
|
use expect_test::{expect, Expect};
|
|
|
|
|
|
|
|
use crate::tests::completion_list;
|
|
|
|
|
|
|
|
fn check(ra_fixture: &str, expect: Expect) {
|
|
|
|
let actual = completion_list(ra_fixture);
|
|
|
|
expect.assert_eq(&actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn use_tree_start() {
|
2022-06-08 20:53:42 +09:00
|
|
|
cov_mark::check!(unqualified_path_selected_only);
|
2021-06-17 13:13:12 +02:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:main deps:other_crate
|
|
|
|
use f$0
|
|
|
|
|
|
|
|
struct Foo;
|
2022-06-08 20:53:42 +09:00
|
|
|
enum FooBar {
|
|
|
|
Foo,
|
|
|
|
Bar
|
|
|
|
}
|
2021-06-17 13:13:12 +02:00
|
|
|
mod foo {}
|
|
|
|
//- /other_crate/lib.rs crate:other_crate
|
|
|
|
// nothing here
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2022-06-09 16:37:18 +09:00
|
|
|
en FooBar::
|
2021-06-17 13:13:12 +02:00
|
|
|
md foo
|
|
|
|
md other_crate
|
2022-05-05 10:49:43 +02:00
|
|
|
kw crate::
|
2021-07-07 19:08:37 +02:00
|
|
|
kw self::
|
|
|
|
kw super::
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-02 15:28:23 +01:00
|
|
|
#[test]
|
|
|
|
fn use_tree_start_abs() {
|
|
|
|
cov_mark::check!(use_tree_crate_roots_only);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:main deps:other_crate
|
|
|
|
use ::f$0
|
|
|
|
|
|
|
|
struct Foo;
|
|
|
|
mod foo {}
|
|
|
|
//- /other_crate/lib.rs crate:other_crate
|
|
|
|
// nothing here
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md other_crate
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-17 13:13:12 +02:00
|
|
|
#[test]
|
|
|
|
fn dont_complete_current_use() {
|
|
|
|
cov_mark::check!(dont_complete_current_use);
|
2021-06-17 13:56:55 +02:00
|
|
|
check(r#"use self::foo$0;"#, expect![[r#""#]]);
|
2021-06-17 13:13:12 +02:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod foo { pub struct S; }
|
|
|
|
use self::{foo::*, bar$0};
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md foo
|
2022-05-05 10:49:43 +02:00
|
|
|
st S
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nested_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub mod bar {
|
|
|
|
pub struct FooBar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use foo::{bar::$0}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
st FooBar
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub mod bar {
|
|
|
|
pub struct FooBar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use foo::{$0}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md bar
|
2022-05-05 10:49:43 +02:00
|
|
|
kw self
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn deeply_nested_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub mod bar {
|
|
|
|
pub mod baz {
|
|
|
|
pub struct FooBarBaz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use foo::{bar::{baz::$0}}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
st FooBarBaz
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub mod bar {
|
|
|
|
pub mod baz {
|
|
|
|
pub struct FooBarBaz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use foo::{bar::{$0}}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md baz
|
2022-05-05 10:49:43 +02:00
|
|
|
kw self
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn plain_qualified_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
use foo::$0
|
|
|
|
|
|
|
|
mod foo {
|
|
|
|
struct Private;
|
|
|
|
pub struct Foo;
|
2021-10-16 23:33:09 +02:00
|
|
|
macro_rules! foo_ { {} => {} }
|
|
|
|
pub use foo_ as foo;
|
2021-06-17 13:13:12 +02:00
|
|
|
}
|
|
|
|
struct Bar;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-12-21 15:20:15 +01:00
|
|
|
ma foo macro_rules! foo_
|
2022-05-05 10:49:43 +02:00
|
|
|
st Foo
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-02 15:03:46 +01:00
|
|
|
#[test]
|
|
|
|
fn enum_plain_qualified_use_tree() {
|
|
|
|
cov_mark::check!(enum_plain_qualified_use_tree);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
use Foo::$0
|
|
|
|
|
|
|
|
enum Foo { Variant }
|
|
|
|
impl Foo {
|
|
|
|
const CONST: () = ()
|
|
|
|
fn func() {}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
Complete enum variants identically to structures.
In particular:
- unit variants now display in the menu as "Variant", complete to "Variant", and display a detail of "Variant" (was "()")
- tuple variants now display in the menu as "Variant(…)", complete to "Variant(${1:()})$0" (was "Variant($0)"), and display a detail of "Variant(type)" (was "(type)")
- record variants now display in the menu as "Variant {…}", complete to "Variant { x: ${1:()} }$0" (was "Variant"), and display a detail of "Variant { x: type }" (was "{x: type}")
This behavior is identical to that of struct completions. In addition, tuple variants no longer set triggers_call_info, as to my understanding it's unnecessary now that we're emitting placeholders.
Tests have been updated to match, and the render::enum_variant::tests::inserts_parens_for_tuple_enums test has been removed entirely as it's covered by other tests (render::enum_detail_includes_{record, tuple}_fields, render::enum_detail_just_name_for_unit, render::pattern::enum_qualified).
2022-03-11 18:26:01 -08:00
|
|
|
ev Variant Variant
|
2022-02-02 15:03:46 +01:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-06 01:34:01 +09:00
|
|
|
#[test]
|
|
|
|
fn enum_no_parens_in_qualified_use_tree() {
|
|
|
|
cov_mark::check!(enum_plain_qualified_use_tree);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
use Foo::$0
|
|
|
|
|
|
|
|
enum Foo {
|
|
|
|
UnitVariant,
|
|
|
|
TupleVariant(),
|
|
|
|
RecordVariant {},
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
ev RecordVariant RecordVariant
|
|
|
|
ev TupleVariant TupleVariant
|
|
|
|
ev UnitVariant UnitVariant
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-17 13:13:12 +02:00
|
|
|
#[test]
|
|
|
|
fn self_qualified_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
use self::$0
|
|
|
|
|
|
|
|
mod foo {}
|
|
|
|
struct Bar;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md foo
|
|
|
|
st Bar
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn super_qualified_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod bar {
|
|
|
|
use super::$0
|
|
|
|
}
|
|
|
|
|
|
|
|
mod foo {}
|
|
|
|
struct Bar;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md bar
|
|
|
|
md foo
|
2022-05-05 10:49:43 +02:00
|
|
|
st Bar
|
|
|
|
kw super::
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn super_super_qualified_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod a {
|
|
|
|
const A: usize = 0;
|
|
|
|
mod b {
|
|
|
|
const B: usize = 0;
|
|
|
|
mod c { use super::super::$0 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
ct A
|
2022-05-05 10:49:43 +02:00
|
|
|
md b
|
|
|
|
kw super::
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn crate_qualified_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
use crate::$0
|
|
|
|
|
|
|
|
mod foo {}
|
|
|
|
struct Bar;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md foo
|
|
|
|
st Bar
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn extern_crate_qualified_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:main deps:other_crate
|
|
|
|
use other_crate::$0
|
|
|
|
//- /other_crate/lib.rs crate:other_crate
|
|
|
|
pub struct Foo;
|
|
|
|
pub mod foo {}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
md foo
|
2022-05-05 10:49:43 +02:00
|
|
|
st Foo
|
2021-06-17 13:13:12 +02:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pub_use_tree() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
pub struct X;
|
|
|
|
pub mod bar {}
|
|
|
|
pub use $0;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-07-07 19:08:37 +02:00
|
|
|
md bar
|
2022-05-05 10:49:43 +02:00
|
|
|
kw crate::
|
2021-06-17 13:56:55 +02:00
|
|
|
kw self::
|
2021-06-17 13:13:12 +02:00
|
|
|
kw super::
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-06-17 13:59:31 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn use_tree_braces_at_start() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
struct X;
|
|
|
|
mod bar {}
|
|
|
|
use {$0};
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-07-07 19:08:37 +02:00
|
|
|
md bar
|
2022-05-05 10:49:43 +02:00
|
|
|
kw crate::
|
2021-06-17 13:59:31 +02:00
|
|
|
kw self::
|
|
|
|
kw super::
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-07-15 22:23:34 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn impl_prefix_does_not_add_fn_snippet() {
|
|
|
|
// regression test for 7222
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub fn bar(x: u32) {}
|
|
|
|
}
|
|
|
|
use self::foo::impl$0
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
fn bar fn(u32)
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|