Refactor keyword completion tests

This commit is contained in:
Aleksey Kladov 2020-07-03 12:51:18 +02:00
parent 81bb3d9c1a
commit e2b04621f9

View file

@ -174,289 +174,281 @@ 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
kw fn kw fn
kw impl kw impl
kw mod kw mod
kw pub kw pub
kw static kw static
kw struct kw struct
kw trait kw trait
kw type kw type
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
kw if kw if
kw if let kw if let
kw impl kw impl
kw let kw let
kw loop kw loop
kw match kw match
kw mod kw mod
kw return kw return
kw static kw static
kw trait kw trait
kw type kw type
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
kw if kw if
kw if let kw if let
kw impl kw impl
kw let kw let
kw loop kw loop
kw match kw match
kw mod kw mod
kw return kw return
kw static kw static
kw trait kw trait
kw type kw type
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() { kw const
if true { kw else
() kw else if
} <|> kw extern
} kw fn
", kw if
), kw if let
@r###" kw impl
kw const kw let
kw else kw loop
kw else if kw match
kw extern kw mod
kw fn kw return
kw if kw static
kw if let kw trait
kw impl kw type
kw let kw unsafe
kw loop kw use
kw match kw while
kw mod "#]],
kw return
kw static
kw trait
kw type
kw unsafe
kw use
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#"
), kw if
@r###" kw if let
kw if kw loop
kw if let kw match
kw loop kw return
kw match kw unsafe
kw return "#]],
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
kw extern kw extern
kw fn kw fn
kw if kw if
kw if let kw if let
kw impl kw impl
kw let kw let
kw loop kw loop
kw match kw match
kw mod kw mod
kw return kw return
kw static kw static
kw trait kw trait
kw type kw type
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
"### "#]],
); );
} }
} }