1 use racer_testutils::*;
2 
3 #[test]
finds_def_of_i64()4 fn finds_def_of_i64() {
5     let src = "
6     fn main() {
7         let a: i64~ = 0;
8     }
9     ";
10     let got = get_definition(src, None);
11     assert_eq!(got.matchstr, "i64", "{:?}", got);
12 }
13 
14 #[test]
get_def_of_str_method()15 fn get_def_of_str_method() {
16     let src = r#"
17         fn check() {
18             "hello".to_lowerca~se();
19         }
20     "#;
21 
22     let got = get_definition(src, None);
23     assert_eq!("to_lowercase", got.matchstr);
24 }
25 
26 #[test]
completes_liballoc_method_for_str()27 fn completes_liballoc_method_for_str() {
28     let src = r#"
29     fn in_let() {
30         let foo = "hello";
31         foo.to_lowerc~
32     }
33     "#;
34 
35     let got = get_only_completion(src, None);
36     assert_eq!(got.matchstr, "to_lowercase");
37 }
38 
39 #[test]
completes_libcore_method_for_str()40 fn completes_libcore_method_for_str() {
41     let src = r#"
42     fn in_let() {
43         let foo = "hello";
44         foo.le~
45     }
46     "#;
47 
48     let got = get_only_completion(src, None);
49     assert_eq!(got.matchstr, "len");
50 }
51 
52 // Experimental featrue
53 #[test]
completes_tuple_field()54 fn completes_tuple_field() {
55     let src = "
56     fn foo() -> (usize, usize) { (1, 2) }
57     fn main() {
58         foo().~
59     }
60     ";
61     let got = get_all_completions(src, None);
62     assert!(got
63         .into_iter()
64         .all(|ma| ma.matchstr == "0" || ma.matchstr == "1"))
65 }
66 
67 #[test]
completes_methods_for_char()68 fn completes_methods_for_char() {
69     let src = r#"
70     fn main() {
71         'c'.is_upperc~
72     }
73     "#;
74 
75     let got = get_only_completion(src, None);
76     assert_eq!(got.matchstr, "is_uppercase");
77 }
78 
79 #[test]
completes_slice_methods_for_array()80 fn completes_slice_methods_for_array() {
81     let src = r#"
82     fn main() {
83         [1, 2, 3].split_mu~
84     }
85     "#;
86 
87     let got = get_only_completion(src, None);
88     assert_eq!(got.matchstr, "split_mut");
89 }
90 
91 #[test]
completes_methods_for_slice()92 fn completes_methods_for_slice() {
93     let src = r#"
94     fn slice() -> &'static [usize] {
95         &[1, 2, 3]
96     }
97     fn main() {
98         let s = slice();
99         s.split_first_m~
100     }
101     "#;
102 
103     let got = get_only_completion(src, None);
104     assert_eq!(got.matchstr, "split_first_mut");
105 }
106 
107 #[test]
completes_slice_methods_for_vec()108 fn completes_slice_methods_for_vec() {
109     let src = r#"
110     fn main() {
111         let v = vec![];
112         v.split_first_m~
113     }
114     "#;
115 
116     let got = get_only_completion(src, None);
117     assert_eq!(got.matchstr, "split_first_mut");
118 }
119