]> git.lizzy.rs Git - rust.git/commitdiff
Add more import insertion tests
authorLukas Wirth <lukastw97@gmail.com>
Wed, 2 Sep 2020 13:50:29 +0000 (15:50 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Thu, 3 Sep 2020 16:36:07 +0000 (18:36 +0200)
crates/assists/src/utils/insert_use.rs

index 8ee5e0c9c55684df35bb7d828fed0b08e26c3349..8563b16abec5eede3818c7c4c14306ddf6656518 100644 (file)
@@ -114,8 +114,7 @@ pub fn try_merge_trees(
     let lhs_tl = lhs.use_tree_list()?;
     let rhs_tl = rhs.use_tree_list()?;
 
-    // if we are only allowed to merge the last level check if the paths are only one level deep
-    // FIXME: This shouldn't work yet i think
+    // if we are only allowed to merge the last level check if the split off paths are only one level deep
     if merge_behaviour == MergeBehaviour::Last && use_tree_list_is_nested(&lhs_tl)
         || use_tree_list_is_nested(&rhs_tl)
     {
@@ -463,7 +462,7 @@ fn merges_groups_last() {
     }
 
     #[test]
-    fn merges_groups2() {
+    fn merges_groups_full() {
         check_full(
             "std::io",
             r"use std::fmt::{Result, Display};",
@@ -471,6 +470,61 @@ fn merges_groups2() {
         )
     }
 
+    #[test]
+    fn merges_groups_long_full() {
+        check_full(
+            "std::foo::bar::Baz",
+            r"use std::foo::bar::Qux;",
+            r"use std::foo::bar::{Baz, Qux};",
+        )
+    }
+
+    #[test]
+    fn merges_groups_long_last() {
+        check_last(
+            "std::foo::bar::Baz",
+            r"use std::foo::bar::Qux;",
+            r"use std::foo::bar::{Baz, Qux};",
+        )
+    }
+
+    #[test]
+    fn merges_groups_long_full_list() {
+        check_full(
+            "std::foo::bar::Baz",
+            r"use std::foo::bar::{Qux, Quux};",
+            r"use std::foo::bar::{Baz, Quux, Qux};",
+        )
+    }
+
+    #[test]
+    fn merges_groups_long_last_list() {
+        check_last(
+            "std::foo::bar::Baz",
+            r"use std::foo::bar::{Qux, Quux};",
+            r"use std::foo::bar::{Baz, Quux, Qux};",
+        )
+    }
+
+    #[test]
+    fn merges_groups_long_full_nested() {
+        check_full(
+            "std::foo::bar::Baz",
+            r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
+            r"use std::foo::bar::{Baz, quux::{Fez, Fizz}, Qux};",
+        )
+    }
+
+    #[test]
+    fn merges_groups_long_last_nested() {
+        check_last(
+            "std::foo::bar::Baz",
+            r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
+            r"use std::foo::bar::Baz;
+use std::foo::bar::{quux::{Fez, Fizz}, Qux};",
+        )
+    }
+
     #[test]
     fn skip_merges_groups_pub() {
         check_full(
@@ -481,6 +535,17 @@ fn skip_merges_groups_pub() {
         )
     }
 
+    // should this be a thing?
+    #[test]
+    fn split_merge() {
+        check_last(
+            "std::fmt::Result",
+            r"use std::{fmt, io};",
+            r"use std::fmt::Result;
+use std::io;",
+        )
+    }
+
     #[test]
     fn merges_groups_self() {
         check_full("std::fmt::Debug", r"use std::fmt;", r"use std::fmt::{self, Debug};")