use racer_testutils::*; #[test] fn finds_type_parameter_for_fnarg() { let src = " fn main() { trait Trait { fn method(&self); } fn func(arg: &T) { arg.meth~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_methods_for_fnarg_by_trait_bounds() { let src = " fn main() { trait Trait { fn method(&self); } fn func(arg: &T) { arg.meth~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_methods_for_fnarg_by_where_clause() { let src = " fn main() { trait Trait { fn method(&self); } fn func(arg: &T) where T: Trait, { arg.meth~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_external_methods_for_fnarg_by_trait_bounds() { let src = " fn main() { fn func(arg: &T) { arg.clo~ } } "; assert!(get_all_completions(src, None) .into_iter() .any(|ma| ma.matchstr == "clone")); } #[test] fn completes_inherited_methods_for_fnarg_by_trait_bounds() { let src = " fn main() { trait Inherited { fn inherited(&self); } trait Trait: Inherited { fn method(&self); } fn func(arg: &T) { arg.inheri~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "inherited"); } // test for checking racer don't cause INF loop #[test] fn completes_inherited_methods_with_cycle() { let src = " fn main() { trait Inherited2: Inherited1 {} trait Inherited1: Inherited2 { fn inherited(&self); } trait Trait: Inherited1 { fn method(&self); } fn func(arg: &T) { arg.inheri~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "inherited"); } #[test] fn completes_impled_bounds_for_fnarg() { let src = " fn main() { struct St(T); trait Trait: Sized { fn method(&self); } impl St { fn new(t: T) -> Self { t.met~ } } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_impled_bounds_for_self() { let src = " fn main() { trait Trait: Sized { fn method(&self); } impl Clone for T { fn f(self) -> Self { self.me~ } } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_impled_bounds_for_self_field() { let src = " fn main() { struct St { mem1: String, mem2: T, } trait Trait: Sized { fn method(&self); } impl St { fn f(self) -> Self { self.mem2.m~ } } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_impled_bounds_for_ref_self_field() { let src = " fn main() { struct St<'a, T> { mem1: String, mem2: &'a T, } trait Trait: Sized { fn method(&self); } impl St { fn f(self) -> Self { self.mem2.m~ } } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_fn_bounds_for_struct_member() { let src = " fn main() { struct St { mem1: String, mem2: T, } fn f(st: St) { st.mem2.clone_fro~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "clone_from"); } #[test] fn completes_impl_trait_in_arg_position() { let src = " struct MyType; trait Foo { fn foo(&self); } impl Foo for MyType { fn foo(&self) { unimplemented!(); } } fn bar(b: impl Foo) { b.~ } "; assert_eq!(get_only_completion(src, None).matchstr, "foo"); } #[test] fn completes_impl_trait_in_fn_return_position() { let src = " struct MyType; trait Foo { fn foo(&self); } impl Foo for MyType { fn foo(&self) { unimplemented!(); } } fn bar() -> impl Foo { MyType } fn main() { let mytype = bar(); mytype.~ } "; assert_eq!(get_only_completion(src, None).matchstr, "foo"); } #[test] fn completes_returned_impl_trait_in_othermod() { let src = " fn main() { m::it().meth~ } mod empty { } mod m { pub trait Trait { fn method(&self) {} } pub fn it() -> impl Trait { } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_arg_impl_trait_in_othermod() { let src = " fn f(t: impl m::Trait) { t.me~ } mod empty { } mod m { pub trait Trait { fn method(&self) {} } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_unsafe_trait_methods_for_fnarg() { let src = " fn main() { unsafe trait Trait { fn method(&self); } fn func(arg: &T) { unsafe { arg.meth~ } } } "; assert_eq!(get_only_completion(src, None).matchstr, "method"); } #[test] fn completes_assoc_type_for_type_param_in_fn() { let src = " trait Object { type BaseObj: Object; } fn f(o: O) { O::Base~ } "; assert_eq!(get_only_completion(src, None).matchstr, "BaseObj"); } #[test] fn completes_assoc_fn_for_type_param_in_fn() { let src = " trait Object { fn init_typeobj() {} } fn f(o: O) { O::init_~ } "; assert_eq!(get_only_completion(src, None).matchstr, "init_typeobj"); } #[test] fn completes_assoc_type_for_type_param_in_impl() { let src = " trait Object { type BaseObj: Object; } struct ObjectWrapper { inner: O, } impl ObjectWrapper { const A: O::BaseO~ } "; assert_eq!(get_only_completion(src, None).matchstr, "BaseObj"); } #[test] fn completes_assoc_fn_for_type_param_in_impl() { let src = " trait Object { fn init_typeobj() {} } struct ObjectWrapper { inner: O, } impl ObjectWrapper { fn method(&self) { O::init~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "init_typeobj"); } #[test] fn completes_assoc_constant_for_type_param_impl_bound() { let src = " trait Object { const OFFSET: usize; } struct ObjectWrapper { inner: O, } impl ObjectWrapper { fn method(&self) { O::OFF~ } } "; assert_eq!(get_only_completion(src, None).matchstr, "OFFSET"); } #[test] fn print_trait_object() { let src = " trait Object {} struct Obj(Box); fn main() { let obj: Obj = function(); obj.~ } "; let got = get_only_completion(src, None); assert_eq!(got.matchstr, "0"); assert_eq!(got.contextstr, "Box"); }