Add a test for correct completion of ..Default::default()

This commit is contained in:
Nick Spain 2021-01-01 11:10:02 +11:00
parent 4cc3a6d4fe
commit 49eeeb61ae

View File

@ -53,7 +53,10 @@ mod tests {
use expect_test::{expect, Expect};
use ide_db::helpers::FamousDefs;
use crate::{test_utils::completion_list, CompletionKind};
use crate::{
test_utils::{self, completion_list},
CompletionKind,
};
fn check(ra_fixture: &str, expect: Expect) {
let actual = completion_list(ra_fixture, CompletionKind::Reference);
@ -68,6 +71,18 @@ mod tests {
expect.assert_eq(&actual);
}
fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
test_utils::check_edit(
what,
&format!(
"//- /main.rs crate:main deps:core{}\n{}",
ra_fixture_before,
FamousDefs::FIXTURE,
),
&(ra_fixture_after.to_owned() + "\n"),
);
}
#[test]
fn test_record_literal_field_default() {
let test_code = r#"
@ -106,6 +121,51 @@ fn process(f: S) {
);
}
#[test]
fn test_record_literal_field_default_completion() {
check_edit(
"..Default::default()",
r#"
struct S { foo: u32, bar: usize }
impl core::default::Default for S {
fn default() -> Self {
S {
foo: 0,
bar: 0,
}
}
}
fn process(f: S) {
let other = S {
foo: 5,
.<|>
};
}
"#,
r#"
struct S { foo: u32, bar: usize }
impl core::default::Default for S {
fn default() -> Self {
S {
foo: 0,
bar: 0,
}
}
}
fn process(f: S) {
let other = S {
foo: 5,
..Default::default()
};
}
"#,
);
}
#[test]
fn test_record_literal_field_without_default() {
let test_code = r#"