]> git.lizzy.rs Git - rust.git/commitdiff
Add a test for correct completion of ..Default::default()
authorNick Spain <nicholas.spain@stileeducation.com>
Fri, 1 Jan 2021 00:10:02 +0000 (11:10 +1100)
committerNick Spain <nicholas.spain@stileeducation.com>
Fri, 1 Jan 2021 00:10:22 +0000 (11:10 +1100)
crates/completion/src/completions/record.rs

index 8f904adfda01c1e3d2a7fe35d8a06e98e22513c2..f55ae11e6b38e232b5bf66a05be39b2b1ee08bd4 100644 (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 @@ fn check_snippet(ra_fixture: &str, expect: Expect) {
         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#"