mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Add tests for stability check in completion
This commit is contained in:
parent
0ce71dd76f
commit
e6e48728da
@ -172,6 +172,43 @@ fn foo(s: S) { s.$0 }
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_unstable_method_on_stable() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
fn foo(s: std::S) { s.$0 }
|
||||||
|
//- /std.rs crate:std
|
||||||
|
pub struct S;
|
||||||
|
impl S {
|
||||||
|
#[unstable]
|
||||||
|
pub fn bar(&self) {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![""],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unstable_method_on_nightly() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
fn foo(s: std::S) { s.$0 }
|
||||||
|
//- /std.rs crate:std
|
||||||
|
pub struct S;
|
||||||
|
impl S {
|
||||||
|
#[unstable]
|
||||||
|
pub fn bar(&self) {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
me bar() fn(&self)
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_struct_field_completion_self() {
|
fn test_struct_field_completion_self() {
|
||||||
check(
|
check(
|
||||||
|
@ -23,6 +23,7 @@ mod type_pos;
|
|||||||
mod use_tree;
|
mod use_tree;
|
||||||
mod visibility;
|
mod visibility;
|
||||||
|
|
||||||
|
use expect_test::Expect;
|
||||||
use hir::PrefixKind;
|
use hir::PrefixKind;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{fixture::ChangeFixture, FileLoader, FilePosition},
|
base_db::{fixture::ChangeFixture, FileLoader, FilePosition},
|
||||||
@ -215,6 +216,11 @@ pub(crate) fn check_edit_with_config(
|
|||||||
assert_eq_text!(&ra_fixture_after, &actual)
|
assert_eq_text!(&ra_fixture_after, &actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_empty(ra_fixture: &str, expect: Expect) {
|
||||||
|
let actual = completion_list(ra_fixture);
|
||||||
|
expect.assert_eq(&actual);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_all_items(
|
pub(crate) fn get_all_items(
|
||||||
config: CompletionConfig,
|
config: CompletionConfig,
|
||||||
code: &str,
|
code: &str,
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
//! Completion tests for expressions.
|
//! Completion tests for expressions.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{check_edit, completion_list, BASE_ITEMS_FIXTURE};
|
use crate::tests::{check_edit, check_empty, completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"));
|
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"));
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_empty(ra_fixture: &str, expect: Expect) {
|
|
||||||
let actual = completion_list(ra_fixture);
|
|
||||||
expect.assert_eq(&actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn complete_literal_struct_with_a_private_field() {
|
fn complete_literal_struct_with_a_private_field() {
|
||||||
// `FooDesc.bar` is private, the completion should not be triggered.
|
// `FooDesc.bar` is private, the completion should not be triggered.
|
||||||
@ -997,3 +992,105 @@ fn foo() { if foo {} el$0 { let x = 92; } }
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expr_no_unstable_item_on_stable() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
fn main() {
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct UnstableThisShouldNotBeListed;
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn main() fn()
|
||||||
|
md std
|
||||||
|
bt u32
|
||||||
|
kw const
|
||||||
|
kw crate::
|
||||||
|
kw enum
|
||||||
|
kw extern
|
||||||
|
kw false
|
||||||
|
kw fn
|
||||||
|
kw for
|
||||||
|
kw if
|
||||||
|
kw if let
|
||||||
|
kw impl
|
||||||
|
kw let
|
||||||
|
kw loop
|
||||||
|
kw match
|
||||||
|
kw mod
|
||||||
|
kw return
|
||||||
|
kw self::
|
||||||
|
kw static
|
||||||
|
kw struct
|
||||||
|
kw trait
|
||||||
|
kw true
|
||||||
|
kw type
|
||||||
|
kw union
|
||||||
|
kw unsafe
|
||||||
|
kw use
|
||||||
|
kw while
|
||||||
|
kw while let
|
||||||
|
sn macro_rules
|
||||||
|
sn pd
|
||||||
|
sn ppd
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn expr_unstable_item_on_nightly() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
fn main() {
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct UnstableButWeAreOnNightlyAnyway;
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn main() fn()
|
||||||
|
md std
|
||||||
|
st UnstableButWeAreOnNightlyAnyway
|
||||||
|
bt u32
|
||||||
|
kw const
|
||||||
|
kw crate::
|
||||||
|
kw enum
|
||||||
|
kw extern
|
||||||
|
kw false
|
||||||
|
kw fn
|
||||||
|
kw for
|
||||||
|
kw if
|
||||||
|
kw if let
|
||||||
|
kw impl
|
||||||
|
kw let
|
||||||
|
kw loop
|
||||||
|
kw match
|
||||||
|
kw mod
|
||||||
|
kw return
|
||||||
|
kw self::
|
||||||
|
kw static
|
||||||
|
kw struct
|
||||||
|
kw trait
|
||||||
|
kw true
|
||||||
|
kw type
|
||||||
|
kw union
|
||||||
|
kw unsafe
|
||||||
|
kw use
|
||||||
|
kw while
|
||||||
|
kw while let
|
||||||
|
sn macro_rules
|
||||||
|
sn pd
|
||||||
|
sn ppd
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1107,6 +1107,41 @@ fn function() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn flyimport_pattern_no_unstable_item_on_stable() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
fn function() {
|
||||||
|
let foo$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct FooStruct {}
|
||||||
|
"#,
|
||||||
|
expect![""],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn flyimport_pattern_unstable_item_on_nightly() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
fn function() {
|
||||||
|
let foo$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct FooStruct {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
st FooStruct (use std::FooStruct)
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flyimport_item_name() {
|
fn flyimport_item_name() {
|
||||||
check(
|
check(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Completion tests for item list position.
|
//! Completion tests for item list position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{check_edit, completion_list, BASE_ITEMS_FIXTURE};
|
use crate::tests::{check_edit, check_empty, completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"));
|
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}{ra_fixture}"));
|
||||||
@ -297,6 +297,58 @@ impl Test for () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_trait_impl_no_unstable_item_on_stable() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
trait Test {
|
||||||
|
#[unstable]
|
||||||
|
type Type;
|
||||||
|
#[unstable]
|
||||||
|
const CONST: ();
|
||||||
|
#[unstable]
|
||||||
|
fn function();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Test for () {
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_trait_impl_unstable_item_on_nightly() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
trait Test {
|
||||||
|
#[unstable]
|
||||||
|
type Type;
|
||||||
|
#[unstable]
|
||||||
|
const CONST: ();
|
||||||
|
#[unstable]
|
||||||
|
fn function();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Test for () {
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
ct const CONST: () =
|
||||||
|
fn fn function()
|
||||||
|
ta type Type =
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn after_unit_struct() {
|
fn after_unit_struct() {
|
||||||
check(
|
check(
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
//! Completion tests for pattern position.
|
//! Completion tests for pattern position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{check_edit, completion_list, BASE_ITEMS_FIXTURE};
|
use crate::tests::{check_edit, check_empty, completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check_empty(ra_fixture: &str, expect: Expect) {
|
|
||||||
let actual = completion_list(ra_fixture);
|
|
||||||
expect.assert_eq(&actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
|
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
|
||||||
@ -742,3 +737,56 @@ fn f(x: EnumAlias<u8>) {
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pat_no_unstable_item_on_stable() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
fn foo() {
|
||||||
|
let a$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct S;
|
||||||
|
#[unstable]
|
||||||
|
pub enum Enum {
|
||||||
|
Variant
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md std
|
||||||
|
kw mut
|
||||||
|
kw ref
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pat_unstable_item_on_nightly() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
fn foo() {
|
||||||
|
let a$0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct S;
|
||||||
|
#[unstable]
|
||||||
|
pub enum Enum {
|
||||||
|
Variant
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
en Enum
|
||||||
|
md std
|
||||||
|
st S
|
||||||
|
kw mut
|
||||||
|
kw ref
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Completion tests for predicates and bounds.
|
//! Completion tests for predicates and bounds.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
use crate::tests::{check_empty, completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
|
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
|
||||||
@ -129,3 +129,43 @@ impl Record {
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pred_no_unstable_item_on_stable() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
struct Foo<T> where T: $0 {}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub trait Trait {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md std
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pred_unstable_item_on_nightly() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
struct Foo<T> where T: $0 {}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub trait Trait {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md std
|
||||||
|
tt Trait
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Completion tests for type position.
|
//! Completion tests for type position.
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
use crate::tests::{check_empty, completion_list, BASE_ITEMS_FIXTURE};
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
|
let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
|
||||||
@ -669,3 +669,53 @@ fn f(t: impl MyTrait<Item1 = u8, Item2 = $0
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn type_pos_no_unstable_type_on_stable() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
struct Foo {
|
||||||
|
f: $0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct S;
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md std
|
||||||
|
sp Self
|
||||||
|
st Foo
|
||||||
|
bt u32
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn type_pos_unstable_type_on_nightly() {
|
||||||
|
check_empty(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /main.rs crate:main deps:std
|
||||||
|
use std::*;
|
||||||
|
struct Foo {
|
||||||
|
f: $0
|
||||||
|
}
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub struct S;
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
md std
|
||||||
|
sp Self
|
||||||
|
st Foo
|
||||||
|
st S
|
||||||
|
bt u32
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -382,3 +382,51 @@ use self::foo::impl$0
|
|||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn use_tree_no_unstable_items_on_stable() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- toolchain:stable
|
||||||
|
//- /lib.rs crate:main deps:std
|
||||||
|
use std::$0
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub mod simd {}
|
||||||
|
#[unstable]
|
||||||
|
pub struct S;
|
||||||
|
#[unstable]
|
||||||
|
pub fn foo() {}
|
||||||
|
#[unstable]
|
||||||
|
#[macro_export]
|
||||||
|
marco_rules! m { () => {} }
|
||||||
|
"#,
|
||||||
|
expect![""],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn use_tree_unstable_items_on_nightly() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- toolchain:nightly
|
||||||
|
//- /lib.rs crate:main deps:std
|
||||||
|
use std::$0
|
||||||
|
//- /std.rs crate:std
|
||||||
|
#[unstable]
|
||||||
|
pub mod simd {}
|
||||||
|
#[unstable]
|
||||||
|
pub struct S;
|
||||||
|
#[unstable]
|
||||||
|
pub fn foo() {}
|
||||||
|
#[unstable]
|
||||||
|
#[macro_export]
|
||||||
|
marco_rules! m { () => {} }
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo fn()
|
||||||
|
md simd
|
||||||
|
st S
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user