mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Refactor keyword completion tests
This commit is contained in:
parent
81bb3d9c1a
commit
e2b04621f9
1 changed files with 199 additions and 207 deletions
|
@ -174,46 +174,48 @@ fn complete_return(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::completion::{test_utils::completion_list, CompletionKind};
|
use expect::{expect, Expect};
|
||||||
use insta::assert_snapshot;
|
|
||||||
|
|
||||||
fn get_keyword_completions(code: &str) -> String {
|
use crate::completion::{test_utils::completion_list, CompletionKind};
|
||||||
completion_list(code, CompletionKind::Keyword)
|
|
||||||
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
|
let actual = completion_list(ra_fixture, CompletionKind::Keyword);
|
||||||
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_use_stmt() {
|
fn test_keywords_in_use_stmt() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"use <|>"),
|
r"use <|>",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw crate::
|
kw crate::
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
kw super::
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"use a::<|>"),
|
r"use a::<|>",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
kw super::
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"use a::{b, <|>}"),
|
r"use a::{b, <|>}",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
kw super::
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_at_source_file_level() {
|
fn test_keywords_at_source_file_level() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"m<|>"),
|
r"m<|>",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw const
|
kw const
|
||||||
kw enum
|
kw enum
|
||||||
kw extern
|
kw extern
|
||||||
|
@ -228,15 +230,15 @@ mod tests {
|
||||||
kw union
|
kw union
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw use
|
kw use
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_function() {
|
fn test_keywords_in_function() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn quux() { <|> }"),
|
r"fn quux() { <|> }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw const
|
kw const
|
||||||
kw extern
|
kw extern
|
||||||
kw fn
|
kw fn
|
||||||
|
@ -254,15 +256,15 @@ mod tests {
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw use
|
kw use
|
||||||
kw while
|
kw while
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_inside_block() {
|
fn test_keywords_inside_block() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn quux() { if true { <|> } }"),
|
r"fn quux() { if true { <|> } }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw const
|
kw const
|
||||||
kw extern
|
kw extern
|
||||||
kw fn
|
kw fn
|
||||||
|
@ -280,23 +282,15 @@ mod tests {
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw use
|
kw use
|
||||||
kw while
|
kw while
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_after_if() {
|
fn test_keywords_after_if() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(
|
r#"fn quux() { if true { () } <|> }"#,
|
||||||
r"
|
expect![[r#"
|
||||||
fn quux() {
|
|
||||||
if true {
|
|
||||||
()
|
|
||||||
} <|>
|
|
||||||
}
|
|
||||||
",
|
|
||||||
),
|
|
||||||
@r###"
|
|
||||||
kw const
|
kw const
|
||||||
kw else
|
kw else
|
||||||
kw else if
|
kw else if
|
||||||
|
@ -316,65 +310,63 @@ mod tests {
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw use
|
kw use
|
||||||
kw while
|
kw while
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_match_arm() {
|
fn test_keywords_in_match_arm() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(
|
r#"
|
||||||
r"
|
fn quux() -> i32 {
|
||||||
fn quux() -> i32 {
|
|
||||||
match () {
|
match () {
|
||||||
() => <|>
|
() => <|>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
",
|
"#,
|
||||||
),
|
expect![[r#"
|
||||||
@r###"
|
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
kw loop
|
kw loop
|
||||||
kw match
|
kw match
|
||||||
kw return
|
kw return
|
||||||
kw unsafe
|
kw unsafe
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_trait_def() {
|
fn test_keywords_in_trait_def() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"trait My { <|> }"),
|
r"trait My { <|> }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw const
|
kw const
|
||||||
kw fn
|
kw fn
|
||||||
kw type
|
kw type
|
||||||
kw unsafe
|
kw unsafe
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_impl_def() {
|
fn test_keywords_in_impl_def() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"impl My { <|> }"),
|
r"impl My { <|> }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw const
|
kw const
|
||||||
kw fn
|
kw fn
|
||||||
kw pub
|
kw pub
|
||||||
kw type
|
kw type
|
||||||
kw unsafe
|
kw unsafe
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_loop() {
|
fn test_keywords_in_loop() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn my() { loop { <|> } }"),
|
r"fn my() { loop { <|> } }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw break
|
kw break
|
||||||
kw const
|
kw const
|
||||||
kw continue
|
kw continue
|
||||||
|
@ -394,69 +386,69 @@ mod tests {
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw use
|
kw use
|
||||||
kw while
|
kw while
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_after_unsafe_in_item_list() {
|
fn test_keywords_after_unsafe_in_item_list() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"unsafe <|>"),
|
r"unsafe <|>",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw fn
|
kw fn
|
||||||
kw impl
|
kw impl
|
||||||
kw trait
|
kw trait
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_after_unsafe_in_block_expr() {
|
fn test_keywords_after_unsafe_in_block_expr() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn my_fn() { unsafe <|> }"),
|
r"fn my_fn() { unsafe <|> }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw fn
|
kw fn
|
||||||
kw impl
|
kw impl
|
||||||
kw trait
|
kw trait
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mut_in_ref_and_in_fn_parameters_list() {
|
fn test_mut_in_ref_and_in_fn_parameters_list() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn my_fn(&<|>) {}"),
|
r"fn my_fn(&<|>) {}",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw mut
|
kw mut
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn my_fn(<|>) {}"),
|
r"fn my_fn(<|>) {}",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw mut
|
kw mut
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"fn my_fn() { let &<|> }"),
|
r"fn my_fn() { let &<|> }",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw mut
|
kw mut
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_where_keyword() {
|
fn test_where_keyword() {
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"trait A <|>"),
|
r"trait A <|>",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw where
|
kw where
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
assert_snapshot!(
|
check(
|
||||||
get_keyword_completions(r"impl A <|>"),
|
r"impl A <|>",
|
||||||
@r###"
|
expect![[r#"
|
||||||
kw where
|
kw where
|
||||||
"###
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue