From 903c7eb2e55ba403f7174110dfdde81184d6ed25 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 2 Sep 2020 15:50:29 +0200 Subject: Add more import insertion tests --- crates/assists/src/utils/insert_use.rs | 71 ++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) (limited to 'crates/assists') diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index 8ee5e0c9c..8563b16ab 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs @@ -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 @@ use std::io;", } #[test] - fn merges_groups2() { + fn merges_groups_full() { check_full( "std::io", r"use std::fmt::{Result, Display};", @@ -471,6 +470,61 @@ use std::io;", ) } + #[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 @@ use std::io;", ) } + // 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};") -- cgit v1.2.3